From 2c02a61791b203cb5c60beb408e9db612e4fc83a Mon Sep 17 00:00:00 2001 From: patrickzerhusen Date: Tue, 21 Apr 2026 17:02:35 +0200 Subject: [PATCH] refractored all var to const or let --- public/js/app.js | 164 +++++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index f7c23f7..a916029 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -14,13 +14,13 @@ // ===================================================================== // API Endpoint as relative Path -var API_URL = 'api/contributions.php'; +const API_URL = 'api/contributions.php'; // Current User Name, set via Login Modal, stored in sessionStorage -var currentUser = sessionStorage.getItem('webgis_user') || ''; +let currentUser = sessionStorage.getItem('webgis_user') || ''; // Category Definitions with Labels, Icons, and Colors -var CATEGORIES = { +const CATEGORIES = { consumption: { label: 'Geschäfte', faIcon: 'fa-cart-shopping', color: '#C00000' }, building: { label: 'Bauen', faIcon: 'fa-building', color: '#E65100' }, energy: { label: 'Energie', faIcon: 'fa-bolt', color: '#FFC000' }, @@ -31,14 +31,14 @@ var CATEGORIES = { }; // Application State -var map; // Leaflet Map Instance -var sidebar; // Sidebar Instance -var contributionsLayer; // GeoJSON Layer holding all Contributions -var contributionsData = []; // Raw Contribution Data Array -var activeFilters = Object.keys(CATEGORIES); // Active Category Filters -var drawnGeometry = null; // Temporary Storage for Geometry drawn with Geoman -var drawnGeomType = null; // Temporary Storage for Geometry Type -var userVotes = {}; // Tracks User Votes +let map; // Leaflet Map Instance +let sidebar; // Sidebar Instance +let contributionsLayer; // GeoJSON Layer holding all Contributions +let contributionsData = []; // Raw Contribution Data Array +let activeFilters = Object.keys(CATEGORIES); // Active Category Filters +let drawnGeometry = null; // Temporary Storage for Geometry drawn with Geoman +let drawnGeomType = null; // Temporary Storage for Geometry Type +let userVotes = {}; // Tracks User Votes // ===================================================================== // Block 2: Map Initialization @@ -63,17 +63,17 @@ map = L.map('map', { // ===================================================================== // Basemap Tile Layers -var basemapOSM = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { +const basemapOSM = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap', maxZoom: 20 }); -var basemapCartoDB = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', { +const basemapCartoDB = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', { attribution: '© Carto', maxZoom: 20 }); -var basemapSatellite = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { +const basemapSatellite = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { attribution: '© Esri', maxZoom: 20 }); @@ -82,15 +82,15 @@ var basemapSatellite = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/ basemapCartoDB.addTo(map); // Layer Control -var basemaps = { +const basemaps = { ' Hintergrundkarte (farbe)': basemapOSM, ' Hintergrundkarte (grau)': basemapCartoDB, ' Satellitenbild': basemapSatellite, }; -var overlays = {}; // Populated later with Contribution Layers +const overlays = {}; // Populated later with Contribution Layers -var layerControl = L.control.layers(basemaps, overlays, { +const layerControl = L.control.layers(basemaps, overlays, { position: 'topright', collapsed: true }).addTo(map); @@ -144,11 +144,11 @@ L.Control.geocoder({ // }).addTo(map); // Mouse Position Display -// var MousePositionControl = L.Control.extend({ +// const MousePositionControl = L.Control.extend({ // options: { position: 'bottomright' }, // onAdd: function () { -// var container = L.DomUtil.create('div', 'mouse-position-display'); +// const container = L.DomUtil.create('div', 'mouse-position-display'); // container.innerHTML = 'Lat: , Lng: '; // map.on('mousemove', function (e) { @@ -162,12 +162,12 @@ L.Control.geocoder({ // new MousePositionControl().addTo(map); // GPS Location Button -var GpsControl = L.Control.extend({ +const GpsControl = L.Control.extend({ options: { position: 'topright' }, onAdd: function () { - var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control'); - var button = L.DomUtil.create('a', 'gps-control-button', container); + const container = L.DomUtil.create('div', 'leaflet-bar leaflet-control'); + const button = L.DomUtil.create('a', 'gps-control-button', container); button.href = '#'; button.title = 'Mein Standort'; button.innerHTML = ''; @@ -184,7 +184,7 @@ var GpsControl = L.Control.extend({ new GpsControl().addTo(map); // GPS Location Found Handler -var gpsMarker = null; +let gpsMarker = null; map.on('locationfound', function (e) { if (gpsMarker) { @@ -240,7 +240,7 @@ map.pm.setLang('de'); // Captures drawn Geometry and opens the Create Modal map.on('pm:create', function (e) { - var geojson = e.layer.toGeoJSON().geometry; + const geojson = e.layer.toGeoJSON().geometry; // Determines drawn Geometry Type and normalizes to simple Types if (e.shape === 'Marker') { @@ -280,8 +280,8 @@ map.on('pm:create', function (e) { // Generic API Call Function function apiCall(data, callback) { - var formData = new FormData(); - for (var key in data) { + const formData = new FormData(); + for (const key in data) { formData.append(key, data[key]); } @@ -338,7 +338,7 @@ function loadContributions() { // Style for Point Features (CircleMarkers) function stylePoint(feature, latlng) { - var cat = CATEGORIES[feature.properties.category] || CATEGORIES.other; + const cat = CATEGORIES[feature.properties.category] || CATEGORIES.other; return L.circleMarker(latlng, { radius: 8, @@ -351,7 +351,7 @@ function stylePoint(feature, latlng) { // Style for Line and Polygon Features function styleLinePolygon(feature) { - var cat = CATEGORIES[feature.properties.category] || CATEGORIES.other; + const cat = CATEGORIES[feature.properties.category] || CATEGORIES.other; return { color: cat.color, @@ -368,17 +368,17 @@ function styleLinePolygon(feature) { // ===================================================================== function bindFeaturePopup(feature, layer) { - var props = feature.properties; - var cat = CATEGORIES[props.category] || CATEGORIES.other; + const props = feature.properties; + const cat = CATEGORIES[props.category] || CATEGORIES.other; // Formats Date - var date = new Date(props.created_at); - var dateStr = date.toLocaleDateString('de-DE', { + const date = new Date(props.created_at); + const dateStr = date.toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' }); // Builds Popup on Click - var html = '' + + const html = '' + '