iconurl von DB bekommen

This commit is contained in:
ISA
2024-05-30 11:41:23 +02:00
parent 3218000bea
commit e927b62f53
7 changed files with 59 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
DB_HOST=localhost DB_HOST=localhost
#DB_HOST=192.168.10.58 #DB_HOST=192.168.10.58
#DB_HOST=10.10.0.13
DB_USER=root DB_USER=root
DB_PASSWORD="root#$" DB_PASSWORD="root#$"
DB_NAME=talas_v5 DB_NAME=talas_v5

View File

@@ -1153,6 +1153,18 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
// poiLayerRef(poiDbLayer) POI hinzufügen // poiLayerRef(poiDbLayer) POI hinzufügen
//-------------------------------------------- //--------------------------------------------
const [poiData, setPoiData] = useState([]);
useEffect(() => {
const fetchPoiData = async () => {
const response = await fetch("/api/poi-icons");
const data = await response.json();
setPoiData(data);
console.log("poiData icons:", data);
};
fetchPoiData();
}, []);
useEffect(() => { useEffect(() => {
if (map && poiLayerRef.current && isPoiTypLoaded) { if (map && poiLayerRef.current && isPoiTypLoaded) {
@@ -1163,13 +1175,22 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
const { latitude, longitude } = parsePoint(location.position); const { latitude, longitude } = parsePoint(location.position);
const poiTypName = poiTypMap.get(location.idPoiTyp) || "Unbekannt"; const poiTypName = poiTypMap.get(location.idPoiTyp) || "Unbekannt";
const deviceName = await fetchDeviceNameById(location.idLD); const deviceName = await fetchDeviceNameById(location.idLD);
console.log("location.icon:", location);
// Check if user has the right to drag the marker // Check if user has the right to drag the marker
const canDrag = userRights ? userRights.includes(56) : false; // Check if userRights is not null before using includes const canDrag = userRights ? userRights.includes(56) : false; // Check if userRights is not null before using includes
// Finde das passende Icon aus poiData
const matchingIcon = poiData.find(
(poi) => poi.idPoi === location.idPoi
);
const iconUrl = matchingIcon
? `/img/icons/pois/${matchingIcon.path}`
: "/img/icons/pois/default-icon.png";
const marker = L.marker([latitude, longitude], { const marker = L.marker([latitude, longitude], {
icon: L.icon({ icon: L.icon({
iconUrl: `/img/icons/pois/poi-marker-icon-${location.idPoiTyp}.png`, iconUrl: `/img/icons/pois/poi-marker-icon-${location.idPoiTyp}.png`,
//iconUrl: `/img/icons/pois/poi-marker-icon-${location.icon}.png`, //die kommen nicht aus poi sonder aus poityp tabelle
iconUrl: iconUrl,
iconSize: [25, 41], iconSize: [25, 41],
iconAnchor: [12, 41], iconAnchor: [12, 41],
popupAnchor: [1, -34], popupAnchor: [1, -34],

36
pages/api/poi-icons.js Normal file
View File

@@ -0,0 +1,36 @@
// pages/api/poi-icons.js
import mysql from "mysql";
const dbConfig = {
//host: "10.10.0.13",
//host: "localhost",
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,
};
const connection = mysql.createConnection(dbConfig);
connection.connect((err) => {
if (err) {
console.error("Fehler beim Verbinden:", err.stack);
return;
}
});
export default function handler(req, res) {
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
const query = `SELECT p.idPoi, i.path
FROM poi p
JOIN poiTyp pt ON p.idPoiTyp = pt.idPoiTyp
JOIN poiicons i ON pt.icon = i.idpoiicons;`;
connection.query(query, (error, results) => {
if (error) {
console.error("Fehler beim Abrufen der icons:", error);
return res.status(500).json({ error: "Fehler beim Abrufen der icons" });
}
res.json(results);
});
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB