UNPKG

@davedev42/react-naver-maps

Version:

React Navermaps API integration for modern development.

64 lines (62 loc) 1.58 kB
import { omitUndefined } from "./chunk-SOBCLIXD.mjs"; import { useNavermaps } from "./chunk-JX27UDSU.mjs"; import { HandleEvents } from "./chunk-TMGZDWPN.mjs"; import { Overlay } from "./chunk-P2HFB547.mjs"; // src/overlays/polygon.tsx import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { jsx } from "react/jsx-runtime"; var kvoKeys = [ "paths", "strokeWeight", "strokeOpacity", "strokeColor", "strokeStyle", "strokeLineCap", "strokeLineJoin", "fillColor", "fillOpacity", "clickable", "visible", "zIndex" ]; var kvoEvents = kvoKeys.map((key) => `${key}_changed`); var uiEvents = [ "mousedown", "mouseup", "click", "dblclick", "rightclick", "mouseover", "mouseout", "mousemove" ]; var events = [...uiEvents, ...kvoEvents]; var Polygon = forwardRef(function Polygon2(props, ref) { const { paths } = props; const options = { paths, ...Object.fromEntries(kvoKeys.filter((key) => key !== "paths").map((key) => [key, props[key]])) }; const navermaps = useNavermaps(); const [polygon] = useState(() => new navermaps.Polygon(options)); useImperativeHandle(ref, () => polygon); useEffect(() => { const cleanOptions = omitUndefined(options); if (Object.keys(cleanOptions).length > 0) { polygon.setOptions(cleanOptions); } }, kvoKeys.map((key) => options[key])); return /* @__PURE__ */ jsx(Overlay, { element: polygon, children: /* @__PURE__ */ jsx(HandleEvents, { events, listeners: props }) }); }); export { Polygon }; //# sourceMappingURL=chunk-OZA2XCCQ.mjs.map