fix: 修复MapboxScene的容器找不到

This commit is contained in:
聆一 2020-02-22 20:58:08 +08:00
parent ee30732a8a
commit 64a2f53cd4
3 changed files with 6 additions and 5 deletions

View File

@ -33,7 +33,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene.setMapStyle(map.style);
}, [map.style]);
return scene !== undefined ? (
return (
<SceneContext.Provider value={scene}>
{createElement(
'div',
@ -45,7 +45,7 @@ const AMapScene = React.memo((props: IMapSceneConig) => {
scene && props.children,
)}
</SceneContext.Provider>
) : null;
);
});
export default AMapScene;

View File

@ -58,7 +58,7 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
}
}, [map.rotation]);
return scene !== undefined ? (
return (
<SceneContext.Provider value={scene}>
{createElement(
'div',
@ -70,7 +70,7 @@ const MapboxScene = React.memo((props: IMapSceneConig) => {
scene && props.children,
)}
</SceneContext.Provider>
) : null;
);
});
export default MapboxScene;

View File

@ -1,7 +1,8 @@
import { Scene } from '@antv/l7';
import { createContext, useContext } from 'react';
export const SceneContext = createContext({});
// tslint:disable-next-line: no-object-literal-type-assertion
export const SceneContext = createContext<Scene | undefined>({} as Scene);
export function useSceneValue(): Scene {
return (useContext(SceneContext) as unknown) as Scene;
}