2017-04-05 04:04:46 +08:00
|
|
|
---
|
|
|
|
layout: tutorial_frame
|
|
|
|
title: Zoom Levels Tutorial
|
|
|
|
---
|
|
|
|
<script>
|
|
|
|
|
|
|
|
var map = L.map('map', {
|
|
|
|
minZoom: 0,
|
|
|
|
maxZoom: 1
|
|
|
|
});
|
|
|
|
|
2018-03-12 15:46:20 +08:00
|
|
|
var cartodbAttribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>';
|
2017-04-05 04:04:46 +08:00
|
|
|
|
|
|
|
var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
|
|
|
|
attribution: cartodbAttribution
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
setInterval(function(){
|
|
|
|
|
|
|
|
map.setZoom(0);
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
map.setZoom(1);
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
}, 4000);
|
|
|
|
|
|
|
|
var ZoomViewer = L.Control.extend({
|
|
|
|
onAdd: function(){
|
|
|
|
var gauge = L.DomUtil.create('div');
|
|
|
|
gauge.style.width = '200px';
|
|
|
|
gauge.style.background = 'rgba(255,255,255,0.5)';
|
|
|
|
gauge.style.textAlign = 'left';
|
|
|
|
map.on('zoomstart zoom zoomend', function(ev){
|
|
|
|
gauge.innerHTML = 'Zoom level: ' + map.getZoom();
|
|
|
|
})
|
|
|
|
return gauge;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
(new ZoomViewer).addTo(map);
|
|
|
|
|
|
|
|
map.setView([0, 0], 0);
|
|
|
|
</script>
|