Merge pull request #224 from antvis/fix/react-scene

fix: 修复MapboxScene的容器找不到
This commit is contained in:
Claire_Yecao 2020-02-22 22:23:36 +08:00 committed by GitHub
commit 547ebf4403
4 changed files with 8 additions and 7 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

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

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