Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 1x 1x 1x 1x 1x 1x 1x | import { useEffect, useState } from 'react';
import { useMapContext } from '@uiw/react-baidu-map-map';
import { useProperties, useVisiable } from '@uiw/react-baidu-map-utils';
import { NavigationControlProps } from './';
export interface UseNavigationControl extends NavigationControlProps {}
export function useNavigationControl(props = {} as UseNavigationControl) {
const [navigationControl, setNavigationControl] = useState<BMap.NavigationControl>();
const { anchor, offset, type, showZoomInfo, enableGeolocation } = props;
const { map } = useMapContext();
useEffect(() => {
if (!map || navigationControl) return;
const instance = new BMap.NavigationControl({
anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
offset,
type,
showZoomInfo,
enableGeolocation,
});
map.addControl(instance);
setNavigationControl(instance);
return () => {
if (map && instance) {
map.removeControl(instance);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [map]);
useVisiable(navigationControl!, props);
useProperties<BMap.NavigationControl, UseNavigationControl>(navigationControl!, props, ['Anchor', 'Offset', 'Type']);
return {
navigationControl,
setNavigationControl,
};
}
|