80 lines
2.2 KiB
HTML
80 lines
2.2 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<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="http://cartodb.com/assets/favicon.ico" />
|
||
|
<style>
|
||
|
html, body, #map {
|
||
|
height: 100%;
|
||
|
padding: 0;
|
||
|
margin: 0;
|
||
|
}
|
||
|
</style>
|
||
|
|
||
|
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/3.13/themes/css/cartodb.css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="map"></div>
|
||
|
|
||
|
<!-- include cartodb.js library -->
|
||
|
<script src="https://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
|
||
|
|
||
|
<script>
|
||
|
|
||
|
function main() {
|
||
|
|
||
|
// create leaflet map
|
||
|
var map = L.map('map', {
|
||
|
zoomControl: false,
|
||
|
center: [43, 0],
|
||
|
zoom: 3
|
||
|
})
|
||
|
|
||
|
// add cartodb layer with multiple sublayers of different types
|
||
|
cartodb.createLayer(map, {
|
||
|
user_name: 'examples',
|
||
|
type: 'cartodb',
|
||
|
sublayers: [
|
||
|
{
|
||
|
type: "http",
|
||
|
urlTemplate: "http://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png",
|
||
|
subdomains: [ "a", "b", "c" ]
|
||
|
},
|
||
|
{
|
||
|
sql: 'select * from country_boundaries',
|
||
|
cartocss: '#layer { polygon-fill: #F00; polygon-opacity: 0.3; line-color: #F00; }'
|
||
|
},
|
||
|
],
|
||
|
}, { filter: ['http', 'mapnik'] })
|
||
|
.addTo(map)
|
||
|
.done(function(layer) {
|
||
|
setTimeout(function() {
|
||
|
layer.getSubLayer(0).setURLTemplate(
|
||
|
'https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png'
|
||
|
)
|
||
|
}, 4000);
|
||
|
|
||
|
setTimeout(function() {
|
||
|
layer.createSubLayer({
|
||
|
type: 'http',
|
||
|
urlTemplate: 'http://{s}.tile.stamen.com/toner-labels/{z}/{x}/{y}.png',
|
||
|
subdomains: [ "a", "b", "c" ]
|
||
|
}, 2);
|
||
|
}, 8000);
|
||
|
|
||
|
setTimeout(function() {
|
||
|
layer.getSubLayer(2).hide();
|
||
|
}, 12000);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// you could use $(window).load(main);
|
||
|
window.onload = main;
|
||
|
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|