From b6f7966fcbfde3464b6e844620cc7310424d5fa9 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Tue, 17 Nov 2020 18:15:30 +0100 Subject: [PATCH] fix: cleaning makers was removing mdm layer --- src/app/map/components/map.component.ts | 18 +++++++++++++++--- src/app/map/services/map.service.ts | 10 ++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index 9e92dd389..29937bddd 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -8,7 +8,19 @@ import { SimpleChanges, ViewChild, } from '@angular/core'; -import { latLng, MapOptions, tileLayer, Map, CRS, TileLayer, LatLngBounds, latLngBounds, Marker } from 'leaflet'; +import { + latLng, + MapOptions, + tileLayer, + Map, + CRS, + TileLayer, + LatLngBounds, + latLngBounds, + Marker, + layerGroup, + polyline, +} from 'leaflet'; import { Observable } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; import { Structure } from '../../models/structure.model'; @@ -86,8 +98,7 @@ export class MapComponent implements OnChanges { previousStructuresValue.length > 0 && previousStructuresValue.length < this.structures.length ) { - const newStructures = _.differenceWith(this.structures, previousStructuresValue, _.isEqual); - this.getStructuresPositions(newStructures); + this.getStructuresPositions(_.differenceWith(this.structures, previousStructuresValue, _.isEqual)); } else if (this.structures) { this.map = this.mapService.cleanMap(this.map); this.getStructuresPositions(this.structures); @@ -180,6 +191,7 @@ export class MapComponent implements OnChanges { // Init mdm this.initMDMLayer(); // Init WMS service with param from data.grandlyon.com + layerGroup(); const carteLayer = tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png', { attribution: '© <a href="https://carto.com/attributions">CARTO</a>', maxZoom: 19, diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts index 9be8deb95..2f4cc3f1e 100644 --- a/src/app/map/services/map.service.ts +++ b/src/app/map/services/map.service.ts @@ -32,10 +32,10 @@ export class MapService { const markerIcon = divIcon({ className: null, html: '<svg width="19" height="24"><use xlink:href="assets/ico/sprite.svg#mdm"></use></svg>', - iconSize: [35, 41], - iconAnchor: [13, 41], + iconSize: [19, 24], + iconAnchor: [19, 24], }); - return new Marker([lat, lon], { icon: markerIcon }); + return new Marker([lat, lon], { icon: markerIcon, attribution: 'mdm' }); } /** @@ -102,7 +102,9 @@ export class MapService { MapService.markersList = {}; if (map) { map.eachLayer((layer) => { - if (layer instanceof Marker) map.removeLayer(layer); + if (layer instanceof Marker && layer.options.attribution !== 'mdm') { + map.removeLayer(layer); + } }); } return map; -- GitLab