[Map] Add options minZoom and maxZoom

Co-authored-by: Nina Alin <56309556+nina-alin@users.noreply.github.com>
This commit is contained in:
Hugo Alliaume
2025-07-07 09:01:18 +02:00
parent 545b7fbff2
commit 51a833d016
3 changed files with 34 additions and 2 deletions

View File

@@ -26,6 +26,8 @@ export default class extends AbstractMapController<MapOptions, LeafletMapOptions
connect(): void;
centerValueChanged(): void;
zoomValueChanged(): void;
minZoomValueChanged(): void;
maxZoomValueChanged(): void;
protected dispatchEvent(name: string, payload?: Record<string, unknown>): void;
protected doCreateMap({ definition }: {
definition: MapDefinition<MapOptions, LeafletMapOptions>;

View File

@@ -23,6 +23,8 @@ class default_1 extends Controller {
const mapDefinition = {
center: this.hasCenterValue ? this.centerValue : null,
zoom: this.hasZoomValue ? this.zoomValue : null,
minZoom: this.hasMinZoomValue ? this.minZoomValue : null,
maxZoom: this.hasMaxZoomValue ? this.maxZoomValue : null,
options: this.optionsValue,
extra,
};
@@ -128,6 +130,8 @@ default_1.values = {
providerOptions: Object,
center: Object,
zoom: Number,
minZoom: Number,
maxZoom: Number,
fitBoundsToMarkers: Boolean,
markers: Array,
polygons: Array,
@@ -159,6 +163,16 @@ class map_controller extends default_1 {
this.map.setZoom(this.zoomValue);
}
}
minZoomValueChanged() {
if (this.map && this.hasMinZoomValue && this.minZoomValue) {
this.map.setMinZoom(this.minZoomValue);
}
}
maxZoomValueChanged() {
if (this.map && this.hasMaxZoomValue && this.maxZoomValue) {
this.map.setMaxZoom(this.maxZoomValue);
}
}
dispatchEvent(name, payload = {}) {
payload.L = L;
this.dispatch(name, {
@@ -167,10 +181,12 @@ class map_controller extends default_1 {
});
}
doCreateMap({ definition }) {
const { center, zoom, options, bridgeOptions = {} } = definition;
const { center, zoom, minZoom, maxZoom, options, bridgeOptions = {} } = definition;
const map = L.map(this.element, {
center: center === null ? undefined : center,
zoom: zoom === null ? undefined : zoom,
minZoom: minZoom === null ? undefined : minZoom,
maxZoom: maxZoom === null ? undefined : maxZoom,
attributionControl: false,
zoomControl: false,
...options,

View File

@@ -87,6 +87,18 @@ export default class extends AbstractMapController<
}
}
public minZoomValueChanged(): void {
if (this.map && this.hasMinZoomValue && this.minZoomValue) {
this.map.setMinZoom(this.minZoomValue);
}
}
public maxZoomValueChanged(): void {
if (this.map && this.hasMaxZoomValue && this.maxZoomValue) {
this.map.setMaxZoom(this.maxZoomValue);
}
}
protected dispatchEvent(name: string, payload: Record<string, unknown> = {}): void {
payload.L = L;
this.dispatch(name, {
@@ -96,11 +108,13 @@ export default class extends AbstractMapController<
}
protected doCreateMap({ definition }: { definition: MapDefinition<MapOptions, LeafletMapOptions> }): L.Map {
const { center, zoom, options, bridgeOptions = {} } = definition;
const { center, zoom, minZoom, maxZoom, options, bridgeOptions = {} } = definition;
const map = L.map(this.element, {
center: center === null ? undefined : center,
zoom: zoom === null ? undefined : zoom,
minZoom: minZoom === null ? undefined : minZoom,
maxZoom: maxZoom === null ? undefined : maxZoom,
attributionControl: false,
zoomControl: false,
...options,