Last active
February 5, 2016 19:34
-
-
Save michellechandra/d462faa8b94959468d9f to your computer and use it in GitHub Desktop.
Infowindow with - createLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>createLayer + infowindow</title> | |
<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> | |
<!-- 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> | |
</head> | |
<body> | |
<!-- define a map object--> | |
<div id="map"></div> | |
<script> | |
function main() { | |
// create leaflet map and define some properties | |
var map = L.map('map', { | |
zoomControl: false, | |
center: [43, 0], | |
zoom: 3 | |
}) | |
// add a base layer to map | |
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
attribution: 'Stamen' | |
}).addTo(map); | |
// viz.json of the map | |
var layerUrl = 'https://documentation.cartodb.com/api/v2/viz/dab13954-cac0-11e5-81d6-0ecd1babdde5/viz.jsonn'; | |
// add cartodb layer with one layer | |
cartodb.createLayer(map, layerUrl ) | |
.addTo(map) | |
.done(function(layer) { | |
// add infowindow | |
cartodb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['pop2005', 'name']) | |
}); | |
} | |
// load main() function | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment