react-leaflet-milsymbol
Version:
A React Leaflet v4 wrapper for the milsymbol library
50 lines (49 loc) • 1.22 kB
JavaScript
import { jsxs as S, jsx as s } from "react/jsx-runtime";
import { useMemo as l, useRef as y, useEffect as g } from "react";
import { Marker as a, Tooltip as z, Popup as b } from "react-leaflet";
import { DivIcon as d } from "leaflet";
import p from "milsymbol";
const x = (o, r = {}) => {
const i = JSON.stringify(r);
return l(() => new p.Symbol(o, {
size: r.size ?? 35,
...r
}), [i, o]);
}, k = ({
position: o,
sidc: r,
size: i = 35,
options: f = {},
tooltipContent: t,
popupContent: m,
children: h,
eventHandlers: u
}) => {
const n = y(null), e = x(r, { size: i, ...f }), c = l(() => new d({
html: e.asSVG(),
className: "",
iconSize: [e.getSize().width, e.getSize().height],
iconAnchor: [e.getAnchor().x, e.getAnchor().y]
}), [e]);
return g(() => {
n.current && n.current.setIcon(c);
}, [c]), /* @__PURE__ */ S(
a,
{
position: o,
icon: c,
ref: n,
eventHandlers: u,
children: [
t && /* @__PURE__ */ s(z, { children: t }),
m && /* @__PURE__ */ s(b, { children: m }),
h
]
}
);
};
export {
k as MilSymbol,
x as useMilSymbol
};
//# sourceMappingURL=react-leaflet-milsymbol.es.js.map