mysql createPool
This commit is contained in:
@@ -131,40 +131,7 @@ export const setupMarkers = async (
|
||||
export const setupPolylines = (map, linePositions, lineColors, tooltipContents, setNewCoords, tempMarker, currentZoom, currentCenter) => {
|
||||
const markers = [];
|
||||
const polylines = [];
|
||||
let isMouseOverMenuItem = false;
|
||||
|
||||
const checkMouseOverMenu = () => {
|
||||
if (!isMouseOverMenuItem) {
|
||||
//showContextMenuItemByIndex(map, 0);
|
||||
//showContextMenuItemByIndex(map, 1);
|
||||
//closeContextMenu(); // Kontextmenü schließen, wenn die Maus nicht mehr darüber ist
|
||||
}
|
||||
};
|
||||
|
||||
const handleMouseOverMenuItem = () => {
|
||||
isMouseOverMenuItem = true;
|
||||
};
|
||||
|
||||
const handleMouseOutMenuItem = () => {
|
||||
isMouseOverMenuItem = false;
|
||||
setTimeout(checkMouseOverMenu, 500); // kleine Verzögerung, um sicherzustellen, dass es keine schnellen Bewegungen sind
|
||||
};
|
||||
|
||||
const closeContextMenu = () => {
|
||||
const contextMenuElement = document.querySelector(".leaflet-contextmenu");
|
||||
if (contextMenuElement) {
|
||||
contextMenuElement.style.display = "none"; // Kontextmenü ausblenden
|
||||
}
|
||||
};
|
||||
|
||||
const handleOutsideClick = (event) => {
|
||||
const contextMenuElement = document.querySelector(".leaflet-contextmenu");
|
||||
if (contextMenuElement && !contextMenuElement.contains(event.target)) {
|
||||
//closeContextMenu(); // Kontextmenü schließen, wenn der Klick außerhalb stattfindet
|
||||
}
|
||||
};
|
||||
|
||||
//document.addEventListener("mousedown", handleOutsideClick);
|
||||
linePositions.forEach((lineData, lineIndex) => {
|
||||
const lineMarkers = [];
|
||||
lineData.coordinates.forEach((coord, index) => {
|
||||
@@ -269,8 +236,6 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
const polyline = L.polyline(lineData.coordinates, {
|
||||
color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
|
||||
contextmenu: true,
|
||||
idLD: lineData.idLD, // Füge die idLD zur Polyline hinzu
|
||||
idModul: lineData.idModul, // Füge die idModul zur Polyline hinzu
|
||||
contextmenuItems: [
|
||||
{
|
||||
text: "Stützpunkt hinzufügen",
|
||||
@@ -290,21 +255,12 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
}).addTo(map);
|
||||
|
||||
polyline.on("mouseover", (e) => {
|
||||
polyline.setStyle({ weight: 15 });
|
||||
});
|
||||
|
||||
polyline.on("mousedown", (e) => {
|
||||
polyline.setStyle({ weight: 15 });
|
||||
});
|
||||
|
||||
polyline.on("mouseup", (e) => {
|
||||
polyline.setStyle({ weight: 15 });
|
||||
polyline.setStyle({ weight: 10 });
|
||||
});
|
||||
|
||||
polyline.on("mouseout", (e) => {
|
||||
polyline.setStyle({ weight: 3 });
|
||||
polyline.setStyle({ color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000" });
|
||||
//setTimeout(checkMouseOverMenu, 500);
|
||||
});
|
||||
|
||||
polyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
|
||||
@@ -316,7 +272,5 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
markers.push(...lineMarkers);
|
||||
});
|
||||
|
||||
// Add listeners to the context menu items
|
||||
const contextMenuElement = document.querySelector(".leaflet-contextmenu"); // Assuming the context menu class is 'leaflet-contextmenu'
|
||||
return { markers, polylines };
|
||||
};
|
||||
|
||||
@@ -40,14 +40,40 @@ export const initializeMap = (mapRef, setMap, setOms, setMenuItemAdded, addItems
|
||||
text: "Station Öffnen (Tab)",
|
||||
icon: "/img/screen_new.png",
|
||||
callback: (e) => {
|
||||
const clickedTarget = lastClickedTarget || findNearestPolyline(initMap, e.latlng); // Verwende zwischengespeichertes Ziel oder die nächstgelegene Linie
|
||||
const clickedTarget = lastClickedTarget || e.relatedTarget || e.layer;
|
||||
|
||||
if (!clickedTarget) {
|
||||
console.error("Kein gültiges Ziel im Kontextmenü");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prüfen, ob das Element eine Station (Marker) oder Linie (Polyline) ist
|
||||
if (clickedTarget instanceof L.Marker) {
|
||||
console.log("Marker angeklickt");
|
||||
openInNewTab(e, clickedTarget);
|
||||
} else if (clickedTarget instanceof L.Polyline) {
|
||||
console.log("Linie angeklickt:", clickedTarget.options.idLD); // Hier kannst du die ID oder andere Optionen der Polyline verwenden
|
||||
// Optional: Funktion zum Öffnen der Linie implementieren
|
||||
openInNewTab(e, clickedTarget);
|
||||
} else {
|
||||
console.error("Unbekanntes Element");
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/* callback: (e) => {
|
||||
//Wenn Kein Station oder ein Station ist
|
||||
const clickedMarker = e.relatedTarget; // Zugriff auf den Marker, der das Event ausgelöst hat
|
||||
openInNewTab(e, clickedMarker);
|
||||
//wenn Linie ist (polyline)
|
||||
const clickedTarget = lastClickedTarget || findNearestPolyline(initMap, e.latlng); // Verwende zwischengespeichertes Ziel oder die nächstgelegene Linie
|
||||
if (clickedTarget) {
|
||||
openInNewTab(e, clickedTarget); // Gemeinsame Funktion für Linien und Stationen
|
||||
} else {
|
||||
console.error("Kein gültiges Ziel im Kontextmenü");
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}, */
|
||||
"-",
|
||||
],
|
||||
});
|
||||
|
||||
40
utils/mysqlPool.js
Normal file
40
utils/mysqlPool.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Variablen für den Singleton-Pool
|
||||
let cachedPool;
|
||||
let connectionCount = 0; // Zähler für die aktiven Verbindungen
|
||||
|
||||
// Funktion zum Abrufen des Pools
|
||||
function getPool() {
|
||||
if (!cachedPool) {
|
||||
cachedPool = mysql.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
connectionLimit: 10, // Setze ein Limit für gleichzeitige Verbindungen
|
||||
waitForConnections: true,
|
||||
queueLimit: 0, // Unbegrenzte Warteschlange für Verbindungen
|
||||
});
|
||||
|
||||
// Ereignisse für das Protokollieren der Verbindungsstatistiken
|
||||
cachedPool.on("acquire", () => {
|
||||
connectionCount++;
|
||||
console.log("Connection acquired. Active connections: ", connectionCount);
|
||||
});
|
||||
|
||||
cachedPool.on("release", () => {
|
||||
connectionCount--;
|
||||
console.log("Connection released. Active connections: ", connectionCount);
|
||||
});
|
||||
|
||||
cachedPool.on("enqueue", () => {
|
||||
console.log("Waiting for available connection slot.");
|
||||
});
|
||||
}
|
||||
|
||||
return cachedPool;
|
||||
}
|
||||
|
||||
export default getPool;
|
||||
Reference in New Issue
Block a user