From 3be192a64c1a55896c405c7d7a28240743999ec2 Mon Sep 17 00:00:00 2001
From: Serverlele30 <46974281+Serverlele30@users.noreply.github.com>
Date: Fri, 22 Aug 2025 09:51:04 +0200
Subject: [PATCH] Update app.js
filter funktion eingebaut
---
app.js | 111 ++++++++++++++++++++-------------------------------------
1 file changed, 38 insertions(+), 73 deletions(-)
diff --git a/app.js b/app.js
index 55221f0..0f1bede 100644
--- a/app.js
+++ b/app.js
@@ -36,6 +36,31 @@ const symbols = {
regional: 'π', express: 'π', longDistance: 'π
', ferry: 'π₯οΈ'
};
+// =============================
+// Aktive Filter
+// =============================
+let activeProducts = Array.from(document.querySelectorAll('#controls input[type="checkbox"]'))
+ .filter(c => c.checked)
+ .map(c => c.value);
+
+// Checkbox Event
+document.querySelectorAll('#controls input[type="checkbox"]').forEach(cb => {
+ cb.addEventListener('change', () => {
+ activeProducts = Array.from(document.querySelectorAll('#controls input[type="checkbox"]'))
+ .filter(c => c.checked)
+ .map(c => c.value);
+
+ Object.values(vehicleMarkers).forEach(marker => {
+ const prod = marker.options.vehicleProduct || '';
+ if (activeProducts.includes(prod)) {
+ if (!map.hasLayer(marker)) map.addLayer(marker);
+ } else {
+ if (map.hasLayer(marker)) map.removeLayer(marker);
+ }
+ });
+ });
+});
+
// =============================
// Hilfsfunktionen
// =============================
@@ -53,7 +78,7 @@ function getLineColor(lineName, product) {
}
function createDivIcon(vehicle) {
- const product = vehicle.line?.product;
+ const product = vehicle.line?.product || '';
const lineName = vehicle.line?.name || '?';
const symbol = symbols[product] || 'β';
@@ -79,7 +104,9 @@ function createDivIcon(vehicle) {
`;
- return L.divIcon({ html: iconHtml, className: '', iconSize: [30, 40], iconAnchor: [15, 20] });
+ const icon = L.divIcon({ html: iconHtml, className: '', iconSize: [30, 40], iconAnchor: [15, 20] });
+ icon.product = product;
+ return icon;
}
const lineColor = getLineColor(lineName, product);
@@ -92,7 +119,9 @@ function createDivIcon(vehicle) {
`;
- return L.divIcon({ html: iconHtml, className: '', iconSize: [30, 40], iconAnchor: [15, 20] });
+ const icon = L.divIcon({ html: iconHtml, className: '', iconSize: [30, 40], iconAnchor: [15, 20] });
+ icon.product = product;
+ return icon;
}
// =============================
@@ -120,16 +149,18 @@ async function loadVehicles() {
if (vehicleMarkers[id]) {
vehicleMarkers[id].setLatLng([loc.latitude, loc.longitude]);
} else {
- const marker = L.marker([loc.latitude, loc.longitude], { icon })
- .bindPopup(`Linie: ${vehicle.line?.name || 'unbekannt'}
Typ: ${vehicle.line?.product || 'unbekannt'}
Richtung: ${vehicle.direction || 'unbekannt'}`)
- .addTo(vehiclesLayer);
+ const marker = L.marker([loc.latitude, loc.longitude], { icon });
+ marker.options.vehicleProduct = vehicle.line?.product || '';
+ if (activeProducts.includes(marker.options.vehicleProduct)) {
+ marker.addTo(map);
+ }
vehicleMarkers[id] = marker;
}
});
Object.keys(vehicleMarkers).forEach(id => {
if (!newIds.has(id)) {
- vehiclesLayer.removeLayer(vehicleMarkers[id]);
+ if (map.hasLayer(vehicleMarkers[id])) map.removeLayer(vehicleMarkers[id]);
delete vehicleMarkers[id];
}
});
@@ -157,69 +188,3 @@ function locateAndLoad() {
locateAndLoad();
setInterval(loadVehicles, 30000);
map.on('moveend', loadVehicles);
-
-// =============================
-// BahnhΓΆfe mit Live-Abfahrten
-// =============================
-const stations = [
- { name: "Berlin Zoologischer Garten", id: "900023201", coords: [52.5069, 13.3326] },
- { name: "Berlin Alexanderplatz", id: "900100003", coords: [52.5215, 13.4115] },
- { name: "Berlin Gesundbrunnen", id: "900007102", coords: [52.5483, 13.3889] },
- { name: "Berlin Spandau", id: "900029101", coords: [52.5341, 13.1977] },
- { name: "Berlin SΓΌdkreuz", id: "900058101", coords: [52.4752, 13.3653] },
- { name: "Berlin Ostbahnhof", id: "900100004", coords: [52.5100, 13.4340] }
-];
-
-async function loadStationDepartures(stationId, marker, stationName) {
- const symbols = {
- bus: 'π', tram: 'π', subway: 'π', suburban: 'π',
- regional: 'π', express: 'π', longDistance: 'π
', ferry: 'π₯οΈ'
- };
-
- try {
- const res = await fetch(`https://v6.vbb.transport.rest/stops/${stationId}/departures?duration=30&results=10`);
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
- const data = await res.json();
- const departures = data.departures || [];
-
- let html = `${stationName}
`;
- html += `
| Linie | Richtung | Zeit |
|---|---|---|
| ${icon} ${line} | -${direction} | -${timeStr} ${delayStr} | -