update popup content

This commit is contained in:
2026-07-07 14:15:51 -06:00
parent 736b47f9f8
commit b718a64321
+9 -7
View File
@@ -165,6 +165,13 @@ function renderVehicleIcon(vehicle) {
}) })
} }
function vehiclePopupContent(vehicle) {
return `<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>`
}
function renderVehicle(vehicle) { function renderVehicle(vehicle) {
return L.marker([vehicle.lat, vehicle.lon], { return L.marker([vehicle.lat, vehicle.lon], {
zIndexOffset: zIndexOffset:
@@ -173,13 +180,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 +212,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(