dev/patrick #1
@@ -111,7 +111,7 @@ L.control.scale({
|
||||
L.control.fullscreen({
|
||||
position: 'topright',
|
||||
title: 'Vollbild',
|
||||
titleCancel: 'Vollbild beenden'
|
||||
titleCancel: 'Vollbild deaktivieren'
|
||||
}).addTo(map);
|
||||
|
||||
// Geocoder Address Search
|
||||
@@ -242,11 +242,11 @@ map.pm.addControls({
|
||||
rotateMode: false
|
||||
});
|
||||
|
||||
// When a Shape is drawn, capture the Geometry and open the Create Modal
|
||||
// Captures drawn Geometry and opens the Create Modal
|
||||
map.on('pm:create', function (e) {
|
||||
var geojson = e.layer.toGeoJSON().geometry;
|
||||
|
||||
// Determine Geometry Type and normalize to simple Types
|
||||
// Determines drawn Geometry Type and normalizes to simple Types
|
||||
if (e.shape === 'Marker') {
|
||||
drawnGeometry = { type: 'Point', coordinates: geojson.coordinates };
|
||||
drawnGeomType = 'point';
|
||||
@@ -257,22 +257,22 @@ map.on('pm:create', function (e) {
|
||||
drawnGeometry = { type: 'Polygon', coordinates: geojson.coordinates };
|
||||
drawnGeomType = 'polygon';
|
||||
} else {
|
||||
// Unsupported Shape — remove from Map and exit
|
||||
// removes unsupported Objects
|
||||
map.removeLayer(e.layer);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the drawn Layer — it will be re-added after API Confirmation
|
||||
// Removes the drawn Layer, which will be re-added after Moderation Confirmation
|
||||
map.removeLayer(e.layer);
|
||||
|
||||
// Check if User is logged in
|
||||
// Checks if User is logged in
|
||||
if (!currentUser) {
|
||||
Swal.fire('Bitte anmelden', 'Sie müssen sich anmelden, um Beiträge zu erstellen.', 'info');
|
||||
Swal.fire('Bitte anmelden', 'Sie sollten sich anmelden, um Beiträge hinzuzufügen oder zu bearbeiten.', 'info');
|
||||
showLoginModal();
|
||||
return;
|
||||
}
|
||||
|
||||
// Populate hidden Fields and open Create Modal
|
||||
// Populates hidden Fields and opens Create Modal
|
||||
document.getElementById('create-geom').value = JSON.stringify(drawnGeometry);
|
||||
document.getElementById('create-geom-type').value = drawnGeomType;
|
||||
document.getElementById('create-modal').style.display = 'flex';
|
||||
@@ -302,11 +302,11 @@ function apiCall(data, callback) {
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error('API Error:', error);
|
||||
Swal.fire('Verbindungsfehler', 'Die Verbindung zum Server ist fehlgeschlagen.', 'error');
|
||||
Swal.fire('Verbindungsfehler', 'Verbindung zum Server fehlgeschlagen.', 'error');
|
||||
});
|
||||
}
|
||||
|
||||
// Load all Contributions from API and display on Map
|
||||
// Loads all Contributions from API and displays Contributions on Map
|
||||
function loadContributions() {
|
||||
apiCall({ action: 'read', municipality_id: MUNICIPALITY.id }, function (data) {
|
||||
if (data.error) {
|
||||
@@ -316,13 +316,13 @@ function loadContributions() {
|
||||
|
||||
contributionsData = data.features || [];
|
||||
|
||||
// Remove existing Layer if present
|
||||
// Removes existing Layer if present
|
||||
if (contributionsLayer) {
|
||||
map.removeLayer(contributionsLayer);
|
||||
layerControl.removeLayer(contributionsLayer);
|
||||
}
|
||||
|
||||
// Create new GeoJSON Layer
|
||||
// Creates new GeoJSON Layer
|
||||
contributionsLayer = L.geoJSON(data, {
|
||||
pointToLayer: stylePoint,
|
||||
style: styleLinePolygon,
|
||||
@@ -370,20 +370,20 @@ function styleLinePolygon(feature) {
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// Block 9: Feature Popups (Read, Vote, Edit, Delete)
|
||||
// Block 9: Feature Popups for Read, Edit, Delete and Vote
|
||||
// =====================================================================
|
||||
|
||||
function bindFeaturePopup(feature, layer) {
|
||||
var props = feature.properties;
|
||||
var cat = CATEGORIES[props.category] || CATEGORIES.other;
|
||||
|
||||
// Format Date
|
||||
// Formats Date
|
||||
var date = new Date(props.created_at);
|
||||
var dateStr = date.toLocaleDateString('de-DE', {
|
||||
day: '2-digit', month: '2-digit', year: 'numeric'
|
||||
});
|
||||
|
||||
// Build Popup HTML
|
||||
// Builds Popup on Click
|
||||
var html = '' +
|
||||
'<div class="popup-detail">' +
|
||||
'<span class="popup-detail-category">' + cat.icon + ' ' + cat.label + '</span>' +
|
||||
@@ -409,7 +409,7 @@ function bindFeaturePopup(feature, layer) {
|
||||
|
||||
layer.bindPopup(html, { maxWidth: 320, minWidth: 240 });
|
||||
|
||||
// Tooltip on Hover
|
||||
// Builds Tooltip on Hover
|
||||
layer.bindTooltip(cat.icon + ' ' + escapeHtml(props.title), {
|
||||
direction: 'top',
|
||||
offset: [0, -10]
|
||||
@@ -421,7 +421,7 @@ function bindFeaturePopup(feature, layer) {
|
||||
// Block 10: CRUD Operations
|
||||
// =====================================================================
|
||||
|
||||
// CREATE — Submit new Contribution from Modal
|
||||
// CREATE: Submits new Contributions from Modal
|
||||
function submitCreate() {
|
||||
var category = document.getElementById('create-category').value;
|
||||
var title = document.getElementById('create-title').value.trim();
|
||||
@@ -429,7 +429,7 @@ function submitCreate() {
|
||||
var geom = document.getElementById('create-geom').value;
|
||||
var geomType = document.getElementById('create-geom-type').value;
|
||||
|
||||
// Validate
|
||||
// Validates
|
||||
if (!category) {
|
||||
Swal.fire('Kategorie fehlt', 'Bitte wählen Sie eine Kategorie aus.', 'warning');
|
||||
return;
|
||||
@@ -458,13 +458,13 @@ function submitCreate() {
|
||||
return;
|
||||
}
|
||||
|
||||
Swal.fire('Eingereicht!', 'Ihr Beitrag wurde erfolgreich eingereicht und wird nach Prüfung veröffentlicht.', 'success');
|
||||
Swal.fire('Eingereicht!', 'Ihr Beitrag wurde erfolgreich eingereicht und wird nach Prüfung durch das Moderationsteam veröffentlicht.', 'success');
|
||||
closeCreateModal();
|
||||
loadContributions();
|
||||
});
|
||||
}
|
||||
|
||||
// Cancel Create — close Modal and clear Form
|
||||
// Cancels Create, closes Modal and clears Form
|
||||
function cancelCreate() {
|
||||
closeCreateModal();
|
||||
}
|
||||
@@ -480,9 +480,9 @@ function closeCreateModal() {
|
||||
drawnGeomType = null;
|
||||
}
|
||||
|
||||
// UPDATE — Edit an existing Contribution
|
||||
// UPDATE: Edit existing Contributions
|
||||
function editContribution(contributionId) {
|
||||
// Find Contribution in local Data
|
||||
// Finds Contribution in local Data
|
||||
var contribution = contributionsData.find(function (f) {
|
||||
return f.properties.contribution_id === contributionId;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user