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 { openInNewTab } from "./openInNewTab.js";
|
||||||
import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines.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) {
|
if (mapRef.current) {
|
||||||
const initMap = L.map(mapRef.current, {
|
const initMap = L.map(mapRef.current, {
|
||||||
center: [53.111111, 8.4625],
|
center: [53.111111, 8.4625],
|
||||||
@@ -24,14 +24,9 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
|
|||||||
text: "Station öffnen (Tab)",
|
text: "Station öffnen (Tab)",
|
||||||
icon: "/img/screen_new.png",
|
icon: "/img/screen_new.png",
|
||||||
callback: (e) => {
|
callback: (e) => {
|
||||||
const lastElementType = localStorage.getItem("lastElementType");
|
const clickedMarker = e.relatedTarget;
|
||||||
if (lastElementType === "polyline") {
|
if (clickedMarker) {
|
||||||
const storedLink = localStorage.getItem("polylineLink");
|
// Verwende die Funktion zum Öffnen in einem neuen Tab
|
||||||
if (storedLink) {
|
|
||||||
window.open(storedLink, "_blank");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const clickedMarker = e.relatedTarget;
|
|
||||||
openInNewTab(e, clickedMarker);
|
openInNewTab(e, clickedMarker);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -50,20 +45,5 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
|
|||||||
|
|
||||||
setMap(initMap);
|
setMap(initMap);
|
||||||
setOms(overlappingMarkerSpiderfier);
|
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
|
// /utils/openInNewTab.js
|
||||||
import { BASE_URL } from "../config/urls";
|
|
||||||
|
|
||||||
export function openInNewTab(e, target) {
|
export function openInNewTab(e, target) {
|
||||||
|
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
|
||||||
let link;
|
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;
|
const idLD = target.options.idLD;
|
||||||
if (idLD) {
|
if (idLD) {
|
||||||
link = `${BASE_URL}cpl.aspx?id=${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.");
|
console.error("Keine gültige 'idLD' für die Linie gefunden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (target instanceof L.Marker && target.options.link) {
|
|
||||||
link = BASE_URL + target.options.link;
|
|
||||||
} else {
|
} else {
|
||||||
console.error("Fehler: Ungültiges Ziel oder keine gültige 'link' Eigenschaft.");
|
console.error("Fehler: Ungültiges Ziel oder keine gültige 'link' Eigenschaft.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Öffne den Link in einem neuen Tab
|
// Ö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