Added ability to define map layers

This commit is contained in:
Davide Passoni 2024-02-29 16:05:21 +01:00
parent a84e190548
commit 6e6da64c51

View File

@ -50,7 +50,7 @@ export type MapMarkerVisibilityControl = {
export class Map extends L.Map {
#ID: string;
#state: string;
#layer: L.TileLayer | null = null;
#layer: L.TileLayer | L.LayerGroup | null = null;
#preventLeftClick: boolean = false;
#leftClickTimer: number = 0;
#deafultPanDelta: number = 100;
@ -281,14 +281,24 @@ export class Map extends L.Map {
if (layerName in this.#mapLayers) {
const layerData = this.#mapLayers[layerName];
var options: L.TileLayerOptions = {
attribution: layerData.attribution,
minZoom: layerData.minZoom,
maxZoom: layerData.maxZoom,
minNativeZoom: layerData.minNativeZoom,
maxNativeZoom: layerData.maxNativeZoom
};
this.#layer = new L.TileLayer(layerData.urlTemplate, options);
if (layerData instanceof Array) {
let layers = layerData.map((layer: any) => {
var options: L.TileLayerOptions = {
attribution: layer.attribution,
minZoom: layer.minZoom,
maxZoom: layer.maxZoom
};
return new L.TileLayer(layer.urlTemplate, options);
})
this.#layer = new L.LayerGroup(layers);
} else {
var options: L.TileLayerOptions = {
attribution: layerData.attribution,
minZoom: layerData.minZoom,
maxZoom: layerData.maxZoom
};
this.#layer = new L.TileLayer(layerData.urlTemplate, options);
}
}
this.#layer?.addTo(this);