mirror of https://gitee.com/antv-l7/antv-l7
commit
4666fc782c
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue