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.
This commit is contained in:
ISA
2024-07-12 06:15:54 +02:00
parent 21d5932b8b
commit c793e1c81c
2 changed files with 11 additions and 11 deletions

View File

@@ -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);

10
utils/openInSameWindow.js Normal file
View File

@@ -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");
}
}