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); + } + }); } }