Skip to content

Commit 550a9b1

Browse files
authored
feat: visualize getTrip and use location instead of rawLocation (#230)
* fix: Deepcopy of lastKnownState and cleanup * feat: visualize getTrip and use location instead of rawLocation
1 parent 98cc4e3 commit 550a9b1

File tree

9 files changed

+341
-74
lines changed

9 files changed

+341
-74
lines changed

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
"plugins": ["react", "jest"],
2222
"rules": {
2323
"no-var": "error",
24-
"no-unused-vars": "warn",
24+
"no-unused-vars": ["warn", {
25+
"argsIgnorePattern": "^_",
26+
"varsIgnorePattern": "^_"
27+
}],
2528
"prefer-arrow-callback": "error",
2629
"react/prop-types": "off",
2730
"react/jsx-key": "off",

src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ class App extends React.Component {
805805
setFeaturedObject={this.setFeaturedObject}
806806
setTimeRange={this.setTimeRange}
807807
setCenterOnLocation={this.setCenterOnLocation}
808+
focusSelectedRow={this.focusOnSelectedRow}
808809
/>
809810
</div>
810811
<TimeSlider
@@ -815,6 +816,7 @@ class App extends React.Component {
815816
selectedEventTime={selectedEventTime}
816817
onRowSelect={(row, rowIndex) => this.onSelectionChange(row, rowIndex)}
817818
centerOnLocation={this.centerOnLocation}
819+
focusSelectedRow={this.focusOnSelectedRow}
818820
/>
819821
<ToggleBar
820822
toggles={this.toggles}

src/Map.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let locationProvider;
2727
let tripLogs;
2828
let taskLogs;
2929
let setFeaturedObject;
30+
let focusSelectedRow;
3031
let setTimeRange;
3132

3233
const render = (status) => {
@@ -54,6 +55,8 @@ function addTripPolys(map) {
5455
if (closestEvent) {
5556
log("Found closest event:", closestEvent.timestamp);
5657
setFeaturedObject(closestEvent);
58+
59+
setTimeout(() => focusSelectedRow(), 0);
5760
}
5861
});
5962

@@ -133,11 +136,6 @@ function MyMapComponent(props) {
133136
map.setHeading(parseInt(urlHeading));
134137
}
135138
map.setOptions({ maxZoom: 100 });
136-
map.addListener("zoom_changed", () => {
137-
setQueryStringValue("zoom", map.getZoom());
138-
setIsFollowingVehicle(false); // zoom disables following
139-
log("Follow mode disabled due to zoom change");
140-
});
141139

142140
map.addListener("heading_changed", () => {
143141
setQueryStringValue("heading", map.getHeading());
@@ -318,7 +316,35 @@ function MyMapComponent(props) {
318316
// Update the polylines state to remove all route segments
319317
setPolylines(polylines.filter((p) => !p.isRouteSegment));
320318

321-
// Get the current route segment from the selected row
319+
const eventType = props.selectedRow["@type"];
320+
const isTripEvent = ["getTrip", "updateTrip", "createTrip"].includes(eventType);
321+
322+
if (isTripEvent) {
323+
// Create a thin red polyline with arrows for trip events
324+
const routeSegment = _.get(props.selectedRow, "response.currentroutesegment");
325+
if (routeSegment) {
326+
try {
327+
const decodedPoints = decode(routeSegment);
328+
if (decodedPoints && decodedPoints.length > 0) {
329+
const validWaypoints = decodedPoints.map((point) => ({
330+
lat: point.latDegrees(),
331+
lng: point.lngDegrees(),
332+
}));
333+
334+
const trafficPolyline = new TrafficPolyline({
335+
path: validWaypoints,
336+
zIndex: 3,
337+
isTripEvent: true,
338+
map: map,
339+
});
340+
setPolylines((prev) => [...prev, ...trafficPolyline.polylines]);
341+
}
342+
} catch (error) {
343+
console.error("Error processing trip event polyline:", error);
344+
}
345+
}
346+
}
347+
322348
const routeSegment =
323349
_.get(props.selectedRow, "request.vehicle.currentroutesegment") ||
324350
_.get(props.selectedRow, "lastlocation.currentroutesegment");
@@ -337,23 +363,19 @@ function MyMapComponent(props) {
337363
_.get(props.selectedRow, "request.vehicle.currentroutesegmenttraffic.trafficrendering") ||
338364
_.get(props.selectedRow, "lastlocation.currentroutesegmenttraffic.trafficrendering");
339365

340-
const rawLocation = _.get(props.selectedRow.lastlocation, "rawlocation");
366+
const location = _.get(props.selectedRow.lastlocation, "location");
341367

342368
const trafficPolyline = new TrafficPolyline({
343369
path: validWaypoints,
344370
zIndex: 2,
345371
trafficRendering: structuredClone(trafficRendering),
346-
currentLatLng: rawLocation,
372+
currentLatLng: location,
347373
map: map,
348374
});
349375
setPolylines((prev) => [...prev, ...trafficPolyline.polylines]);
350376
}
351377
} catch (error) {
352-
console.error("Error processing route segment polyline:", {
353-
error,
354-
routeSegment,
355-
rowData: props.selectedRow,
356-
});
378+
console.error("Error processing route segment polyline:", error);
357379
}
358380
}
359381
}, [props.selectedRow]);
@@ -384,34 +406,55 @@ function MyMapComponent(props) {
384406
strokeWeight: 1,
385407
rotation: 0,
386408
},
409+
rawLocation: {
410+
path: google.maps.SymbolPath.CIRCLE,
411+
fillColor: "#FF0000",
412+
fillOpacity: 1,
413+
scale: 2,
414+
strokeColor: "#FF0000",
415+
strokeWeight: 1,
416+
},
387417
};
388418

389-
const rawLocation = _.get(data.lastlocation, "rawlocation");
390-
if (rawLocation) {
391-
lastValidPositionRef.current = { lat: rawLocation.latitude, lng: rawLocation.longitude };
419+
const location = _.get(data.lastlocation, "location") || _.get(data.lastlocationResponse, "location");
420+
if (location) {
421+
lastValidPositionRef.current = { lat: location.latitude, lng: location.longitude };
392422

393-
const heading = _.get(data.lastlocation, "heading") || 0;
423+
const heading = _.get(data.lastlocation, "heading") || _.get(data.lastlocationResponse, "heading") || 0;
394424
markerSymbols.chevron.rotation = heading;
395425

396426
const backgroundMarker = new window.google.maps.Marker({
397-
position: { lat: rawLocation.latitude, lng: rawLocation.longitude },
427+
position: { lat: location.latitude, lng: location.longitude },
398428
map: map,
399429
icon: markerSymbols.background,
400430
clickable: false,
401431
zIndex: 9,
402432
});
403433

404434
const chevronMarker = new window.google.maps.Marker({
405-
position: { lat: rawLocation.latitude, lng: rawLocation.longitude },
435+
position: { lat: location.latitude, lng: location.longitude },
406436
map: map,
407437
icon: markerSymbols.chevron,
408438
zIndex: 10,
409439
});
410440

411441
dataMakers.push(backgroundMarker, chevronMarker);
412442

443+
const rawLocation = _.get(data.lastlocation, "rawlocation");
444+
if (rawLocation) {
445+
const rawLocationMarker = new window.google.maps.Marker({
446+
position: { lat: rawLocation.latitude, lng: rawLocation.longitude },
447+
map: map,
448+
icon: markerSymbols.rawLocation,
449+
zIndex: 8,
450+
clickable: false,
451+
});
452+
453+
dataMakers.push(rawLocationMarker);
454+
}
455+
413456
if (isFollowingVehicle) {
414-
map.setCenter({ lat: rawLocation.latitude, lng: rawLocation.longitude });
457+
map.setCenter({ lat: location.latitude, lng: location.longitude });
415458
}
416459
}
417460
}, [props.selectedRow, isFollowingVehicle]);
@@ -449,6 +492,7 @@ function Map(props) {
449492
jwt = props.logData.jwt;
450493
projectId = props.logData.projectId;
451494
setFeaturedObject = props.setFeaturedObject;
495+
focusSelectedRow = props.focusSelectedRow;
452496
setTimeRange = props.setTimeRange;
453497

454498
function centerOnLocation(lat, lng) {

src/TimeSlider.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ function TimeSlider(props) {
108108
if (props.centerOnLocation && lat && lng) {
109109
props.centerOnLocation(lat, lng);
110110
}
111+
112+
setTimeout(() => props.focusSelectedRow(), 0);
111113
}
112114
} else {
113115
log("TimeSlider - No logs found in current time range");

src/TrafficPolyline.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export const TRAFFIC_COLORS = {
1515
};
1616

1717
export class TrafficPolyline {
18-
constructor({ path, zIndex, trafficRendering, currentLatLng, map }) {
18+
constructor({ path, zIndex, isTripEvent, trafficRendering, currentLatLng, map }) {
1919
this.polylines = [];
2020
this.path = path;
2121
this.zIndex = zIndex;
22+
this.isTripEvent = isTripEvent;
2223
this.currentLatLng = currentLatLng;
2324
this.map = map;
2425
this.segments = this.calculateSegments(trafficRendering);
@@ -142,6 +143,33 @@ export class TrafficPolyline {
142143
}
143144

144145
createPolylines() {
146+
if (this.isTripEvent) {
147+
const polyline = new google.maps.Polyline({
148+
path: this.path,
149+
geodesic: true,
150+
strokeColor: "#000000",
151+
strokeOpacity: 1,
152+
strokeWeight: 1.5,
153+
zIndex: this.zIndex || 3,
154+
isRouteSegment: true,
155+
icons: [
156+
{
157+
icon: {
158+
path: google.maps.SymbolPath.FORWARD_OPEN_ARROW,
159+
scale: 1.5,
160+
strokeWeight: 1,
161+
},
162+
offset: "50%",
163+
repeat: "100px",
164+
},
165+
],
166+
map: this.map,
167+
clickable: false,
168+
});
169+
this.polylines.push(polyline);
170+
return;
171+
}
172+
145173
this.segments.forEach((segment) => {
146174
const polyline = new google.maps.Polyline({
147175
path: segment.path,

src/Trip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class Trip {
5555
// or synthesize pathCoords on the fly?
5656
appendCoords(lastLocation, timestamp) {
5757
this.pathCoords.push({
58-
lat: lastLocation.rawlocation.latitude,
59-
lng: lastLocation.rawlocation.longitude,
58+
lat: lastLocation.location.latitude,
59+
lng: lastLocation.location.longitude,
6060
trip_id: this.tripName,
6161
date: new Date(timestamp),
6262
});

0 commit comments

Comments
 (0)