Skip to content

Commit

Permalink
More fixes for phantom vehicles without trips
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Jan 3, 2025
1 parent 77fa254 commit 8ee765e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/components/TransitMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ function TransitMap({
{vehicleMarkers.length > 0 && (
<LayersControl.Overlay checked={true} name="Vehicles">
<LayerGroup>
{vehicleMarkers.map((item, _index) => {
if (!item.vehicle.trip) {
console.warn('Vehicle without trip', item);
return;
}

{vehicleMarkers.filter((i) => i.vehicle.trip).map((item, _index) => {
const route = getRouteDataById(item.vehicle.trip.route_id);
const routeAlerts = getRouteAlertsById(item.vehicle.trip.route_id);
const agency = getAgencyDataById(route ? route.agency_gid : {});
Expand Down
2 changes: 1 addition & 1 deletion src/components/VehicleMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function VehicleMarker({
const marker = useRef(null);

if (typeof route === 'undefined' || typeof route.route_gid === 'undefined') {
console.warn(`No matching route found for Trip #${vehiclePositionData.vehicle.trip.trip_id}`);
console.warn(`No matching route found for Trip #${vehiclePositionData.vehicle.trip?.trip_id}`);
return (<></>);
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/VehicleMarkerPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ function VehicleMarkerPopup({
);
})}
{tripStopTimes.length === 0 && (
<div className="alert bg-info text-bg-info">No upcoming stops for this trip.</div>
<tr>
<td>
<div className="alert bg-info text-bg-info">No upcoming stops for this trip.</div>
</td>
</tr>
)}
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/Stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Stops() {
// Filter vehicle positions to relevant trips
const filteredVehiclePositions = [];
const tripsAtStop = trips.map((t) => t.trip_gid);
vehiclePositions.forEach((vp) => {
vehiclePositions.filter((v) => v.vehicle.trip).forEach((vp) => {
if (tripsAtStop.includes(vp.vehicle.trip.trip_id)) {
filteredVehiclePositions.push(vp);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/TransitRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function TransitRoute() {
}

// Filter vehicle positions to only those relevant to this route
const filteredVehiclePositions = vehicleMarkers.filter((v) => v.vehicle.trip.route_id === route.route_gid || v.vehicle.trip.route_id === route.route_short_name);
const filteredVehiclePositions = vehicleMarkers.filter((v) => v.vehicle.trip).filter((v) => v.vehicle.trip.route_id === route.route_gid || v.vehicle.trip.route_id === route.route_short_name);
const routeAlerts = alerts.filter((a) => typeof a.alert.informed_entity !== 'undefined' && (a.alert.informed_entity[0].route_id === route.route_gid || a.alert.informed_entity[0].route_id === route.route_short_name));

// Load in selected date
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/Trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function Trip() {
const routeAlerts = alerts.filter((a) => typeof a.alert.informed_entity !== 'undefined' && a.alert.informed_entity[0].route_id === route.route_gid);

// Filter vehicle markers
const filteredVehicleMarkers = vehicleMarkers.filter((v) => v.vehicle.trip.trip_id === trip.trip_gid);
const filteredVehicleMarkers = vehicleMarkers.filter((v) => v.vehicle.trip?.trip_id === trip.trip_gid);

// Filter updates to this trip, key stop time updates by sequence
const filteredTripUpdates = tripUpdates.filter((i) => i.id === trip.trip_gid);
Expand Down

0 comments on commit 8ee765e

Please sign in to comment.