Skip to content

Commit

Permalink
[fix]ISVJ-6527 动态图层数据刷新会重新缩放 review by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Sep 14, 2023
1 parent 0f78198 commit 4a99d01
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/zh/api/layer/animate-marker.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
| textFontSize | 字体大小 | number | - | 14 |
| textColor | 字体颜色 | string | - | '#fff' |
| textField | 显示字段 | string | - | - |
| fitBounds | 是否自适应 | boolean | - | false |
| fitBounds | 是否自适应 | boolean | - | true |
| mapTarget | 关联地图容器 ID。如果该参数省略,则默认绑定其父组件为地图组件的 Map 实例或者第一个地图组件的 Map 实例 | string | - | - |
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 4a99d01

Please sign in to comment.