From a25a9f772406f432a6abad470b9727faf79ac661 Mon Sep 17 00:00:00 2001 From: qiwei Date: Fri, 10 Nov 2023 15:23:00 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=8A=A8=E6=80=81=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E5=9B=BE=E5=B1=82=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9=E5=9B=BE?= =?UTF-8?q?=E5=B1=82=E5=90=8D=20review=20by=20luox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnimateMarkerLayerViewModel.ts | 9 +++++ .../__tests__/AnimateMarkerLayer.spec.js | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts index e80e69a2..af9e7a03 100644 --- a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts +++ b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts @@ -49,6 +49,15 @@ export default class AnimateMarkerLayerViewModel extends mapboxgl.Evented { this._initalizeMarkerLayer(fitBounds); } + public setLayerId(layerId) { + if (!this.features || JSON.stringify(this.features) === '{}') { + return; + } + this.removed(); + this.layerId = layerId; + this._createMarker(); + } + private _initalizeMarkerLayer(fitBounds?) { if (!this.features || JSON.stringify(this.features) === '{}') { return; diff --git a/src/mapboxgl/web-map/layer/animate-marker/__tests__/AnimateMarkerLayer.spec.js b/src/mapboxgl/web-map/layer/animate-marker/__tests__/AnimateMarkerLayer.spec.js index 197ffa61..6da19ff2 100644 --- a/src/mapboxgl/web-map/layer/animate-marker/__tests__/AnimateMarkerLayer.spec.js +++ b/src/mapboxgl/web-map/layer/animate-marker/__tests__/AnimateMarkerLayer.spec.js @@ -465,4 +465,38 @@ describe('AnimateMarkerLayer.vue', () => { expect(wrapper.vm.viewModel.layerId).toBe('test-id'); done(); }); + + it('change layerId', async done => { + const newFeatures= { + features: [ + { + geometry: { + type: 'Point', + coordinates: [122, 53] + }, + properties: { + SmID: '10' + }, + type: 'Feature' + } + ], + type: 'FeatureCollection' + }; + wrapper = mount(SmAnimateMarkerLayer, { + propsData: { + features: newFeatures, + mapTarget: 'map', + textField: 'name', + layerId: 'test-id1' + } + }); + const spy = jest.spyOn(wrapper.vm.viewModel, 'setLayerId'); + await mapSubComponentLoaded(wrapper); + await wrapper.setProps({ + layerId: 'test-id2' + }); + expect(spy).toHaveBeenCalled(); + expect(wrapper.vm.viewModel.layerId).toBe('test-id2'); + done(); + }); });