From a7efec97141180a488bbb498283dfbdf8bc0cdbe Mon Sep 17 00:00:00 2001 From: xiongjj Date: Tue, 15 Oct 2024 09:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feature=E3=80=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E6=B8=85=E7=A9=BA=E7=BB=93?= =?UTF-8?q?=E6=9E=9Csource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mapboxgl/_utils/HightlighLayer.ts | 6 +++--- src/mapboxgl/query/QueryViewModel.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/mapboxgl/_utils/HightlighLayer.ts b/src/mapboxgl/_utils/HightlighLayer.ts index 1b9d2670..8be4ab20 100644 --- a/src/mapboxgl/_utils/HightlighLayer.ts +++ b/src/mapboxgl/_utils/HightlighLayer.ts @@ -2,7 +2,6 @@ import mapboxgl from 'vue-iclient/static/libs/mapboxgl/mapbox-gl-enhance'; import CircleStyle from 'vue-iclient/src/mapboxgl/_types/CircleStyle'; import LineStyle from 'vue-iclient/src/mapboxgl/_types/LineStyle'; import FillStyle from 'vue-iclient/src/mapboxgl/_types/FillStyle'; -import { AnyLayer } from 'mapbox-gl'; interface HighlightStyle { circle: InstanceType; @@ -110,6 +109,7 @@ export default class HighlightLayer extends mapboxgl.Evented { filterFields?: string[]; clickTolerance = 5; map: mapboxglTypes.Map; + fire: (type: string, params?: any) => void; constructor(options: HighlightLayerOptions) { super(); @@ -186,7 +186,7 @@ export default class HighlightLayer extends mapboxgl.Evented { layout: Object.assign({}, LAYER_DEFAULT_STYLE[type].layout, layerStyle?.layout), filter }); - this.map.addLayer(highlightLayer as AnyLayer); + this.map.addLayer(highlightLayer as mapboxglTypes.AnyLayer); this.targetLayerIds.push(id); this.targetLayerIds = this._uniqueLayerIds(this.targetLayerIds); } @@ -199,7 +199,7 @@ export default class HighlightLayer extends mapboxgl.Evented { layout: Object.assign({}, LAYER_DEFAULT_STYLE['strokeLine'].layout, layerStyle?.layout), filter }); - this.map.addLayer(highlightLayer as AnyLayer); + this.map.addLayer(highlightLayer as mapboxglTypes.AnyLayer); } } diff --git a/src/mapboxgl/query/QueryViewModel.js b/src/mapboxgl/query/QueryViewModel.js index f38724f3..47ae5c2c 100644 --- a/src/mapboxgl/query/QueryViewModel.js +++ b/src/mapboxgl/query/QueryViewModel.js @@ -43,10 +43,17 @@ export default class QueryViewModel extends HighlightLayer { clearResultLayer() { if (this.map) { - this.strokeLayerID && this.map.getLayer(this.strokeLayerID) && this.map.removeLayer(this.strokeLayerID); - this.layerID && this.map.getLayer(this.layerID) && this.map.removeLayer(this.layerID); this.removeHighlightLayers(); this.unregisterLayerMouseEvents(); + const layerIds = [this.strokeLayerID, this.layerID].filter(item => !!item); + layerIds.forEach(item => { + if (this.map.getLayer(item)) { + this.map.removeLayer(item); + } + if (this.map.getSource(item)) { + this.map.removeSource(item); + } + }); } }