From 32fa5bab846140d22f7dfb65b551ef31ed90cbd4 Mon Sep 17 00:00:00 2001 From: "luoxiao-supermap.com" Date: Thu, 14 Sep 2023 16:01:09 +0800 Subject: [PATCH] =?UTF-8?q?[fix]ISVJ-6527=20=E5=8A=A8=E6=80=81=E5=9B=BE?= =?UTF-8?q?=E5=B1=82=E6=95=B0=E6=8D=AE=E5=88=B7=E6=96=B0=E4=BC=9A=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E7=BC=A9=E6=94=BE=20review=20by=20qiw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/api/layer/animate-marker.md | 2 +- .../animate-marker/AnimateMarkerLayer.vue | 4 +- .../AnimateMarkerLayerViewModel.ts | 12 +++--- .../__tests__/AnimateMarkerLayer.spec.js | 37 +++++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/docs/zh/api/layer/animate-marker.md b/docs/zh/api/layer/animate-marker.md index 1905637e..f1475919 100644 --- a/docs/zh/api/layer/animate-marker.md +++ b/docs/zh/api/layer/animate-marker.md @@ -20,5 +20,5 @@ | textFontSize | 字体大小 | number | - | 14 | | textColor | 字体颜色 | string | - | '#fff' | | textField | 显示字段 | string | - | - | -| fitBounds | 是否自适应 | boolean | - | false | +| fitBounds | 是否自适应 | boolean | - | true | | mapTarget | 关联地图容器 ID。如果该参数省略,则默认绑定其父组件为地图组件的 Map 实例或者第一个地图组件的 Map 实例 | string | - | - | diff --git a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayer.vue b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayer.vue index 6167568d..1d5aa063 100644 --- a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayer.vue +++ b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayer.vue @@ -52,14 +52,14 @@ class AnimateMarkerLayer extends Mixins(MapGetter) { @Prop() textField: string; - @Prop() fitBounds: boolean; + @Prop() fitBounds: boolean = true; @Watch('features') featuresChanged(newVal, oldVal) { if (this.viewModel && !isEqual(newVal, oldVal)) { this._pointFeatures = this._getPointFeatures(this.features); this._getMarkerElement(this._pointFeatures); - this._markersElement.length > 0 && this.viewModel.setFeatures(this._pointFeatures, this._markersElement); + this._markersElement.length > 0 && this.viewModel.setFeatures(this._pointFeatures, this._markersElement, !oldVal); } } diff --git a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts index 441d495d..6b9ca762 100644 --- a/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts +++ b/src/mapboxgl/web-map/layer/animate-marker/AnimateMarkerLayerViewModel.ts @@ -37,21 +37,21 @@ export default class AnimateMarkerLayerViewModel extends mapboxgl.Evented { this._initalizeMarkerLayer(); } - public setFeatures(features, markersElement) { + public setFeatures(features, markersElement, fitBounds?) { this.markersElement = markersElement; this.features = features; - this._initalizeMarkerLayer(); + this._initalizeMarkerLayer(fitBounds); } - private _initalizeMarkerLayer() { + private _initalizeMarkerLayer(fitBounds?) { if (!this.features || JSON.stringify(this.features) === '{}') { return; } this.removed(); - this._createMarker(); + this._createMarker(fitBounds); } - private _createMarker() { + private _createMarker(fitBounds = true) { if ( this.markersElement.length === 0 || !this.map || @@ -71,7 +71,7 @@ export default class AnimateMarkerLayerViewModel extends mapboxgl.Evented { this.markers.push(marker); } }, this); - if (this.fitBounds) { + if (this.fitBounds && fitBounds) { // @ts-ignore const bounds = bbox(transformScale(envelope(this.features), 1.7)); this.fitBounds && 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 985c7ecd..d58faf5b 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 @@ -394,4 +394,41 @@ describe('AnimateMarkerLayer.vue', () => { expect(wrapper.vm.mapTarget).toBe('map'); done(); }); + + it('change features fitBounds', async done => { + const newFeatures= { + features: [ + { + geometry: { + type: 'Point', + coordinates: [122, 53] + }, + properties: { + SmID: '10' + }, + type: 'Feature' + } + ], + type: 'FeatureCollection' + }; + wrapper = mount(SmAnimateMarkerLayer, { + propsData: { + mapTarget: 'map', + textField: 'name' + } + }); + await mapSubComponentLoaded(wrapper); + const mockFn = jest.fn(); + wrapper.vm.viewModel._createMarker = mockFn; + await wrapper.setProps({ + features + }); + expect(mockFn.mock.calls).toEqual([[true]]); + await mapSubComponentLoaded(wrapper); + await wrapper.setProps({ + features: newFeatures + }); + expect(mockFn.mock.calls).toEqual([[ true ], [ false ]]); + done(); + }); });