Last active
May 17, 2016 16:45
-
-
Save ernesmb/b53eaf7427427d3fd974 to your computer and use it in GitHub Desktop.
CreateLayer with Infobox
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>CartoTemplate | CartoDB</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/v3/3.15/themes/css/cartodb.css" /> | |
<!-- | |
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
--> | |
</head> | |
<body> | |
<div id="map"></div> | |
<div id="box"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<!-- | |
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script> | |
--> | |
<script type=cartocss/text id=cartocss> | |
#world_borders{ polygon-fill: #FFFFB2; | |
polygon-opacity: 0.8; | |
line-color: #FFF; | |
line-width: 0.5; | |
line-opacity: 1; } | |
#world_borders [ area <= 1638094] { polygon-fill: #B10026; } | |
#world_borders [ area <= 91077] { polygon-fill: #E31A1C; } | |
#world_borders [ area <= 39730] { polygon-fill: #FC4E2A; } | |
#world_borders [ area <= 17652] { polygon-fill: #FD8D3C; } | |
#world_borders [ area <= 7162] { polygon-fill: #FEB24C; } | |
#world_borders [ area <= 2281] { polygon-fill: #FED976; } | |
#world_borders [ area <= 80] { polygon-fill: #FFFFB2; } | |
</script> | |
<!-- Drop your code between the script tags below! --> | |
<script> | |
map= new L.Map('map', { | |
zoom:3, | |
center:[40.5,-3.6] | |
}); | |
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', | |
{attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>' | |
}).addTo(map); | |
cartodb.createLayer(map, { | |
user_name:'ernestomb', | |
type:'cartodb', | |
sublayers:[ | |
{ | |
sql:'SELECT * FROM world_borders_public', | |
cartocss:$('#cartocss').html(), | |
interactivity: ['cartodb_id','name','pop2005'] | |
} | |
] | |
}) | |
.addTo(map) | |
.done(function(layer){ | |
//do stuff | |
var infoBox = layer.leafletMap.viz.addOverlay({ | |
type: 'infobox', | |
layer: layer, | |
template: '<div class="cartodb-tooltip-content-wrapper"> <h2>{{name}}</h2> <h3>Population</h3> <p>{{pop2005}}<span> hab</span></p> </div>', | |
width: 150, | |
position: 'bottom|right' | |
}); | |
$('box').append(infoBox.render().el); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment