UNPKG

react-bkoi-gl

Version:

React components for Barikoi GL JS

46 lines 1.37 kB
import { useImperativeHandle, useRef, useEffect, forwardRef, memo } from "react"; import { applyReactStyle } from "../utils/apply-react-style.js"; import { useControl } from "./use-control.js"; function _GeolocateControl(props, ref) { const thisRef = useRef({ props }); const ctrl = useControl(_ref => { let { mapLib } = _ref; const gc = new mapLib.GeolocateControl(props); const setupUI = gc._setupUI; gc._setupUI = () => { if (!gc._container.hasChildNodes()) { setupUI(); } }; gc.on("geolocate", e => { thisRef.current.props.onGeolocate?.(e); }); gc.on("error", e => { thisRef.current.props.onError?.(e); }); gc.on("outofmaxbounds", e => { thisRef.current.props.onOutOfMaxBounds?.(e); }); gc.on("trackuserlocationstart", e => { thisRef.current.props.onTrackUserLocationStart?.(e); }); gc.on("trackuserlocationend", e => { thisRef.current.props.onTrackUserLocationEnd?.(e); }); return gc; }, { position: props.position }); thisRef.current.props = props; useImperativeHandle(ref, () => ctrl, []); useEffect(() => { applyReactStyle(ctrl._container, props.style); }, [props.style]); return null; } export const GeolocateControl = memo(forwardRef(_GeolocateControl)); //# sourceMappingURL=geolocate-control.js.map