From 4143e1e78f120724b7d0b5e1559c003b95716ecb Mon Sep 17 00:00:00 2001 From: steven Date: Fri, 9 May 2025 21:52:47 -0400 Subject: [PATCH] filter currently selected routes --- templates/map.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/templates/map.html b/templates/map.html index 4960d1d..009a076 100644 --- a/templates/map.html +++ b/templates/map.html @@ -22,6 +22,15 @@ for (stop in stops){ let busIcon=L.icon({iconUrl:'static/bus.ico',iconSize:[32,32]}) let layerControl=L.control.layers().addTo(map); let busLayers={},busMarkers={}; +function filterRoutes(wanted){ + for(r in busLayers){ + if(!wanted||wanted==r){ + map.addLayer(busLayers[r]) + } else{ + map.removeLayer(busLayers[r]) + } + } +} function updateMap(){ let routes={}; fetch("tarc.csv").then(response=>response.text()).then(csv=>{ @@ -30,7 +39,7 @@ function updateMap(){ p=parseInt(p); t=new Date(t*1000).toLocaleTimeString("en-US",{hour12:false}); if(!busLayers[r]){busLayers[r]=L.layerGroup().addTo(map)} - if(!busMarkers[id]){busMarkers[id]=L.marker([0,0]).addTo(busLayers[r])} + if(!busMarkers[id]){busMarkers[id]=L.marker([0,0],{icon:busIcon}).on('click',()=>filterRoutes(r)).addTo(busLayers[r])} if(!routes[r]){routes[r]=[0,0]} routes[r][0]++; routes[r][1]+=p; @@ -47,6 +56,7 @@ function updateMap(){ } updateMap(); setInterval(updateMap,5000); +map.on('click',()=>filterRoutes()) let locationMarker=L.marker([0,0]).addTo(map); let locationRadius=L.circle([0,0]).addTo(map).bringToBack();