Compare commits

...
3 Commits
Author SHA1 Message Date
cjdenio 9354988f93 handle null headsign 2026-07-08 14:09:40 -06:00
cjdenio bb1be8a143 bump 2026-07-08 10:10:18 -06:00
cjdenio b718a64321 update popup content 2026-07-07 14:15:51 -06:00
2 changed files with 21 additions and 8 deletions

No files matched your search

+1 -1
View File
@@ -300,6 +300,6 @@
</div> </div>
</div> </div>
<script type="module" src="/js/main.js?v=5"></script> <script type="module" src="/js/main.js?v=7"></script>
</body> </body>
</html> </html>
+20 -7
View File
@@ -165,6 +165,24 @@ function renderVehicleIcon(vehicle) {
}) })
} }
function vehiclePopupContent(vehicle) {
let content = `<b>${routeDesignator(vehicle.route)}</b>`
if (vehicle.headsign) {
content += ` to <b>${vehicle.headsign.replace(
/^to /i,
""
)}</b>`
}
if (vehicle.nearest_station) {
content += `<br />@ ${vehicle.nearest_station.name}`
}
content += `<br /><br /><small>vehicle #: ${vehicle.id}</small>`
return content
}
function renderVehicle(vehicle) { function renderVehicle(vehicle) {
return L.marker([vehicle.lat, vehicle.lon], { return L.marker([vehicle.lat, vehicle.lon], {
zIndexOffset: zIndexOffset:
@@ -173,13 +191,7 @@ function renderVehicle(vehicle) {
? 4000 ? 4000
: 3000, : 3000,
icon: renderVehicleIcon(vehicle), icon: renderVehicleIcon(vehicle),
}) }).bindPopup(vehiclePopupContent(vehicle));
.bindPopup(
`<b>${routeDesignator(vehicle.route)}</b> to <b>${vehicle.headsign?.replace(
/^to /i,
""
)}</b>${vehicle.nearest_station ? `<br />@ ${vehicle.nearest_station?.name}` : ""}<br /><br /><small>vehicle #: ${vehicle.id}</small>`
);
} }
async function reload() { async function reload() {
@@ -211,6 +223,7 @@ async function reload() {
if (currentVehicles.has(vehicle.id)) { // if this vehicle is already on the map, update its location if (currentVehicles.has(vehicle.id)) { // if this vehicle is already on the map, update its location
currentVehicles.get(vehicle.id).marker.setLatLng([vehicle.lat, vehicle.lon]) currentVehicles.get(vehicle.id).marker.setLatLng([vehicle.lat, vehicle.lon])
currentVehicles.get(vehicle.id).marker.setIcon(renderVehicleIcon(vehicle)) currentVehicles.get(vehicle.id).marker.setIcon(renderVehicleIcon(vehicle))
currentVehicles.get(vehicle.id).marker.setPopupContent(vehiclePopupContent(vehicle))
} else { } else {
const marker = renderVehicle(vehicle) const marker = renderVehicle(vehicle)
marker.addTo( marker.addTo(