Skip to content

Commit

Permalink
Move to use vector tiles #1171 - Fix attributiuon.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Mar 13, 2020
1 parent 513e665 commit 6392ca2
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = "<a href='https://github.com/IsraelHikingMap/Site/wiki/Attribution' target='_blank'>" +
"Click me to see attribution</a>"

@Input()
public address: string;
@Input()
Expand Down Expand Up @@ -109,8 +112,7 @@ export class AutomaticLayerPresentationComponent extends BaseMapComponent implem
maxzoom: this.maxZoom,
scheme,
tileSize: 256,
attribution: "<a href='https://github.com/IsraelHikingMap/Site/wiki/Attribution' target='_blank'>" +
"Click me to see attribution</a>"
attribution: AutomaticLayerPresentationComponent.ATTRIBUTION
} as RasterSource;
this.host.mapInstance.addSource(this.rasterSourceId, source);
let layer = {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6392ca2

Please sign in to comment.