From 09fa42d4f9776d8eddd129efc98d5245211cd7df Mon Sep 17 00:00:00 2001 From: HarelM Date: Wed, 25 Dec 2024 18:06:56 +0200 Subject: [PATCH] Resolves #2087 - Do not allow overlapping layer on the same baselayer --- .../automatic-layer-presentation.component.ts | 30 ++++++++++--------- .../components/map/layers-view.component.html | 3 +- .../components/map/layers-view.component.ts | 4 +++ .../application/services/layers.service.ts | 15 ---------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/IsraelHiking.Web/src/application/components/map/automatic-layer-presentation.component.ts b/IsraelHiking.Web/src/application/components/map/automatic-layer-presentation.component.ts index 2a5795fc1..907cfd11b 100644 --- a/IsraelHiking.Web/src/application/components/map/automatic-layer-presentation.component.ts +++ b/IsraelHiking.Web/src/application/components/map/automatic-layer-presentation.component.ts @@ -31,6 +31,7 @@ export class AutomaticLayerPresentationComponent implements OnInit, OnChanges, O public isBaselayer = input(); public layerData = input(); public isMainMap = input(); + public isSameBaselayerOn = input(false); private rasterSourceId: string; private rasterLayerId: string; @@ -155,24 +156,25 @@ export class AutomaticLayerPresentationComponent implements OnInit, OnChanges, O } private updateSourcesAndLayers(layerData: LayerData, sources: {[_: string]: SourceSpecification}, layers: LayerSpecification[]) { + if (!this.visible()) { + return; + } let attributiuonUpdated = false; for (let sourceKey of Object.keys(sources)) { - if (Object.prototype.hasOwnProperty.call(sources, sourceKey) && this.visible()) { - const source = sources[sourceKey]; - if (!this.isBaselayer()) { - sourceKey = layerData.key + "_" + sourceKey; - } - if (source.type === "vector") { - source.attribution = attributiuonUpdated === false ? AutomaticLayerPresentationComponent.ATTRIBUTION : ""; - attributiuonUpdated = true; - } - - this.mapComponent.mapInstance.addSource(sourceKey, source); - this.jsonSourcesIds.push(sourceKey); + const source = sources[sourceKey]; + if (!this.isBaselayer()) { + sourceKey = layerData.key + "_" + sourceKey; } + if (source.type === "vector") { + source.attribution = attributiuonUpdated === false ? AutomaticLayerPresentationComponent.ATTRIBUTION : ""; + attributiuonUpdated = true; + } + + this.mapComponent.mapInstance.addSource(sourceKey, source); + this.jsonSourcesIds.push(sourceKey); } for (const layer of layers) { - if (!this.visible() || (!this.isBaselayer() && layer.metadata && !(layer.metadata as any)["IHM:overlay"])) { + if (!this.isBaselayer() && layer.metadata && !(layer.metadata as any)["IHM:overlay"]) { continue; } if (!this.isBaselayer()) { @@ -226,7 +228,7 @@ export class AutomaticLayerPresentationComponent implements OnInit, OnChanges, O if (oldLayer != null) { this.removeLayer(oldLayer); } - if (newLayer != null) { + if (newLayer != null && !this.isSameBaselayerOn()) { await this.createLayer(newLayer); } }); diff --git a/IsraelHiking.Web/src/application/components/map/layers-view.component.html b/IsraelHiking.Web/src/application/components/map/layers-view.component.html index d60e95043..fff41d820 100644 --- a/IsraelHiking.Web/src/application/components/map/layers-view.component.html +++ b/IsraelHiking.Web/src/application/components/map/layers-view.component.html @@ -9,7 +9,8 @@ [visible]="overlay.visible" [before]="resources.endOfOverlays" [isBaselayer]="false" - [isMainMap]="true"> + [isMainMap]="true" + [isSameBaselayerOn]="isSameBaselayerOn(overlay)"> o.key === HIKING_TRAILS).visible && this.selectedBaseLayerKey === ISRAEL_HIKING_MAP || - this.overlays.find(o => o.key === BICYCLE_TRAILS).visible && this.selectedBaseLayerKey === ISRAEL_MTB_MAP)) { - this.toastService.warning(this.resources.baseLayerAndOverlayAreOverlapping); - } } public isAllOverlaysHidden() {