I want to limit the users max zoom level with inputs (muse scroll etc.) and buttons. In other words, I limit the "maxZoom" to -lets say- level9. But I still want to be able to zoom to level10 in special conditions. When I set the maxZoom, it obviously does not let me zoom more in any way, so wht is my solution in this case?
For setting maximum zoom level :
map._layersMaxZoom=15 (which sets the maximum zoomlevel as 15)
Similarly we can set minimum zoom level:
map._layersMinZoom=2, (which sets minimum zoomlevel as 2).
Another way of doing the same-
map.options.maxZoom = 15;
map.options.minZoom = 10;
You can set the map's maximum zoom level dynamically with map.options.maxZoom
in those special conditions and set it back when you are done.
This works for me:
L.tileLayer('...', { minZoom: 5, maxZoom: 15 }).addTo(map)
If you're displaying the controls and you change the maxZoom
or minZoom
options, the controls won't be updated. For example, if your min zoom level is 10 and the current zoom level is 10, the zoom out control will appear disabled even if you change the zoom level.
One workaround for this solution is to trigger a 'zoomend' event on the map:
map.options.minZoom = 9;
map.fire('zoomend');
You might also want to consider calling the setZoom()
method if you change the max/min zoom levels in a way that invalidates the current zoom level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With