From 6392ca276e2f18fcae486c422d49e7a1907410e7 Mon Sep 17 00:00:00 2001 From: Harel Mazor Date: Fri, 13 Mar 2020 21:31:34 +0200 Subject: [PATCH] Move to use vector tiles #1171 - Fix attributiuon. --- .../automatic-layer-presentation.component.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/IsraelHiking.Web/sources/application/components/map/automatic-layer-presentation.component.ts b/IsraelHiking.Web/sources/application/components/map/automatic-layer-presentation.component.ts index 6fc6f4e59..f410b84a3 100644 --- a/IsraelHiking.Web/sources/application/components/map/automatic-layer-presentation.component.ts +++ b/IsraelHiking.Web/sources/application/components/map/automatic-layer-presentation.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit, OnChanges, SimpleChanges, OnDestroy } from "@angular/core"; import { MapComponent } from "ngx-mapbox-gl"; -import { RasterSource, RasterLayout, Layer, Style } from "mapbox-gl"; +import { RasterSource, RasterLayout, Layer, Style, Sources } from "mapbox-gl"; import { Subscription } from "rxjs"; import { ResourcesService } from "../../services/resources.service"; @@ -14,6 +14,9 @@ import { BaseMapComponent } from "../base-map.component"; export class AutomaticLayerPresentationComponent extends BaseMapComponent implements OnInit, OnChanges, OnDestroy { private static indexNumber = 0; + private static readonly ATTRIBUTION = "" + + "Click me to see attribution" + @Input() public address: string; @Input() @@ -109,8 +112,7 @@ export class AutomaticLayerPresentationComponent extends BaseMapComponent implem maxzoom: this.maxZoom, scheme, tileSize: 256, - attribution: "" + - "Click me to see attribution" + attribution: AutomaticLayerPresentationComponent.ATTRIBUTION } as RasterSource; this.host.mapInstance.addSource(this.rasterSourceId, source); let layer = { @@ -139,13 +141,18 @@ export class AutomaticLayerPresentationComponent extends BaseMapComponent implem this.updateSourcesAndLayers(styleJson.sources, styleJson.layers); } - private updateSourcesAndLayers(sources: {}, layers: Layer[]) { - for (let sourceKey in sources) { + private updateSourcesAndLayers(sources: Sources, layers: Layer[]) { + let attributiuonUpdated = false; + for (let sourceKey of Object.keys(sources)) { if (sources.hasOwnProperty(sourceKey) && this.visible) { let source = sources[sourceKey]; if (!this.isBaselayer) { sourceKey = this.key + "_" + sourceKey; } + if (source.type === "vector") { + source.attribution = attributiuonUpdated == false ? AutomaticLayerPresentationComponent.ATTRIBUTION : ""; + attributiuonUpdated = true; + } this.jsonSourcesIds.push(sourceKey); this.host.mapInstance.addSource(sourceKey, source); }