fix: close context menu 2 seconds before API call to prevent errors
- Implemented logic to monitor the context menu state and ensure it closes 2 seconds before the 20-second interval API call - Added functionality to log remaining time while the context menu is open for better debugging - Refactored interval handling to reset remaining time and close the context menu properly - Addressed runtime error related to null context menu handling
This commit is contained in:
@@ -37,6 +37,31 @@ export function enablePolylineEvents(polylines, lineColors) {
|
||||
});
|
||||
}
|
||||
|
||||
// Funktion zum Schließen des Kontextmenüs vor dem Intervall
|
||||
const closeContextMenuBeforeInterval = (map) => {
|
||||
if (map && map.contextmenu && map.contextmenu.isVisible && map.contextmenu.isVisible()) {
|
||||
console.log("Schließe Kontextmenü 2 Sekunden vor dem Intervall");
|
||||
map.contextmenu.hide();
|
||||
}
|
||||
};
|
||||
|
||||
// Zeitintervall mit Schließen des Kontextmenüs 2 Sekunden vorher
|
||||
export const startIntervalWithContextMenuHandling = (map) => {
|
||||
setInterval(() => {
|
||||
remainingTime = 20; // Zeit zurücksetzen für den neuen Durchlauf
|
||||
// Kontextmenü überwachen
|
||||
monitorContextMenu(map);
|
||||
|
||||
// Schließe das Kontextmenü 2 Sekunden vor dem API-Aufruf
|
||||
setTimeout(() => {
|
||||
closeContextMenuBeforeInterval(map);
|
||||
}, 18000); // 18 Sekunden warten, dann schließen
|
||||
|
||||
// API-Aufruf oder Logik, die alle 20 Sekunden ausgeführt wird
|
||||
fetchData();
|
||||
}, 20000); // 20-Sekunden-Intervall
|
||||
};
|
||||
|
||||
export const setupPolylines = (map, linePositions, lineColors, tooltipContents, setNewCoords, tempMarker, currentZoom, currentCenter) => {
|
||||
const markers = [];
|
||||
const polylines = [];
|
||||
@@ -223,6 +248,7 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
console.log("Link der Linie (via Rechtsklick):", link);
|
||||
localStorage.setItem("lastElementType", "polyline");
|
||||
localStorage.setItem("polylineLink", link);
|
||||
closeContextMenuBeforeInterval(map);
|
||||
});
|
||||
|
||||
polylines.push(polyline);
|
||||
|
||||
Reference in New Issue
Block a user