diff --git a/packages/core/src/services/config/IConfigService.ts b/packages/core/src/services/config/IConfigService.ts index f516ad673f..518d6f07d1 100644 --- a/packages/core/src/services/config/IConfigService.ts +++ b/packages/core/src/services/config/IConfigService.ts @@ -8,6 +8,7 @@ export interface ISceneConfig extends IRenderConfig { map: IMapWrapper; logoPosition?: PositionName; logoVisible?: boolean; + animate?: boolean; fitBoundsOptions?: mapboxgl.FitBoundsOptions; } diff --git a/packages/react/src/component/LayerAttribute/Layer.tsx b/packages/react/src/component/LayerAttribute/Layer.tsx index e122727df1..a90a30ee39 100644 --- a/packages/react/src/component/LayerAttribute/Layer.tsx +++ b/packages/react/src/component/LayerAttribute/Layer.tsx @@ -113,12 +113,6 @@ export default function BaseLayer(type: string, props: ILayerProps) { } }, [options?.blend]); - // useEffect(() => { - // if (layer && layer.inited && options && options.autoFit === true) { - // layer.fitBounds(); - // } - // }, [options?.autoFit]); - return layer !== null && layer !== undefined ? ( diff --git a/packages/scene/src/index.ts b/packages/scene/src/index.ts index 64561fc14e..54f35c1029 100644 --- a/packages/scene/src/index.ts +++ b/packages/scene/src/index.ts @@ -58,6 +58,7 @@ class Scene private popupService: IPopupService; private fontService: IFontService; private interactionService: IInteractionService; + private animate: boolean; private fitBoundsOptions: mapboxgl.FitBoundsOptions; private container: Container; @@ -67,7 +68,8 @@ class Scene map, logoPosition, logoVisible = true, - fitBoundsOptions = { animate: true }, + animate = true, + fitBoundsOptions = {}, } = config; this.fitBoundsOptions = fitBoundsOptions; // 创建场景容器 @@ -281,7 +283,11 @@ class Scene bound: Bounds, fitBoundsOptions?: mapboxgl.FitBoundsOptions, ): void { - this.mapService.fitBounds(bound, this.fitBoundsOptions || fitBoundsOptions); + this.mapService.fitBounds( + bound, + // 选项优先级:用户传入,覆盖animate直接配置,覆盖Scene配置项传入 + fitBoundsOptions || { ...this.fitBoundsOptions, animate: this.animate }, + ); } public setZoomAndCenter(zoom: number, center: Point): void {