eine Beispiel Marker einfügen und entferne Standard-Zoomsteuerung

This commit is contained in:
ISA
2024-04-15 10:48:46 +02:00
parent afee410333
commit a051d47aab
33 changed files with 75 additions and 86 deletions

View File

@@ -6,19 +6,23 @@ const MapComponent = () => {
const mapRef = useRef(null);
const [map, setMap] = useState(null);
function addMarker(map) {
const marker = L.marker([53.111111, 8.4625]).addTo(map);
marker.bindPopup("<b>Hallo Welt!</b><br>Ich bin ein Popup.").openPopup();
}
useEffect(() => {
if (mapRef.current && !map) {
const initialMap = L.map(mapRef.current, {
center: [53.111111, 8.4625],
zoom: 10,
zoomControl: false, // Deaktiviere die Standard-Zoomsteuerung
});
initialMap.on("contextmenu", (event) => {
L.popup()
.setLatLng(event.latlng)
.setContent(
'<p>Right-click menu<br/><button onclick="zoomIn()">Zoom in</button></p>'
)
.setContent('<p><button onclick="zoomIn()">Zoom in</button></p>')
.openOn(initialMap);
});
@@ -30,6 +34,7 @@ const MapComponent = () => {
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(initialMap);
addMarker(initialMap);
setMap(initialMap);
}