UNPKG

@uiw/react-baidu-map-ground-overlay

Version:

Baidu Map ground-overlay Components for React.

44 lines 1.23 kB
import { useEffect, useState } from 'react'; import { useMapContext } from '@uiw/react-baidu-map-map'; import { useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils'; export function useGroundOverlay(props) { if (props === void 0) { props = {}; } var [groundOverlay, setGroundOverlay] = useState(); var { bounds, opacity, imageURL, displayOnMinLevel, displayOnMaxLevel } = props; var { map } = useMapContext(); useEffect(() => { if (!groundOverlay && bounds && map) { var instance = new BMap.GroundOverlay(bounds, { opacity, imageURL, displayOnMinLevel, displayOnMaxLevel }); map.addOverlay(instance); setGroundOverlay(instance); return () => { if (map && instance) { map.removeOverlay(instance); } }; } // eslint-disable-next-line react-hooks/exhaustive-deps }, [map]); useVisiable(groundOverlay, props); useEventProperties(groundOverlay, props, ['Click', 'DblClick']); useProperties(groundOverlay, props, ['Bounds', 'Opacity', 'ImageURL', 'DisplayOnMinLevel', 'DispalyOnMaxLevel']); return { groundOverlay, setGroundOverlay }; }