diff --git a/packages/li-core-assets/src/widgets/MapViewSettingControl/Component.tsx b/packages/li-core-assets/src/widgets/MapViewSettingControl/Component.tsx index dc9e5da0..061adc82 100644 --- a/packages/li-core-assets/src/widgets/MapViewSettingControl/Component.tsx +++ b/packages/li-core-assets/src/widgets/MapViewSettingControl/Component.tsx @@ -18,6 +18,7 @@ const MapViewSettingControl: React.FC = (props) => { const [rotateValue, setRotateValue] = useState(); const isGaode = scene?.getType() === 'amap2'; const styles = useStyle(); + const [open, setOpen] = useState(false); const onPitchChange = (value: number) => { setMapViewState({ pitch: value }); @@ -36,7 +37,7 @@ const MapViewSettingControl: React.FC = (props) => { }; useEffect(() => { - if (scene) { + if (scene && open) { const onMapSelectPitch = () => { setPitchValue(Math.round(scene.getPitch())); const currentRotation = scene.getRotation(); @@ -63,7 +64,7 @@ const MapViewSettingControl: React.FC = (props) => { scene?.off('moveend', onMapSelectPitch); }; } - }, [scene]); + }, [scene, open]); // 判断气泡方向 const onPlacement = useMemo(() => { @@ -87,7 +88,14 @@ const MapViewSettingControl: React.FC = (props) => { return ( - + setOpen(open)} + >
diff --git a/packages/li-sdk/src/state/map.ts b/packages/li-sdk/src/state/map.ts index 2591d287..2438001b 100644 --- a/packages/li-sdk/src/state/map.ts +++ b/packages/li-sdk/src/state/map.ts @@ -1,5 +1,4 @@ import type { Scene } from '@antv/l7'; -import { produce } from 'immer'; import type { MapSchema } from '../specs'; import BaseStore from './base-store'; import { MapStoreEvent } from './constants'; @@ -52,9 +51,14 @@ class MapStore extends BaseStore { } public setMapViewState(viewState: MapState['mapConfig']['config']) { - this.state = produce(this.state, (draftState) => { - draftState.mapConfig.config = viewState; - }); + const originalMapConfig = this.state.mapConfig; + const mapConfig = { + ...originalMapConfig, + config: { ...originalMapConfig.config, ...viewState }, + }; + + this.state = { ...this.state, mapConfig }; + this.emit(MapStoreEvent.UPDATE_VIEWSTATE, viewState); }