Skip to content

Instantly share code, notes, and snippets.

@michellechandra
Last active February 5, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michellechandra/3bdd9a2a36713c46dde4 to your computer and use it in GitHub Desktop.
Save michellechandra/3bdd9a2a36713c46dde4 to your computer and use it in GitHub Desktop.
Infowindow with data from different datasets
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style>html, body, #map { height: 100%; padding: 0; margin: 0 }</style>
</head>
<body>
<div id="map"></div>
<!-- include cartodb css -->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<!-- include cartodb.js library -->
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<script type="text/javascript">
var layer;
function main() {
var map = L.map('map', {
zoomControl: false,
center: [20, 20],
zoom: 2
});
// add basemap
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>'}).addTo(map);
cartodb.createLayer(map, {
user_name: 'documentation',
type: 'cartodb',
sublayers: [{
sql: "select european.the_geom, european.the_geom_webmercator, european.cartodb_id, european.admin ,world_table.area FROM european, world_table WHERE european.adm0_a3 = world_table.iso3",
cartocss: "#world_table{ line-color: #FFF; line-opacity: 1; line-width: 1; polygon-opacity: 0.8;} #world_table[area <= 1638094.0] { polygon-fill: #B10026; } #world_table [ area <= 34895.0] { polygon-fill: #E31A1C; } #world_table [ area <= 24193.0] { polygon-fill: #FC4E2A; } #world_table [ area <= 10025.0] { polygon-fill: #FD8D3C; } #world_table [ area <= 6889.0] { polygon-fill: #FEB24C; } #world_table [ area <= 4808.0] { polygon-fill: #FED976; } #world_table [ area <= 3288.0] { polygon-fill: #FFFFB2; }",
interactivity: "cartodb_id"
}]
}, {https: true})
.addTo(map)
.on('done', function(lyr) {
cartodb.vis.Vis.addInfowindow(map, lyr.getSubLayer(0), ['area','admin'])
}).on('error', function() {
console.log("some error occurred");
});
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment