Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created June 5, 2013 06:38
Show Gist options
  • Save javisantana/5712016 to your computer and use it in GitHub Desktop.
Save javisantana/5712016 to your computer and use it in GitHub Desktop.
infobox usage
<!DOCTYPE html>
<html>
<head>
<title>Leaflet example | CartoDB.js</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" />
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.ie.css" />
<![endif]-->
</head>
<body>
<div id="map"></div>
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v2/cartodb.js"></script>
<script>
function main() {
var map = L.map('map', {
zoomControl: false,
center: [43, 0],
zoom: 3
})
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
cartodb.createLayer(map, 'http://examples.cartodb.com/api/v1/viz/european_countries_e/viz.json', {
query: 'select * from {{table_name}} where area::float > 10000' ,
interactivity: 'area'
})
.on('done', function(layer) {
map.addLayer(layer);
var infobox = new cdb.geo.ui.InfoBox({
width: 300,
layer: layer,
template: '<p>area: {{area}}</p>'
});
$("body").append(infobox.render().el);
}).on('error', function() {
cartodb.log.log("some error occurred");
});
}
// you could use $(window).load(main);
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment