Skip to content

Commit

Permalink
refactor: Update GoogleMapProvider.js to use activeTrip object for ve…
Browse files Browse the repository at this point in the history
…hicle marker data
  • Loading branch information
Ahmedhossamdev committed Oct 26, 2024
1 parent a575268 commit cb9d3b6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/lib/Provider/GoogleMapProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@ export default class GoogleMapProvider {
this.stopMarkers = [];
}

addVehicleMarker(vehicle) {
addVehicleMarker(vehicle, activeTrip) {
if (!this.map) return null;

const busIcon = createVehicleIconSvg(vehicle?.orientation);
// TODO: Add enum for vehicle color and status
let color;
if (!vehicle.predicted) {
color = COLORS.VEHICLE_REAL_TIME_OFF;
}

const busIcon = createVehicleIconSvg(vehicle?.orientation, color);
const icon = {
url: `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(busIcon)}`,
scaledSize: new google.maps.Size(40, 40),
Expand All @@ -172,11 +178,10 @@ export default class GoogleMapProvider {
this.vehicleMarkers.push(marker);

const vehicleData = {
routeName: vehicle.routeName,
nextDestination: activeTrip.routeShortName + ' - ' + activeTrip.tripHeadsign,
vehicleId: vehicle.vehicleId,
lastUpdateTime: vehicle.lastUpdateTime,
nextStopName: this.stopsMap.get(vehicle.nextStop)?.name || 'N/A',
status: vehicle.status,
predicted: vehicle.predicted
};

Expand All @@ -197,24 +202,28 @@ export default class GoogleMapProvider {
return marker;
}

updateVehicleMarker(marker, vehicleStatus) {
updateVehicleMarker(marker, vehicleStatus, activeTrip) {
if (!this.map || !marker) return;

marker.setPosition({ lat: vehicleStatus.position.lat, lng: vehicleStatus.position.lon });

const updatedIcon = createVehicleIconSvg(vehicleStatus.orientation);
let color;
if (!vehicleStatus.predicted) {
color = COLORS.VEHICLE_REAL_TIME_OFF;
}

const updatedIcon = createVehicleIconSvg(vehicleStatus.orientation, color);
marker.setIcon({
url: `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(updatedIcon)}`,
scaledSize: new google.maps.Size(40, 40),
anchor: new google.maps.Point(20, 20)
});

const updatedData = {
routeName: vehicleStatus.routeName,
nextDestination: activeTrip.routeShortName + ' - ' + activeTrip.tripHeadsign,
vehicleId: vehicleStatus.vehicleId,
lastUpdateTime: vehicleStatus.lastUpdateTime,
nextStopName: this.stopsMap.get(vehicleStatus.nextStop)?.name || 'N/A',
status: vehicleStatus.status,
predicted: vehicleStatus.predicted
};

Expand Down

0 comments on commit cb9d3b6

Please sign in to comment.