improved Popup handleing
This commit is contained in:
@@ -5,26 +5,39 @@ import { Popup, useMap } from "react-leaflet";
|
||||
|
||||
export const ContextMenu = () => {
|
||||
const map = useMap();
|
||||
const { popup, setSearchElements, setPopup, setSearchPopup } = useMapStore();
|
||||
const {
|
||||
contextMenu,
|
||||
setContextMenu,
|
||||
setSearchElements,
|
||||
setSearchPopup,
|
||||
setOpenMissionMarker,
|
||||
openMissionMarker,
|
||||
} = useMapStore();
|
||||
|
||||
useEffect(() => {
|
||||
map.on("contextmenu", (e) => {
|
||||
setPopup({ isOpen: true, lat: e.latlng.lat, lng: e.latlng.lng });
|
||||
setSearchPopup(undefined);
|
||||
// setOpenMissionMarker({ open: [], close: openMissionMarker });
|
||||
setContextMenu({ lat: e.latlng.lat, lng: e.latlng.lng });
|
||||
// setSearchPopup(null);
|
||||
});
|
||||
}, [popup]);
|
||||
}, [contextMenu]);
|
||||
|
||||
if (!popup) return null;
|
||||
if (!contextMenu) return null;
|
||||
|
||||
return (
|
||||
<Popup position={[popup.lat, popup.lng]}>
|
||||
<Popup
|
||||
position={[contextMenu.lat, contextMenu.lng]}
|
||||
autoClose={false}
|
||||
closeOnClick={false}
|
||||
autoPan={false}
|
||||
>
|
||||
{/* // TODO: maske: */}
|
||||
<div className="absolute transform -translate-y-1/2 z-1000 opacity-100 pointer-events-auto p-3">
|
||||
<button
|
||||
className="btn btn-sm rounded-full bg-amber-600 hover:bg-amber-700 aspect-square"
|
||||
onClick={async () => {
|
||||
const address = await fetch(
|
||||
`https://nominatim.openstreetmap.org/reverse?lat=${popup.lat}&lon=${popup.lng}&format=json`,
|
||||
`https://nominatim.openstreetmap.org/reverse?lat=${contextMenu.lat}&lon=${contextMenu.lng}&format=json`,
|
||||
);
|
||||
const data = (await address.json()) as {
|
||||
address: {
|
||||
@@ -62,8 +75,8 @@ export const ContextMenu = () => {
|
||||
`https://overpass-api.de/api/interpreter?data=${encodeURIComponent(`
|
||||
[out:json];
|
||||
(
|
||||
way["building"](around:100, ${popup.lat}, ${popup.lng});
|
||||
relation["building"](around:100, ${popup.lat}, ${popup.lng});
|
||||
way["building"](around:100, ${contextMenu.lat}, ${contextMenu.lng});
|
||||
relation["building"](around:100, ${contextMenu.lat}, ${contextMenu.lng});
|
||||
);
|
||||
out body;
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user