In my React app, I'm using Geoman on a Leaflet map with several Geoman tools. Currently, I have an event listener that verify which tool is used and chose the right function to fire when the user has finished with the tool :
useEffect(() => {
map.on("pm:create", ({ shape, layer }) => {
if (mapMode === MapMode.SPLIT_SPACES) {
handlingSplit(shape, layer);
} else {
handlingCreate(shape, layer);
}
setMapMode(MapMode.NONE);
});
return (): void => {
if (map.hasEventListeners("pm:create")) {
map.removeEventListener("pm:create");
}
};
}, [map, setMapMode, handlingCreate, mapMode]);
I'd like to add a button to trigger the handlingSplit()
function instead of clicking on the points on the map. The problem is, this function needs both shape
and layer
provided by the pm:create
event. Is there any way to get those data ?