UNPKG

react-naver-maps

Version:

React Navermaps API integration for modern development.

61 lines (59 loc) 1.66 kB
import { useNavermaps } from "./chunk-2R4EMKHB.mjs"; import { HandleEvents } from "./chunk-533MYCRP.mjs"; import { Overlay } from "./chunk-IV7GZJYG.mjs"; // src/overlays/ground-overlay.tsx import pick from "lodash.pick"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { jsx } from "react/jsx-runtime"; var kvoKeys = [ "clickable", "opacity" ]; var kvoEvents = kvoKeys.map((key) => `${key}_changed`); var uiEvents = [ "mousedown", "mouseup", "click", "dblclick", "rightclick", "mouseover", "mouseout", "mousemove" ]; var events = [...uiEvents, ...kvoEvents]; var GroundOverlay = forwardRef(function GroundOverlay2(props, ref) { const options = pick(props, kvoKeys); const { url, bounds } = props; const navermaps = useNavermaps(); const [groundOverlay, setGroundOverlay] = useState(() => new navermaps.GroundOverlay(url, bounds, options)); useImperativeHandle(ref, () => groundOverlay, [groundOverlay]); useEffect(() => { if (groundOverlay.getUrl() !== url || groundOverlay.getBounds().equals(bounds)) { setGroundOverlay(new naver.maps.GroundOverlay(url, bounds, options)); } }, [url, bounds]); useEffect(() => { kvoKeys.forEach((key) => { if (options[key] && groundOverlay.get(key) !== options[key]) { groundOverlay.set(key, options[key]); } }); }, kvoKeys.map((key) => options[key])); return /* @__PURE__ */ jsx(Overlay, { element: groundOverlay, children: /* @__PURE__ */ jsx(HandleEvents, { events, listeners: props }) }); }); export { GroundOverlay }; //# sourceMappingURL=chunk-U6FCVLAX.mjs.map