Skip to content

Commit

Permalink
fix(leaflet-map-adapter): min zoom behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rendrom committed Apr 3, 2024
1 parent f97e5c4 commit c02c30e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/leaflet-map-adapter/src/LeafletMapAdapter.ts
Expand Up @@ -108,6 +108,8 @@ export class LeafletMapAdapter implements MapAdapter<Map, any, Control> {
zoom,
...mapAdapterOptions,
});

this._updateMinZoomForBounds();
// create default pane
const defPane = this.map.createPane('order-0');
(this.map as any)._addUnselectCb = (def: UnselectDef) => {
Expand Down Expand Up @@ -355,7 +357,7 @@ export class LeafletMapAdapter implements MapAdapter<Map, any, Control> {
const map = this.map;
if (container && map && window.ResizeObserver) {
this._resizeObserver = new ResizeObserver(() => {
map.setMinZoom(map.getBoundsZoom(bounds));
this._updateMinZoomForBounds(bounds);
});
this._resizeObserver.observe(container);
}
Expand Down Expand Up @@ -395,4 +397,18 @@ export class LeafletMapAdapter implements MapAdapter<Map, any, Control> {
}
}
}

private _updateMinZoomForBounds(bounds?: LatLngBoundsExpression) {
const map = this.map;
if (map) {
const maxBounds = bounds ?? map.options.maxBounds;
if (maxBounds !== undefined) {
const minZoom = map.getBoundsZoom(maxBounds, true);
map.options.minZoom = minZoom;
if (map.getZoom() < minZoom) {
map.setZoom(minZoom);
}
}
}
}
}

0 comments on commit c02c30e

Please sign in to comment.