Create a gist now

Instantly share code, notes, and snippets.

CartoDB.js InfoBox Example
<!DOCTYPE html>
<html>
<head>
<title>CartoDB.js Infobox Example</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
function main() {
var map = L.map('map', {
zoomControl: true,
center: [0, 0],
zoom: 2,
search: true,
});
L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
cartodb.createVis('map', 'https://team.cartodb.com/u/chandra/api/v2/viz/0249d564-6d3a-11e5-a49e-0e5db1731f59/viz.json', {legends:false})
.done(function(vis, layers) {
var sublayer = layers[1].getSubLayer(0);
sublayer.set({ 'interactivity': ['name', 'age', 'city', 'country'] });
vis.addOverlay({
type: 'infobox',
template: '<h3>{{name}}</h3><p>{{age}}</p>',
width: 200,
position: 'bottom|right'
});
}).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