Refactoring addContextMenuToMarker.js and openInNewTab.js
This commit is contained in:
11
utils/addContextMenuToMarker.js
Normal file
11
utils/addContextMenuToMarker.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// /utils/addContextMenuToMarker.js
|
||||
|
||||
export function addContextMenuToMarker(marker) {
|
||||
marker.unbindContextMenu(); // Entferne das Kontextmenü, um Duplikate zu vermeiden
|
||||
|
||||
marker.bindContextMenu({
|
||||
contextmenu: true,
|
||||
contextmenuWidth: 140,
|
||||
contextmenuItems: [],
|
||||
});
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// contextMenuUtils.js
|
||||
import { BASE_URL } from "../config/urls";
|
||||
|
||||
export function addContextMenuToMarker(marker) {
|
||||
marker.unbindContextMenu(); // Entferne das Kontextmenü, um Duplikate zu vermeiden
|
||||
|
||||
marker.bindContextMenu({
|
||||
contextmenu: true,
|
||||
contextmenuWidth: 140,
|
||||
contextmenuItems: [],
|
||||
});
|
||||
}
|
||||
|
||||
// Funktion zum Öffnen in einem neuen Tab
|
||||
export function openInNewTab(e, target) {
|
||||
const baseUrl = BASE_URL;
|
||||
let idLD, idModul, link;
|
||||
|
||||
if (target instanceof L.Polyline) {
|
||||
idLD = target.options.idLD;
|
||||
idModul = target.options.idModul;
|
||||
if (idLD) {
|
||||
link = `${baseUrl}cpl.aspx?id=${idLD}`;
|
||||
if (idModul) {
|
||||
//link += `&module=${idModul}`;
|
||||
}
|
||||
} else {
|
||||
console.error("Keine gültige 'idLD' für die Linie gefunden.");
|
||||
return;
|
||||
}
|
||||
} else if (target instanceof L.Marker && target.options.link) {
|
||||
link = baseUrl + 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");
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import "leaflet/dist/leaflet.css";
|
||||
import "leaflet-contextmenu/dist/leaflet.contextmenu.css";
|
||||
import * as urls from "../config/urls.js";
|
||||
import * as layers from "../config/layers.js";
|
||||
import { addContextMenuToMarker, openInNewTab } from "./contextMenuUtils.js";
|
||||
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) => {
|
||||
|
||||
24
utils/openInNewTab.js
Normal file
24
utils/openInNewTab.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// /utils/openInNewTab.js
|
||||
import { BASE_URL } from "../config/urls";
|
||||
|
||||
export function openInNewTab(e, target) {
|
||||
let link;
|
||||
|
||||
if (target instanceof L.Polyline) {
|
||||
const idLD = target.options.idLD;
|
||||
if (idLD) {
|
||||
link = `${BASE_URL}cpl.aspx?id=${idLD}`;
|
||||
} else {
|
||||
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");
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import circleIcon from "../components/gisPolylines/icons/CircleIcon";
|
||||
import startIcon from "../components/gisPolylines/icons/StartIcon";
|
||||
import endIcon from "../components/gisPolylines/icons/EndIcon";
|
||||
import { redrawPolyline } from "./mapUtils";
|
||||
import { openInNewTab } from "../utils/contextMenuUtils";
|
||||
import { openInNewTab } from "../utils/openInNewTab";
|
||||
import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines"; // Importiere die Funktionen
|
||||
|
||||
export const setupPOIs = async (
|
||||
|
||||
@@ -8,7 +8,7 @@ import circleIcon from "../components/gisPolylines/icons/CircleIcon";
|
||||
import startIcon from "../components/gisPolylines/icons/StartIcon";
|
||||
import endIcon from "../components/gisPolylines/icons/EndIcon";
|
||||
import { redrawPolyline } from "./mapUtils";
|
||||
import { openInNewTab } from "./contextMenuUtils";
|
||||
import { openInNewTab } from "./openInNewTab";
|
||||
|
||||
// Funktion zum Deaktivieren der Polyline-Ereignisse
|
||||
export function disablePolylineEvents(polylines) {
|
||||
|
||||
Reference in New Issue
Block a user