Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet: set min/maxZoom dynamically

Tags:

leaflet

I'm using Leaflet v0.7 and there seem to be no setters for min/maxZoom on the map or tileLayer.

Is there any way to set these values dynamically?

like image 748
bardu Avatar asked Dec 11 '14 19:12

bardu


People also ask

How do you set a min zoom in leaflet?

To enable it, use the map's zoomSnap option. The zoomSnap option has a default value of 1 (which means that the zoom level of the map can be 0 , 1 , 2 , and so on). If you set the value of zoomSnap to 0.5 , the valid zoom levels of the map will be 0 , 0.5 , 1 , 1.5 , 2 , and so on.

What is setView in leaflet?

setView : Set the view of the map (center and zoom level) flyTo : Flys to a given location/zoom-level using smooth pan-zoom. fitBounds : Set the bounds of a map. flyToBounds : Flys to given bound using smooth pan/zoom. setMaxBounds : Restricts the map view to the given bounds.

How do you reset the map on leaflet?

A reset view control for Leaflet. Move the map then click the reset button to see the reset effect.

What is tile layer in leaflet?

Used to load and display tile layers on the map, implements ILayer interface.


1 Answers

If you have your map initialized

var map = L.map('map').setView([51.505, -0.09], 13);

then you can simply do:

map.options.minZoom = 12;
map.options.maxZoom = 14;

Example JSFiddle.

like image 145
yarl Avatar answered Oct 15 '22 17:10

yarl