Leaflet zoom out when no tiles -
i have offline map leaflet. due reason of minimal weight in megabytes map has 2 sectors: first sector has zooms 11th 14th. second sector has zooms 11th 17th.
i need when user see map in first sector , want zoom in more 14th zoom map not allow , automatically zoom out 14th zoom.
and when user want zoom second sector - it's work 17th zoom.
i use code:
var layer1 = new l.tilelayer('map/all/{z}/{x}/{y}.png', { minzoom: 11, maxzoom: 14, errortileurl:'empty.png', opacity:1}); var layer2 = new l.tilelayer('map/center/{z}/{x}/{y}.png', { minzoom: 15, maxzoom: 17,errortileurl:'empty.png', opacity:1}); var map = new l.map('map', { center: new l.latlng(55.74178084263216, 37.607244264547475), zoom: 11, minzoom: 11, maxzoom: 17, layers: [layer1,layer2] });
you can catch event when map's zoom level changes, , make appropriate decisions here based on 1 of sectors showing.
i'm not sure how you're determining sector shown, example code below has comment. put logic in here determining layer shown.
// called when map zoom changes map.on('zoomend', function() { if (/*the map set sector 1*/) { // if user zooms past 14, set them 14. if (map.getzoom() > 14) { map.setzoom(14); } } });
Comments
Post a Comment