Poi hinzufügen per Popup Formular
This commit is contained in:
@@ -28,12 +28,23 @@ const ShowAddStationPopup = ({ map, latlng }) => {
|
|||||||
|
|
||||||
const handleSubmit = (event) => {
|
const handleSubmit = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log("Daten von ShowAddStationPopup: ", {
|
const formData = {
|
||||||
name, // Name der Station
|
name, // Name der Station
|
||||||
poiTypeId, // Typ der Station, logged as idPoiTyp
|
poiTypeId, // Typ der Station, logged as idPoiTyp
|
||||||
latitude, // Breitengrad
|
latitude, // Breitengrad
|
||||||
longitude, // Längengrad
|
longitude, // Längengrad
|
||||||
});
|
};
|
||||||
|
|
||||||
|
fetch('/api/addLocation', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(formData),
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => console.log(data)) // Handle the response data
|
||||||
|
.catch((error) => console.error(error)); // Handle any errors
|
||||||
|
|
||||||
|
// Close the popup
|
||||||
//map.closePopup();
|
//map.closePopup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,23 +11,20 @@ const dbConfig = {
|
|||||||
|
|
||||||
export default function handler(req, res) {
|
export default function handler(req, res) {
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
const { name, type, latitude, longitude } = req.body;
|
const { name, poiTypeId, latitude, longitude } = req.body;
|
||||||
|
console.log("Received data:", req.body); // Überprüfen der empfangenen Daten
|
||||||
const connection = mysql.createConnection(dbConfig);
|
const connection = mysql.createConnection(dbConfig);
|
||||||
|
|
||||||
// Nutze ST_GeomFromText, um den Punkt zu erzeugen
|
const query = "INSERT INTO poi (description, idPoiTyp, position) VALUES (?, ?, ST_GeomFromText(?))";
|
||||||
const query =
|
const point = `POINT(${longitude} ${latitude})`;
|
||||||
"INSERT INTO poi (description, idPoiTyp, position) VALUES (?, ?, ST_GeomFromText(?))";
|
const values = [name, poiTypeId, point]; // Stellen Sie sicher, dass poiTypeId korrekt ist
|
||||||
const point = `POINT(${longitude} ${latitude})`; // Achte auf die Reihenfolge: Längengrad (Longitude), Breitengrad (Latitude)
|
|
||||||
const values = [name, type, point];
|
|
||||||
|
|
||||||
connection.query(query, values, (error, results) => {
|
connection.query(query, values, (error, results) => {
|
||||||
connection.end();
|
connection.end();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Fehler beim Einfügen des Standorts:", error);
|
console.error("Fehler beim Einfügen des Standorts:", error);
|
||||||
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({ id: results.insertId, message: "Standort erfolgreich hinzugefügt" });
|
res.status(200).json({ id: results.insertId, message: "Standort erfolgreich hinzugefügt" });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -35,3 +32,4 @@ export default function handler(req, res) {
|
|||||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user