50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
// utils/initializeMap.js
|
|
import L from "leaflet";
|
|
import "leaflet-contextmenu";
|
|
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 } from "./addContextMenuToMarker.js";
|
|
import { openInNewTab } from "./openInNewTab.js";
|
|
import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines.js";
|
|
|
|
export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItemsToMapContextMenu, hasRights) => {
|
|
if (mapRef.current) {
|
|
const initMap = L.map(mapRef.current, {
|
|
center: [53.111111, 8.4625],
|
|
zoom: 12,
|
|
layers: [layers.MAP_LAYERS.TALAS, layers.MAP_LAYERS.ECI, layers.MAP_LAYERS.ULAF, layers.MAP_LAYERS.GSMModem],
|
|
minZoom: 5,
|
|
maxZoom: 15,
|
|
zoomControl: false,
|
|
contextmenu: true,
|
|
contextmenuItems: [
|
|
{
|
|
text: "Station öffnen (Tab)",
|
|
icon: "/img/screen_new.png",
|
|
callback: (e) => {
|
|
const clickedMarker = e.relatedTarget;
|
|
if (clickedMarker) {
|
|
// Verwende die Funktion zum Öffnen in einem neuen Tab
|
|
openInNewTab(e, clickedMarker);
|
|
}
|
|
},
|
|
},
|
|
"-",
|
|
],
|
|
});
|
|
|
|
L.tileLayer(urls.ONLINE_TILE_LAYER, {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
}).addTo(initMap);
|
|
|
|
const overlappingMarkerSpiderfier = new OverlappingMarkerSpiderfier(initMap, {
|
|
nearbyDistance: 20,
|
|
});
|
|
|
|
setMap(initMap);
|
|
setOms(overlappingMarkerSpiderfier);
|
|
}
|
|
};
|