From c793e1c81c3dbc575f31db7a7fe77c04e7a5e5ea Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 12 Jul 2024 06:15:54 +0200 Subject: [PATCH] feat: Move openInSameWindow function to a separate file - Moved the openInSameWindow function from MapComponent.js to a new file openInSameWindow.js in the utils directory. - Updated MapComponent.js to import and use the openInSameWindow function from the new file. - This change improves code modularity and readability. --- components/MapComponent.js | 12 +----------- utils/openInSameWindow.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 utils/openInSameWindow.js diff --git a/components/MapComponent.js b/components/MapComponent.js index 6dee11000..70ed0b610 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -78,7 +78,7 @@ import { import { MAP_VERSION } from "../config/settings"; import * as layers from "../config/layers.js"; import useMapContextMenu from "./useMapContextMenu.js"; - +import { openInSameWindow } from "../utils/openInSameWindow"; //--------------------------------------------------------------------- //-------------------- MapComponent ----------------------------------- const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { @@ -235,16 +235,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //---------------------------------------------------- //-----Kontextmenu---------------- - // Funktion zum Öffnen im gleichen Fenster - function openInSameWindow(e, marker) { - if (marker && marker.options && marker.options.link) { - //console.log("Marker data:", baseUrl + marker.options.link); - window.location.href = baseUrl + marker.options.link; - } else { - console.error("Fehler: Marker hat keine gültige 'link' Eigenschaft"); - } - } - const zoomIn = (e) => { initMap.flyTo(e.latlng, 12); //console.log("ZoomIn koordinaten in MapComponent", e.latlng); diff --git a/utils/openInSameWindow.js b/utils/openInSameWindow.js new file mode 100644 index 000000000..214c4719c --- /dev/null +++ b/utils/openInSameWindow.js @@ -0,0 +1,10 @@ +// utils/openInSameWindow.js + +export function openInSameWindow(e, marker, baseUrl) { + if (marker && marker.options && marker.options.link) { + //console.log("Marker data:", baseUrl + marker.options.link); + window.location.href = baseUrl + marker.options.link; + } else { + console.error("Fehler: Marker hat keine gültige 'link' Eigenschaft"); + } +}