UNPKG

react-leaflet-milsymbol

Version:
54 lines (53 loc) 2.21 kB
(function(global, factory) { typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("react-leaflet"), require("leaflet"), require("milsymbol")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "react-leaflet", "leaflet", "milsymbol"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.ReactLeafletMilsymbol = {}, global.jsxRuntime, global.React, global.ReactLeaflet, global.L, global.milsymbol)); })(this, function(exports2, jsxRuntime, react, reactLeaflet, leaflet, ms) { "use strict"; const useMilSymbol = (sidc, options = {}) => { return react.useMemo(() => { return new ms.Symbol(sidc, { size: options.size ?? 35, ...options }); }, [options, sidc]); }; const MilSymbol = ({ position, sidc, size = 35, options = {}, tooltipContent, popupContent, eventHandlers }) => { const markerRef = react.useRef(null); const milSymbol = useMilSymbol(sidc, { size, ...options }); const divIcon = react.useMemo(() => new leaflet.DivIcon({ html: milSymbol.asDOM(), className: "", iconSize: [milSymbol.getSize().width, milSymbol.getSize().height], iconAnchor: [milSymbol.getAnchor().x, milSymbol.getAnchor().y] }), [milSymbol]); react.useEffect(() => { if (markerRef.current) { markerRef.current.setIcon(divIcon); } }, [divIcon, sidc, size, options]); return /* @__PURE__ */ jsxRuntime.jsxs( reactLeaflet.Marker, { position, icon: divIcon, ref: markerRef, eventHandlers, children: [ tooltipContent && /* @__PURE__ */ jsxRuntime.jsx(reactLeaflet.Tooltip, { children: tooltipContent }), popupContent && /* @__PURE__ */ jsxRuntime.jsx(reactLeaflet.Popup, { children: popupContent }) ] } ); }; exports2.MilSymbol = MilSymbol; exports2.useMilSymbol = useMilSymbol; Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" }); }); //# sourceMappingURL=react-leaflet-milsymbol.umd.js.map