Skip to content

Instantly share code, notes, and snippets.

Forked from javisantana/index.html
Created February 28, 2014 11:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Add an Infowindow to a CartoDB layer (using createLayer).
<!DOCTYPE html>
<title>Leaflet multilayer 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="" />
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
<link rel="stylesheet" href="" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="" />
<div id="map"></div>
<!-- include cartodb.js library -->
<script src=""></script>
function main() {
// create leaflet map
var map ='map', {
zoomControl: false,
center: [43, 0],
zoom: 3
// add a base layer
L.tileLayer('{z}/{x}/{y}.png', {
attribution: 'Stamen'
// add cartodb layer with one sublayer
cartodb.createLayer(map, {
user_name: 'examples',
type: 'cartodb',
sublayers: [{
sql: 'select * from country_boundaries',
cartocss: '#layer { polygon-fill: #F00; polygon-opacity: 0.3; line-color: #F00; }',
interactivity: 'cartodb_id'
.done(function(layer) {
cdb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['cartodb_id'])
// you could use $(window).load(main);
window.onload = main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment