Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maxZoom and User Input

Tags:

leaflet

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?

like image 252
Mia Avatar asked Jan 29 '13 14:01

Mia


4 Answers

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;

like image 93
Rahul G Nair Avatar answered Nov 19 '22 10:11

Rahul G Nair


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.

like image 36
flup Avatar answered Nov 19 '22 08:11

flup


This works for me:

L.tileLayer('...', { minZoom: 5, maxZoom: 15 }).addTo(map)

like image 5
EvilInside Avatar answered Nov 19 '22 09:11

EvilInside


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.

like image 2
Andy E Avatar answered Nov 19 '22 10:11

Andy E