From c1a7e25173922f42719793ff38e04852de3cd593 Mon Sep 17 00:00:00 2001 From: "ext.sopra.ncastejon" <castejon.nicolas@gmail.com> Date: Wed, 13 May 2020 14:17:00 +0200 Subject: [PATCH] Set the 3d layer url in config.json file. Enable the feature in the map only if this url is informed. --- src/app/core/services/app-config.service.ts | 3 ++ src/app/map/components/map.component.ts | 34 ++++++++++++--------- src/app/map/services/map.service.ts | 16 +++++----- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/app/core/services/app-config.service.ts b/src/app/core/services/app-config.service.ts index 8a59a134..b320a1e2 100644 --- a/src/app/core/services/app-config.service.ts +++ b/src/app/core/services/app-config.service.ts @@ -17,6 +17,9 @@ export class AppConfig { proxyQuery: string; seo: string; }; + layer3d: { + url: string; + }; theFunctionalitiesInterruptor: { credits: boolean; reuses: boolean; diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index 5aa6e8ae..75473bb5 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -2,6 +2,7 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import * as mapboxgl from 'mapbox-gl'; import { Subscription } from 'rxjs'; import { geosource } from '../../../i18n/traductions'; +import { APP_CONFIG } from '../../core/services/app-config.service'; import { linkFormats } from '../../shared/models'; import { MapOptions } from '../models/map-options'; import { GeocoderService } from '../services/geocoder.service'; @@ -211,22 +212,25 @@ export class MapComponent implements OnInit, OnDestroy { this._mapService.addLayers(); }); - this.map.on('zoomend', () => { - if (this.map.getZoom() < 14) { - this.displayButton3d = false; - - if (this.map.getLayer('3d-layer')) { - // this.display3d = false; - this.map.removeLayer('3d-layer'); - } - - } else if (this.map.getZoom() > 14) { - this.displayButton3d = true; - if (this.display3d) { - this._mapService.switch3DLayer(); + // Manage the 3d layer button only if config contains the url 3d layer + if (APP_CONFIG.layer3d) { + this.map.on('zoomend', () => { + if (this.map.getZoom() < 14) { + this.displayButton3d = false; + + if (this.map.getLayer('3d-layer')) { + // this.display3d = false; + this.map.removeLayer('3d-layer'); + } + + } else if (this.map.getZoom() > 14) { + this.displayButton3d = true; + if (this.display3d) { + this._mapService.switch3DLayer(); + } } - } - }); + }); + } } } diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts index 054da24c..77ad3ec6 100644 --- a/src/app/map/services/map.service.ts +++ b/src/app/map/services/map.service.ts @@ -118,13 +118,13 @@ export class MapService { this.addWMSLayer(); // Add the 3d source. Constructed with MVT tiles from the 'fpc_fond_plan_communaut.fpctoit' dataset - const domain = this.mapOptions.vectorService.url.split('wfs')[1]; - const url = `${this.mapOptions.mvtUrl}${domain}?LAYERS= -fpc_fond_plan_communaut.fpctoit&map.imagetype=mvt&tilemode=gmap&tile={x}+{y}+{z}&mode=tile`; - this._map.addSource('3d-source', { - type: 'vector', - tiles: [url], - }); + if (APP_CONFIG.layer3d) { + const url = APP_CONFIG.layer3d.url; + this._map.addSource('3d-source', { + type: 'vector', + tiles: [url], + }); + } // Add the data layer only if it comes from the Lyon Metropole if (this.mapOptions.rasterService.url.includes(`${APP_CONFIG.backendUrls.proxyQuery}/map/wms`)) { @@ -519,7 +519,7 @@ fpc_fond_plan_communaut.fpctoit&map.imagetype=mvt&tilemode=gmap&tile={x}+{y}+{z} } switch3DLayer() { - if (!this._map.getLayer('3d-layer')) { + if (!this._map.getLayer('3d-layer') && this._map.getSource('3d-source')) { this._map.addLayer( { -- GitLab