Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 地图倾角操作后添加新的控件报错 #135

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const MapViewSettingControl: React.FC<MapViewSettingProps> = (props) => {
const [rotateValue, setRotateValue] = useState<number>();
const isGaode = scene?.getType() === 'amap2';
const styles = useStyle();
const [open, setOpen] = useState(false);

const onPitchChange = (value: number) => {
setMapViewState({ pitch: value });
Expand All @@ -36,7 +37,7 @@ const MapViewSettingControl: React.FC<MapViewSettingProps> = (props) => {
};

useEffect(() => {
if (scene) {
if (scene && open) {
const onMapSelectPitch = () => {
setPitchValue(Math.round(scene.getPitch()));
const currentRotation = scene.getRotation();
Expand All @@ -63,7 +64,7 @@ const MapViewSettingControl: React.FC<MapViewSettingProps> = (props) => {
scene?.off('moveend', onMapSelectPitch);
};
}
}, [scene]);
}, [scene, open]);

// 判断气泡方向
const onPlacement = useMemo(() => {
Expand All @@ -87,7 +88,14 @@ const MapViewSettingControl: React.FC<MapViewSettingProps> = (props) => {

return (
<CustomControl position={position} className={CLS_PREFIX}>
<Popover arrow={false} placement={onPlacement} content={content} trigger="click">
<Popover
arrow={false}
placement={onPlacement}
content={content}
trigger="click"
open={open}
onOpenChange={(open: boolean) => setOpen(open)}
>
<Tooltip placement={onPlacement} title="地图倾角">
<div className={classNames(`${CLS_PREFIX}__setting-btn`, styles.settingBtn)}>
<Icon component={MapViewSettingControlSvg} />
Expand Down
12 changes: 8 additions & 4 deletions packages/li-sdk/src/state/map.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,9 +51,14 @@ class MapStore extends BaseStore<MapState> {
}

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

Expand Down
Loading