85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
// /utils/mapInitialization.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, openInNewTab } from "../utils/contextMenuUtils";
|
|
|
|
export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItemsToMapContextMenu, hasRights) => {
|
|
const offlineTileLayer = urls.OFFLINE_TILE_LAYER;
|
|
const onlineTileLayer = urls.ONLINE_TILE_LAYER;
|
|
const TALAS = layers.MAP_LAYERS.TALAS;
|
|
const ECI = layers.MAP_LAYERS.ECI;
|
|
const ULAF = layers.MAP_LAYERS.ULAF;
|
|
const GSMModem = layers.MAP_LAYERS.GSMModem;
|
|
const CiscoRouter = layers.MAP_LAYERS.CiscoRouter;
|
|
const WAGO = layers.MAP_LAYERS.WAGO;
|
|
const Siemens = layers.MAP_LAYERS.Siemens;
|
|
const OTDR = layers.MAP_LAYERS.OTDR;
|
|
const WDM = layers.MAP_LAYERS.WDM;
|
|
const GMA = layers.MAP_LAYERS.GMA;
|
|
const Sonstige = layers.MAP_LAYERS.Sonstige;
|
|
const TALASICL = layers.MAP_LAYERS.TALASICL;
|
|
|
|
if (mapRef.current) {
|
|
const initMap = L.map(mapRef.current, {
|
|
center: [53.111111, 8.4625],
|
|
zoom: 12,
|
|
layers: [TALAS, ECI, ULAF, GSMModem, CiscoRouter, WAGO, Siemens, OTDR, WDM, GMA, Sonstige, TALASICL],
|
|
minZoom: 5,
|
|
maxZoom: 15,
|
|
zoomControl: false,
|
|
contextmenu: true,
|
|
contextmenuItems: [
|
|
{
|
|
text: "Station öffnen (Tab)",
|
|
icon: "/img/screen_new.png",
|
|
callback: (e) => {
|
|
const lastElementType = localStorage.getItem("lastElementType");
|
|
|
|
if (lastElementType === "polyline") {
|
|
const storedLink = localStorage.getItem("polylineLink");
|
|
if (storedLink) {
|
|
console.log("Opening polyline link:", storedLink);
|
|
window.open(storedLink, "_blank");
|
|
}
|
|
} else if (lastElementType === "marker") {
|
|
const clickedItem = e.relatedTarget;
|
|
if (clickedItem instanceof L.Marker) {
|
|
openInNewTab(e, clickedItem);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
"-",
|
|
],
|
|
});
|
|
|
|
L.tileLayer(onlineTileLayer, {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
}).addTo(initMap);
|
|
|
|
const overlappingMarkerSpiderfier = new OverlappingMarkerSpiderfier(initMap, {
|
|
nearbyDistance: 20,
|
|
});
|
|
|
|
setMap(initMap);
|
|
setOms(overlappingMarkerSpiderfier);
|
|
|
|
initMap.on("zoomend", function () {
|
|
if (initMap.getZoom() > 15) {
|
|
initMap.setZoom(15);
|
|
} else if (initMap.getZoom() < 5) {
|
|
initMap.setZoom(5);
|
|
}
|
|
});
|
|
|
|
initMap.whenReady(() => {
|
|
console.log("Karte ist jetzt bereit und initialisiert.");
|
|
addItemsToMapContextMenu(hasRights);
|
|
});
|
|
}
|
|
};
|