Skip to content

Instantly share code, notes, and snippets.

@cspanring
Last active December 27, 2015 16:49
Show Gist options
  • Select an option

  • Save cspanring/7357998 to your computer and use it in GitHub Desktop.

Select an option

Save cspanring/7357998 to your computer and use it in GitHub Desktop.
Basic Leaflet CartoDB Core Example
<!DOCTYPE html>
<html>
<head>
<title>Leaflet CartoDB Core Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id="map"></div>
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.core.js"></script>
<script>
var map = L.map('map').setView([42.373611, -71.110556], 12),
filter = window.location.hash !== '' ? 'WHERE name ILIKE \'' + window.location.hash.slice(1) + '\'' : '',
cartodbLayerOptions = {
user_name: 'cspanring',
sublayers: [{
sql: 'SELECT * FROM cambridge_neighborhoods ' + filter,
cartocss: '#cambridge_neighborhoods { \
polygon-fill: yellow; \
polygon-opacity: 0.2; \
line-width: 2; \
line-color: yellow; \
line-opacity: 1; \
}'
}]
// add map_key for private tables
// ,extra_params: {
// map_key: 'xxxxxxxxxxxx'
// }
};
L.tileLayer('http://{s}.tile.stamen.com/toner-background/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20
}).addTo(map);
cartodb.Tiles.getTiles(cartodbLayerOptions, function(tiles, err) {
if(tiles == null) return;
L.tileLayer(tiles.tiles[0], {
attribution: 'City of Cambridge, MA',
minZoom: 9,
maxZoom: 12
}).addTo(map);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment