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