fix: POI-Icons erscheinen nun korrekt je nach Typ
- Fehler behoben: Alle POIs zeigten immer dasselbe Icon (z. B. poi-marker-icon-4.png) - Ursache: In setupPOIs.js wurde iconPath fälschlich anhand von idPoiTyp gesucht, obwohl nur idPoi verfügbar war - Lösung: Icon-Zuordnung erfolgt jetzt über Mapping idPoi → path (Map) - Kein Backend-Änderung nötig - Standard-Icon wird verwendet, wenn kein Eintrag im Mapping vorhanden ist # Version: 1.1.166
This commit is contained in:
27
CHANGELOG.md
27
CHANGELOG.md
@@ -4,6 +4,33 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.1.166] – 2025-05-25
|
||||||
|
|
||||||
|
### 🐞 Fixed
|
||||||
|
|
||||||
|
- POI-Icons wurden immer als `poi-marker-icon-4.png` dargestellt, egal welcher Typ
|
||||||
|
- Ursache: `setupPOIs.js` hat versehentlich `poi.idPoi === poi.idPoi` geprüft statt `poi.idPoiTyp === ...`
|
||||||
|
|
||||||
|
### ✅ Clean
|
||||||
|
|
||||||
|
- Korrekte Zuordnung von `idPoi → iconPath` über Map-Mapping implementiert (`iconMap`)
|
||||||
|
- Fallback-Icon `default-icon.png` wird angezeigt, wenn kein Icon verfügbar ist
|
||||||
|
|
||||||
|
### 🧠 Architektur
|
||||||
|
|
||||||
|
- `poiIconsData` wird in Redux geladen und über `setupPOIs` interpretiert
|
||||||
|
- Mapping-Logik in `setupPOIs.js` gekapselt, vorbereitet für Unit-Tests
|
||||||
|
|
||||||
|
### 🧪 Tests
|
||||||
|
|
||||||
|
- Test-Vorbereitung: `setupPOIs.js` wurde entkoppelt für spätere Jest-Tests (TDD-fähig gemacht)
|
||||||
|
|
||||||
|
### 🔧 Version
|
||||||
|
|
||||||
|
- 📦 Version erhöht auf **1.1.166**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### ✅ Test
|
### ✅ Test
|
||||||
|
|
||||||
- Cypress E2E-Test für POI-Bearbeitung eingeführt:
|
- Cypress E2E-Test für POI-Bearbeitung eingeführt:
|
||||||
|
|||||||
16
__tests__/setupPOIs.test.js
Normal file
16
__tests__/setupPOIs.test.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
describe("setupPOIs Icon-Mapping intern", () => {
|
||||||
|
it("ordnet korrektes Icon anhand idPoi zu", () => {
|
||||||
|
const mockPoiData = [{ idPoi: 7, path: "poi-marker-icon-2.png" }];
|
||||||
|
const iconMap = new Map();
|
||||||
|
mockPoiData.forEach((item) => iconMap.set(item.idPoi, item.path));
|
||||||
|
const result = iconMap.get(7);
|
||||||
|
expect(result).toBe("poi-marker-icon-2.png");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("gibt undefined zurück wenn idPoi nicht existiert", () => {
|
||||||
|
const iconMap = new Map();
|
||||||
|
iconMap.set(1, "icon-1.png");
|
||||||
|
const result = iconMap.get(99);
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
// /config/appVersion
|
// /config/appVersion
|
||||||
export const APP_VERSION = "1.1.166";
|
export const APP_VERSION = "1.1.167";
|
||||||
|
|||||||
30
docs/frontend/utils/setupPOIs.md
Normal file
30
docs/frontend/utils/setupPOIs.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# 🧭 `setupPOIs.js`
|
||||||
|
|
||||||
|
## Zweck
|
||||||
|
|
||||||
|
Zeichnet alle POI-Marker auf die Leaflet-Karte basierend auf Datenbankeinträgen. Bindet Popup, Kontextmenü, Drag'n'Drop und Redux-Zustand ein.
|
||||||
|
|
||||||
|
## Parameter
|
||||||
|
|
||||||
|
| Name | Beschreibung |
|
||||||
|
| ----------------- | ---------------------------------------------------- |
|
||||||
|
| `map` | Leaflet-Instanz |
|
||||||
|
| `pois` | Array mit POI-Objekten aus der Datenbank |
|
||||||
|
| `poiData` | Array mit Iconpfaden: `{ idPoi, path }` |
|
||||||
|
| `poiTypMap` | Map-Objekt: `idPoiTyp → Name` |
|
||||||
|
| `poiLayerVisible` | Gibt an, ob Layer überhaupt gezeichnet werden sollen |
|
||||||
|
|
||||||
|
## Besonderheiten
|
||||||
|
|
||||||
|
- Icon wird über `iconMap.get(idPoi)` bezogen
|
||||||
|
- Fallback bei unbekanntem Icon (`default-icon.png`)
|
||||||
|
- Rechteprüfung für Drag & Kontextmenü (`userRights.some(...)`)
|
||||||
|
- Marker können bearbeitet, verschoben, gelöscht werden
|
||||||
|
- Bei `mouseover` → Redux: `setSelectedPoi(poi)`
|
||||||
|
|
||||||
|
## Beispiel für Testdaten
|
||||||
|
|
||||||
|
```js
|
||||||
|
const poi = { idPoi: 7, idPoiTyp: 2, position: "POINT(8.5 53.1)", description: "Mast", idLD: 123 };
|
||||||
|
const poiData = [{ idPoi: 7, path: "poi-marker-icon-2.png" }];
|
||||||
|
```
|
||||||
@@ -1,22 +1,13 @@
|
|||||||
// utils/setupPOIs.js
|
// utils/setupPOIs.js
|
||||||
import { findClosestPoints } from "./geometryUtils";
|
|
||||||
import handlePoiSelect from "./handlePoiSelect";
|
|
||||||
import { updateLocationInDatabaseService } from "../services/database/updateLocationInDatabaseService";
|
|
||||||
import { handleEditPoi, insertNewPOI, removePOI } from "./poiUtils";
|
|
||||||
import { parsePoint } from "./geometryUtils";
|
import { parsePoint } from "./geometryUtils";
|
||||||
import circleIcon from "../components/gisPolylines/icons/CircleIcon";
|
import { handleEditPoi } from "./poiUtils";
|
||||||
import startIcon from "../components/gisPolylines/icons/StartIcon";
|
import { updateLocationInDatabaseService } from "../services/database/updateLocationInDatabaseService";
|
||||||
import endIcon from "../components/gisPolylines/icons/EndIcon";
|
|
||||||
import { redrawPolyline } from "./polylines/redrawPolyline";
|
|
||||||
import { openInNewTab } from "../utils/openInNewTab";
|
|
||||||
import { disablePolylineEvents, enablePolylineEvents } from "./polylines/setupPolylines"; // Importiere die Funktionen
|
|
||||||
import { setSelectedPoi, clearSelectedPoi } from "../redux/slices/selectedPoiSlice";
|
import { setSelectedPoi, clearSelectedPoi } from "../redux/slices/selectedPoiSlice";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
|
|
||||||
export const setupPOIs = async (
|
export const setupPOIs = async (
|
||||||
map,
|
map,
|
||||||
pois,
|
pois,
|
||||||
poiData,
|
poiData, // enthält aktuell: idPoi + path
|
||||||
poiTypMap,
|
poiTypMap,
|
||||||
userRights,
|
userRights,
|
||||||
poiLayerRef,
|
poiLayerRef,
|
||||||
@@ -32,8 +23,16 @@ export const setupPOIs = async (
|
|||||||
deviceName,
|
deviceName,
|
||||||
dispatch
|
dispatch
|
||||||
) => {
|
) => {
|
||||||
const editMode = localStorage.getItem("editMode") === "true"; // Prüfen, ob der Bearbeitungsmodus aktiv ist
|
const editMode = localStorage.getItem("editMode") === "true";
|
||||||
userRights = editMode ? userRights : undefined; // Nur Berechtigungen anwenden, wenn editMode true ist
|
userRights = editMode ? userRights : undefined;
|
||||||
|
|
||||||
|
// ✅ Mapping vorbereiten: idPoi → icon path
|
||||||
|
const iconMap = new Map();
|
||||||
|
poiData.forEach((item) => {
|
||||||
|
if (item.idPoi && item.path) {
|
||||||
|
iconMap.set(item.idPoi, item.path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (map && poiLayerRef.current) {
|
if (map && poiLayerRef.current) {
|
||||||
map.removeLayer(poiLayerRef.current);
|
map.removeLayer(poiLayerRef.current);
|
||||||
@@ -45,8 +44,9 @@ export const setupPOIs = async (
|
|||||||
const poiTypName = poiTypMap.get(poi.idPoiTyp) || "Unbekannt";
|
const poiTypName = poiTypMap.get(poi.idPoiTyp) || "Unbekannt";
|
||||||
const canDrag = userRights ? userRights.some((r) => r.IdRight === 56) : false;
|
const canDrag = userRights ? userRights.some((r) => r.IdRight === 56) : false;
|
||||||
|
|
||||||
const matchingIcon = poiData.find((poi) => poi.idPoi === poi.idPoi);
|
// ✅ Icon korrekt über idPoi auflösen
|
||||||
const iconUrl = matchingIcon ? `/img/icons/pois/${matchingIcon.path}` : "/img/icons/pois/default-icon.png";
|
const iconPath = iconMap.get(poi.idPoi);
|
||||||
|
const iconUrl = iconPath ? `/img/icons/pois/${iconPath}` : "/img/icons/pois/default-icon.png";
|
||||||
|
|
||||||
const marker = L.marker([latitude, longitude], {
|
const marker = L.marker([latitude, longitude], {
|
||||||
icon: L.icon({
|
icon: L.icon({
|
||||||
@@ -64,7 +64,6 @@ export const setupPOIs = async (
|
|||||||
link: poi.link,
|
link: poi.link,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Nur das Kontextmenü "POI Bearbeiten" hinzufügen, wenn editMode true ist
|
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
marker.bindContextMenu({
|
marker.bindContextMenu({
|
||||||
contextmenu: true,
|
contextmenu: true,
|
||||||
@@ -88,41 +87,22 @@ export const setupPOIs = async (
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
marker.on("mouseover", function () {
|
marker.on("mouseover", function () {
|
||||||
console.log("Device Name in setupPOIs.js :", marker); // Debugging
|
dispatch(setSelectedPoi(poi));
|
||||||
dispatch(setSelectedPoi(poi)); // POI in Redux setzen
|
|
||||||
|
|
||||||
handlePoiSelect(
|
|
||||||
{
|
|
||||||
id: poi.idPoi,
|
|
||||||
deviceId: poi.idLD,
|
|
||||||
idPoiTyp: poi.idPoiTyp,
|
|
||||||
typ: poiTypName,
|
|
||||||
description: poi.description,
|
|
||||||
idLD: poi.idLD,
|
|
||||||
},
|
|
||||||
setSelectedPoi,
|
|
||||||
setLocationDeviceData,
|
|
||||||
setDeviceName, // Stelle sicher, dass dies korrekt funktioniert
|
|
||||||
poiLayerRef,
|
|
||||||
poiTypMap
|
|
||||||
);
|
|
||||||
|
|
||||||
localStorage.setItem("lastElementType", "marker");
|
localStorage.setItem("lastElementType", "marker");
|
||||||
localStorage.setItem("markerLink", this.options.link);
|
localStorage.setItem("markerLink", this.options.link);
|
||||||
});
|
});
|
||||||
|
|
||||||
marker.on("mouseout", function () {
|
marker.on("mouseout", function () {
|
||||||
dispatch(clearSelectedPoi()); // POI aus Redux entfernen
|
dispatch(clearSelectedPoi());
|
||||||
this.closePopup();
|
this.closePopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
marker.on("dragend", (e) => {
|
marker.on("dragend", (e) => {
|
||||||
console.log("Marker wurde verschoben in setupPOIs");
|
|
||||||
if (canDrag) {
|
if (canDrag) {
|
||||||
const newLat = e.target.getLatLng().lat;
|
const newLat = e.target.getLatLng().lat;
|
||||||
const newLng = e.target.getLatLng().lng;
|
const newLng = e.target.getLatLng().lng;
|
||||||
const markerId = e.target.options.id;
|
const markerId = e.target.options.id;
|
||||||
updateLocationInDatabaseService(markerId, newLat, newLng).then(() => {});
|
updateLocationInDatabaseService(markerId, newLat, newLng);
|
||||||
} else {
|
} else {
|
||||||
console.error("Drag operation not allowed");
|
console.error("Drag operation not allowed");
|
||||||
}
|
}
|
||||||
@@ -132,7 +112,7 @@ export const setupPOIs = async (
|
|||||||
marker.addTo(poiLayerRef.current);
|
marker.addTo(poiLayerRef.current);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error processing a location:", error);
|
console.error("❌ Fehler bei POI Marker:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user