Leaflet zoom overridden by maxZoom

leaflet maxnativezoom
leaflet fitbounds zoom level
leaflet smooth zoom
leaflet zoom r
leaflet world map
leaflet zoom out
leaflet zoom level display
leaflet get zoom level

Issue:

So my issue is that maxZoom seems to over ride the zoom in Leaflet.

From the docs, zoom description is: Initial map zoom.

The code I am using is as follows.

Code:

var map = L.map('map', {
    maxZoom: 18,
    zoom: 17,
    zoomControl: false
}).locate({
    setView: true,
}); // set default location to current GPS location

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
}).addTo(map);

Result: The result is that the initial zoom is 18 instead of 17.

Expected Behavior: What I want is the max zoom to go no more than 18 but start out initially as 17.

I raised this topic a bit late and don't know if you already managed to fix the issue. I hit the same problem on a project I am currently working on and I found a solution by using setZoom() method.

On my specific case I am using Leaflet version 0.7.x and to me it was enough to concatenate the method to fitBounds() like in the example below:

map.fitBounds(group.getBounds(), {
   padding: [30, 30]
}).setZoom(settings.zoom.initialZoom);

As I didn't find that much documentation regarding this specific issue, I post my solution here with the hope it can help anyone else should face the same problem.

Autoscaling behavior when zooming past a layer's maxZoom · Issue , Maximum zoom level of the map. This overrides any maxZoom set on map layers. The TileMapServiceCatalogItem's maxZoom attribute is being correctly overridden and the maximumLevel is being correctly set to level 23. this.options.maxZoom is also being set to 23. I think the Bing level of 20 is somehow overriding the max zoom. I think setting the max zoom setting on the map however may work

Try adding the maxzoom and minzoom to your tilelayer. I have the starting zoom set in setView (13 there is the starting zoom). Hope it helps a bit, because i'm not sure how it works when u get your location by gps.

var map = L.map('map').setView([8.939, 3.541], 13);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
minZoom:7,
attribution: 'OpenStreetMap'
}).addTo(map);

Kristjan

Zoom >= 19 seems to be not working · Issue #5289 · Leaflet/Leaflet , Zoom = 18 with Leaflet - OK http://playground-leaflet.rhcloud zoom level of the map. Overrides any maxZoom option set on map layers. maxzoom doesn't work over 18 #387. Closed it has tiles over zoom 18. the max zoom is set to 20 but angular-leaflet-directive doesn't try to load it.

I guess that the .locate() function resets the zoom to a level that is appropriate for the supplied user location. If you don't want this, you can set a separate maxZoom for this, too.

Zoom levels - Leaflet, Lower zoom levels means that the map shows entire continents, while higher var map = L.map('map', { minZoom: 0, maxZoom: 0 }); var cartodbAttribution  Issue: So my issue is that maxZoom seems to over ride the zoom in Leaflet. From the docs, zoom description is: Initial map zoom. The code I am using is as follows. Code: var map = L.map('map',

Documentation - Leaflet, Returns the maximum zoom level of the map (if set in the maxZoom option of the Set it to false if you want to override the default behavior of the popup closing  The opening zoom level is 18 - zoom in and the Bing Maps layer should not be removed. If you comment out the maxNativeZoom and maxZoom lines, the Bing Maps layers is removed when you zoom in. (I couldn't get it to work on JS Fiddle using Leaflet 1.2.0 but didn't bother trying to debug why)

Touch zoom, Maximum zoom level of the map. Overrides any maxZoom option set on map layers. layers, Layer[], [], Array of layers that  Forces the map's zoom level to always be a multiple of this, particularly right after a fitBounds() or a pinch-zoom. By default, the zoom level snaps to the nearest integer; lower values (e.g. 0.5 or 0.1 ) allow for greater granularity.

L.Map, maxZoom, Number, null, Maximum zoom level of the map. This overrides any maxZoom set on map layers. maxBounds, LatLngBounds, null, When this option is  Leaflet.MiniMap. Leaflet.MiniMap is a simple minimap control that you can drop into your leaflet map, and it will create a small map in the corner which shows the same as the main map with a set zoom offset. (By default it is -5.) Using the MiniMap control

Comments
  • Accepting this as answer. Unfortunately because of several issues (at the time) with Leaflet, we had to abandon it for our project.
  • No problem mate. I know my answer is quite late but I decided to post my solution anyway to just keep it as kind of reminder ;)
  • I have tried writing zoom in the .locate() function but this changes nothing. It should be noted that I also tried writing this in the L.tileLayer() method call.