Links für alle Geräte funktioniert aber für die Linien muss noch bearbeitet werden
This commit is contained in:
@@ -9,7 +9,7 @@ import { addContextMenuToMarker } from "./addContextMenuToMarker.js";
|
||||
import { openInNewTab } from "./openInNewTab.js";
|
||||
import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines.js";
|
||||
|
||||
export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItemsToMapContextMenu, hasRights, setPolylineEventsDisabled) => {
|
||||
export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItemsToMapContextMenu, hasRights) => {
|
||||
if (mapRef.current) {
|
||||
const initMap = L.map(mapRef.current, {
|
||||
center: [53.111111, 8.4625],
|
||||
@@ -24,14 +24,9 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
|
||||
text: "Station öffnen (Tab)",
|
||||
icon: "/img/screen_new.png",
|
||||
callback: (e) => {
|
||||
const lastElementType = localStorage.getItem("lastElementType");
|
||||
if (lastElementType === "polyline") {
|
||||
const storedLink = localStorage.getItem("polylineLink");
|
||||
if (storedLink) {
|
||||
window.open(storedLink, "_blank");
|
||||
}
|
||||
} else {
|
||||
const clickedMarker = e.relatedTarget;
|
||||
const clickedMarker = e.relatedTarget;
|
||||
if (clickedMarker) {
|
||||
// Verwende die Funktion zum Öffnen in einem neuen Tab
|
||||
openInNewTab(e, clickedMarker);
|
||||
}
|
||||
},
|
||||
@@ -50,20 +45,5 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
|
||||
|
||||
setMap(initMap);
|
||||
setOms(overlappingMarkerSpiderfier);
|
||||
|
||||
// Polyline-Ereignisse deaktivieren, wenn das Kontextmenü geöffnet wird
|
||||
initMap.on("contextmenu.show", function () {
|
||||
//setPolylineEventsDisabled(true);
|
||||
});
|
||||
|
||||
// Polyline-Ereignisse aktivieren, wenn das Kontextmenü geschlossen wird
|
||||
initMap.on("contextmenu.hide", function () {
|
||||
//setPolylineEventsDisabled(false);
|
||||
});
|
||||
|
||||
initMap.whenReady(() => {
|
||||
console.log("Karte ist jetzt bereit und initialisiert.");
|
||||
addItemsToMapContextMenu(hasRights);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
// /utils/openInNewTab.js
|
||||
import { BASE_URL } from "../config/urls";
|
||||
|
||||
export function openInNewTab(e, target) {
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
|
||||
let link;
|
||||
|
||||
if (target instanceof L.Polyline) {
|
||||
// Überprüfen, ob es sich um einen Marker handelt und ein gültiger Link vorhanden ist
|
||||
if (target instanceof L.Marker && target.options.link) {
|
||||
// Verwende den Link, der im Marker gespeichert ist
|
||||
link = `${BASE_URL}${target.options.link}`;
|
||||
//link = target.options.link;
|
||||
} else if (target instanceof L.Polyline) {
|
||||
// Polyline-Logik bleibt unverändert
|
||||
const idLD = target.options.idLD;
|
||||
if (idLD) {
|
||||
link = `${BASE_URL}cpl.aspx?id=${idLD}`;
|
||||
@@ -12,13 +18,15 @@ export function openInNewTab(e, target) {
|
||||
console.error("Keine gültige 'idLD' für die Linie gefunden.");
|
||||
return;
|
||||
}
|
||||
} else if (target instanceof L.Marker && target.options.link) {
|
||||
link = BASE_URL + target.options.link;
|
||||
} else {
|
||||
console.error("Fehler: Ungültiges Ziel oder keine gültige 'link' Eigenschaft.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Öffne den Link in einem neuen Tab
|
||||
window.open(link, "_blank");
|
||||
if (link) {
|
||||
window.open(link, "_blank");
|
||||
} else {
|
||||
console.error("Fehler: Es wurde kein gültiger Link gefunden.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user