Skip to content Skip to sidebar Skip to footer

Leaflet.js Setmaxbounds Ignores Southern Bound

Using Leaflet.js for an open-source map project, but I need to set specific bounds the user can't move beyond. The maxBounds property of the map object works as expected on the nor

Solution 1:

When you use setBounds then leaflet called L.Map.panInsideBounds with your bounds, where are you trying get projection: viewSw = this.project(viewBounds.getSouthWest()), which use next code for default projection:

project: function (latlng) { // (LatLng) -> Pointvar d = L.LatLng.DEG_TO_RAD,
    max = this.MAX_LATITUDE,
    lat = Math.max(Math.min(max, latlng.lat), -max),
    x = latlng.lng * d,
    y = lat * d;

    y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));

    returnnew L.Point(x, y);
}

So there are Math.max(Math.min(max, latlng.lat), -max) can't be more then max or min value and viewSw became equal to max value and real bounds not fixed.

This issue was fixed. You can use version from master or wait when next realise will be come.

Post a Comment for "Leaflet.js Setmaxbounds Ignores Southern Bound"