Merge pull request #221 from antvis/fix/l7-react

修复l7-react中的几个小问题
This commit is contained in:
@thinkinggis 2020-02-22 10:09:30 +08:00 committed by GitHub
commit 4666fc782c
4 changed files with 8 additions and 24 deletions

View File

@ -58,6 +58,10 @@ export default function BaseLayer(type: string, props: ILayerProps) {
// 重绘layer
if (layer) {
mapScene.render();
// 如果autoFit为true执行自适应操作
if (options?.autoFit) {
layer.fitBounds();
}
}
});
@ -65,7 +69,7 @@ export default function BaseLayer(type: string, props: ILayerProps) {
if (layer && layer.inited) {
layer.updateLayerConfig(options);
}
}, [options?.maxZoom, options?.maxZoom, options?.visible, options?.autoFit]);
}, [options?.maxZoom, options?.maxZoom, options?.visible]);
useEffect(() => {
if (layer && layer.inited && options && options.zIndex) {

View File

@ -14,7 +14,7 @@ export const LayerEvent = React.memo((props: ILayerProps) => {
useEffect(() => {
layer.on(type, handler);
return () => {
layer.off('type', handler);
layer.off(type, handler);
};
}, [type]);
return null;

View File

@ -4,16 +4,12 @@ import { SceneContext } from './SceneContext';
interface IMapSceneConig {
style?: React.CSSProperties;
// 配置项,比如是否禁止鼠标缩放地图
options?: {
[key: string]: any;
};
className?: string;
map: IMapWrapper;
children?: JSX.Element | JSX.Element[] | Array<JSX.Element | undefined>;
}
export default React.memo((props: IMapSceneConig) => {
const { style, className, map, options } = props;
const { style, className, map } = props;
const container = createRef();
const [scene, setScene] = useState();
useEffect(() => {
@ -23,28 +19,12 @@ export default React.memo((props: IMapSceneConig) => {
});
sceneInstance.on('loaded', () => {
setScene(sceneInstance);
// 禁止鼠标滚轮缩放地图
if (options && !options.enableMouseZoom) {
const mapsService = sceneInstance.getMapService();
if (mapsService && mapsService.getType() === 'mapbox') {
(mapsService.map as any).scrollZoom.disable();
}
// TODO高德地图的禁止待补充
}
});
return () => {
sceneInstance.destroy();
};
}, []);
// 更新地图
useEffect(() => {
if (!scene) {
return;
}
scene.setMapStyle(style);
}, [style]);
return (
<SceneContext.Provider value={scene}>
{createElement(

View File

@ -14,7 +14,7 @@ export const SceneEvent = React.memo((props: ILayerProps) => {
useEffect(() => {
mapScene.on(type, handler);
return () => {
mapScene.off('type', handler);
mapScene.off(type, handler);
};
}, [type]);
return null;