import React, { useEffect, useRef, useState } from "react"; import L from "leaflet"; import "leaflet/dist/leaflet.css"; const MapComponent = () => { const mapRef = useRef(null); const [map, setMap] = useState(null); useEffect(() => { if (mapRef.current && !map) { const initialMap = L.map(mapRef.current, { center: [53.111111, 8.4625], zoom: 10, }); initialMap.on("contextmenu", (event) => { L.popup() .setLatLng(event.latlng) .setContent( '

Right-click menu

' ) .openOn(initialMap); }); window.zoomIn = () => { initialMap.zoomIn(); }; L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { attribution: '© OpenStreetMap contributors', }).addTo(initialMap); setMap(initialMap); } }, [mapRef, map]); return (
); }; export default MapComponent;