fix(react): 高德地图地图状态同步

This commit is contained in:
thinkinggis 2020-08-17 15:16:05 +08:00
parent ad607fcdeb
commit aad458ab85
1 changed files with 25 additions and 4 deletions

View File

@ -32,13 +32,34 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
sceneInstance.destroy();
};
}, []);
// 更新地图样式
useEffect(() => {
if (!scene) {
return;
if (scene && map.style) {
scene.setMapStyle(map.style);
}
scene.setMapStyle(map.style);
}, [map.style]);
}, [JSON.stringify(map.style)]);
useEffect(() => {
if (scene && map.zoom) {
scene.setZoom(map.zoom);
}
}, [map.zoom]);
useEffect(() => {
if (scene && map.center) {
scene.setCenter(map.center);
}
}, [JSON.stringify(map.center)]);
useEffect(() => {
if (scene && map.pitch) {
scene.setPitch(map.pitch);
}
}, [map.pitch]);
useEffect(() => {
if (scene && map.rotation) {
scene.setRotation(map.rotation);
}
}, [map.rotation]);
return (
<SceneContext.Provider value={scene}>
{createElement(