56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
// components/useMapContextMenu.js
|
|
import { toast } from "react-toastify";
|
|
import { zoomIn, zoomOut, centerHere } from "../utils/zoomAndCenterUtils";
|
|
|
|
const addItemsToMapContextMenu = (map, menuItemAdded, setMenuItemAdded, openModalWithCoordinates, hasRights, setShowPopup, setPopupCoordinates) => {
|
|
if (!menuItemAdded && map && map.contextmenu) {
|
|
map.contextmenu.addItem({
|
|
text: "Koordinaten anzeigen",
|
|
icon: "img/not_listed_location.png",
|
|
callback: openModalWithCoordinates,
|
|
});
|
|
|
|
map.contextmenu.addItem({ separator: true });
|
|
|
|
map.contextmenu.addItem({
|
|
text: "Reinzoomen",
|
|
icon: "img/zoom_in.png",
|
|
callback: (e) => zoomIn(e, map),
|
|
});
|
|
|
|
map.contextmenu.addItem({
|
|
text: "Rauszoomen",
|
|
icon: "img/zoom_out.png",
|
|
callback: () => zoomOut(map),
|
|
});
|
|
|
|
map.contextmenu.addItem({
|
|
text: "Hier zentrieren",
|
|
icon: "img/center_focus.png",
|
|
callback: (e) => centerHere(e, map),
|
|
});
|
|
|
|
if (localStorage.getItem("editMode") === "true") {
|
|
map.contextmenu.addItem({ separator: true });
|
|
map.contextmenu.addItem({
|
|
text: "POI hinzufügen",
|
|
icon: "img/add_station.png",
|
|
className: "background-red",
|
|
callback: (event) => {
|
|
const editMode = localStorage.getItem("editMode") === "true";
|
|
if (editMode && hasRights) {
|
|
setPopupCoordinates(event.latlng);
|
|
setShowPopup(true);
|
|
} else {
|
|
toast.error("Benutzer hat keine Berechtigung zum Hinzufügen.");
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
setMenuItemAdded(true);
|
|
}
|
|
};
|
|
|
|
export default addItemsToMapContextMenu;
|