polylines tooltip content
This commit is contained in:
129
services/apiService.js
Normal file
129
services/apiService.js
Normal file
@@ -0,0 +1,129 @@
|
||||
// services/apiService.js
|
||||
import * as config from "../config/config";
|
||||
import * as urls from "../config/urls";
|
||||
|
||||
export const fetchGisStatusStations = async (idMap, idUser) => {
|
||||
try {
|
||||
const response = await fetch(`/api/talas5/webserviceMap/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.statusText}
|
||||
MySQL Datenbankverbindung fehlgeschlagen und
|
||||
MySQL-Mode prüfen!`);
|
||||
}
|
||||
const data = await response.json();
|
||||
//console.log("GisStatusStations:", data);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Daten:", error);
|
||||
throw error; // Fehler weiter werfen, um ihn in der Komponente behandeln zu können
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
/* export const fetchPriorityConfig = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/talas_v5_DB/priorityConfig");
|
||||
const data = await response.json();
|
||||
console.log("Prioritätskonfiguration:", data);
|
||||
setPriorityConfig(data);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Prioritätskonfiguration:", error);
|
||||
}
|
||||
}; */
|
||||
|
||||
// ----------------------------------------------
|
||||
export const fetchPoiData = async (idPoi) => {
|
||||
try {
|
||||
const response = await fetch(`/api/talas_v5_DB/pois/getPoiById?idPoi=${idPoi}`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der POI-Daten");
|
||||
}
|
||||
const data = await response.json();
|
||||
return {
|
||||
idPoi,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der POI-Daten", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// ----------------------------------------------
|
||||
// Funktion zum Aktualisieren der Position in der Datenbank
|
||||
export const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
|
||||
const response = await fetch("/api/talas_v5_DB/pois/updateLocation", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id,
|
||||
latitude: newLatitude,
|
||||
longitude: newLongitude,
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
//schreib die neue Kooridnaten in die Console
|
||||
//akuellisiere die Position in der Datenbank mit den neuen Koordinaten mit updateLocation mit SQL Anweisung UPDATE
|
||||
} else {
|
||||
console.error("Fehler beim Aktualisieren der Position");
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
// Funktionen zur Überwachung der Internetverbindung
|
||||
export const checkInternet = () => {
|
||||
fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" })
|
||||
.then((response) => setOnline(response.ok))
|
||||
.catch(() => setOnline(false));
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
export const fetchDeviceNameById = async (idLD) => {
|
||||
try {
|
||||
const response = await fetch(`/api/talas_v5_DB/locationDevice/locationDeviceNameById?idLD=${idLD}`);
|
||||
const data = await response.json();
|
||||
if (response.ok) {
|
||||
return data.name;
|
||||
} else {
|
||||
//throw new Error(data.error || "Gerät nicht gefunden");
|
||||
throw new Error("Gerät nicht gefunden in apiService.js");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen des Gerätenamens in apiService.js:", error);
|
||||
return "Unbekannt";
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------
|
||||
// services/apiService.js
|
||||
export const fetchUserRights = async () => {
|
||||
try {
|
||||
// const response = await fetch(`${urls.SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`);
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
// console.log("Benutzerrechte in fetchRights:", data);
|
||||
|
||||
// Überprüfen der Struktur der Antwort
|
||||
if (!data || !data.Rights || !Array.isArray(data.Rights)) {
|
||||
throw new Error("Invalid response structure");
|
||||
}
|
||||
|
||||
const rightsArray = data.Rights; // Nehmen an, dass 'Rights' das Array von Rechten ist
|
||||
//console.log("rightsArray in apiService:", rightsArray);
|
||||
|
||||
// Speichert die IDs der Rechte in einem Array
|
||||
const userRightsIds = rightsArray.map((right) => right.IdRight);
|
||||
|
||||
// Wenn alles gut geht, logge die erfolgreichen Abschluss
|
||||
// console.log("Benutzerrechte erfolgreich abgerufen:", userRightsIds);
|
||||
return userRightsIds;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Benutzerrechte", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
62
services/fetchData.js
Normal file
62
services/fetchData.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// services/fetchData.js
|
||||
export const fetchGisStationsStaticDistrict = async (url, setGisStationsStaticDistrict) => {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse && jsonResponse.Points) {
|
||||
setGisStationsStaticDistrict(jsonResponse.Points);
|
||||
} else {
|
||||
console.error('Erwartete Daten im "Points"-Array nicht gefunden', jsonResponse);
|
||||
setGisStationsStaticDistrict([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten: ", error);
|
||||
setGisStationsStaticDistrict([]);
|
||||
}
|
||||
};
|
||||
export const fetchGisStationsStatusDistrict = async (url, setGisStationsStatusDistrict) => {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse && jsonResponse.Statis) {
|
||||
setGisStationsStatusDistrict(jsonResponse.Statis);
|
||||
} else {
|
||||
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
|
||||
setGisStationsStatusDistrict([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten: ", error);
|
||||
setGisStationsStatusDistrict([]);
|
||||
}
|
||||
};
|
||||
export const fetchGisStationsMeasurements = async (url, setGisStationsMeasurements) => {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse && jsonResponse.Statis) {
|
||||
setGisStationsMeasurements(jsonResponse.Statis);
|
||||
} else {
|
||||
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
|
||||
setGisStationsMeasurements([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten: ", error);
|
||||
setGisStationsMeasurements([]);
|
||||
}
|
||||
};
|
||||
export const fetchGisSystemStatic = async (url, setGisSystemStatic, setGisSystemStaticLoaded) => {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse && jsonResponse.Systems) {
|
||||
setGisSystemStatic(jsonResponse.Systems);
|
||||
setGisSystemStaticLoaded(true);
|
||||
} else {
|
||||
console.error('Erwartete Daten im "Systems"-Array nicht gefunden', jsonResponse);
|
||||
setGisSystemStatic([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten: ", error);
|
||||
setGisSystemStatic([]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user