Skip to content

Instantly share code, notes, and snippets.

@oriolbx
Created October 16, 2015 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oriolbx/a3332612907c0757ef6a to your computer and use it in GitHub Desktop.
Save oriolbx/a3332612907c0757ef6a to your computer and use it in GitHub Desktop.
sublayers order cartodb createLayer
<!DOCTYPE html>
<html>
<head>
<title>createLayer + two sublayers</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<!-- include cartodb css -->
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
</head>
<body>
<!-- define a map object-->
<div id="map"></div>
<script>
function main() {
// create leaflet map and define some properties
var map = L.map('map', {
zoomControl: false,
center: [43, 0],
zoom: 3
})
// add a base layer to map
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
// add cartodb layer with one layer
cartodb.createLayer(map, {
user_name: 'oboix', // Required
type: 'cartodb', // Required
sublayers: [
{ // first sublayer is the one that is painted at the bottom
sql: "SELECT * FROM populated_places_test", // Required
cartocss: '#populated_places_test{marker-fill: #229A00; marker-allow-overlap: true;}', // Required
},
{ // second sublayer is painted above the previous sublayer
sql: "SELECT * FROM world_table", // Required
cartocss: '#world_table {polygon-fill: #3E7BB6;polygon-opacity: 0.7;line-color: #FFF;line-width: 0.5;line-opacity: 1;}' // Required
}
]
}).addTo(map);
}
// load main() function
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment