Skip to content

Commit 7748965

Browse files
committed
feat: change car marker to be chevron with heading similar to google maps navigation
1 parent ea58ed0 commit 7748965

File tree

2 files changed

+67
-37
lines changed

2 files changed

+67
-37
lines changed

src/Map.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/*
2-
* Map.js
3-
*
4-
* Uses the react-wrapper to make using google maps js sdk
5-
* easier in react. Beyond basic loading doesn't pretend to
6-
* act like a normal react component.
7-
*/
1+
// src/Map.js
2+
83
import { useEffect, useRef, useState } from "react";
94
import { Wrapper, Status } from "@googlemaps/react-wrapper";
105
import _ from "lodash";
@@ -325,33 +320,55 @@ function MyMapComponent(props) {
325320
}, [props.rangeStart, props.rangeEnd]);
326321

327322
useEffect(() => {
323+
// Car location maker
328324
const data = props.selectedRow;
329325
if (!data) return;
330326
_.forEach(dataMakers, (m) => m.setMap(null));
331327
dataMakers = [];
332-
const svgMarker = {
333-
path: "M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
334-
fillColor: "blue",
335-
fillOpacity: 0.6,
336-
strokeWeight: 0,
337-
rotation: 0,
338-
scale: 1,
339-
anchor: new google.maps.Point(15, 30),
328+
329+
const markerSymbols = {
330+
background: {
331+
path: google.maps.SymbolPath.CIRCLE,
332+
fillColor: "#FFFFFF",
333+
fillOpacity: 0.7,
334+
scale: 18,
335+
strokeColor: "#FFFFFF",
336+
strokeWeight: 2,
337+
strokeOpacity: 0.3,
338+
},
339+
chevron: {
340+
path: "M -1,1 L 0,-1 L 1,1 L 0,0.5 z",
341+
fillColor: "#4285F4",
342+
fillOpacity: 1,
343+
scale: 10,
344+
strokeColor: "#4285F4",
345+
strokeWeight: 1,
346+
rotation: 0,
347+
},
340348
};
341349

342350
const rawLocation = _.get(data.lastlocation, "rawlocation");
343351
if (rawLocation) {
344-
const status = _.get(data, "response.tripstatus");
345-
const state = _.get(data, "response.vehiclestate");
346-
const locationForLog = new window.google.maps.Marker({
352+
const heading = _.get(data.lastlocation, "heading") || 0;
353+
markerSymbols.chevron.rotation = heading;
354+
355+
const backgroundMarker = new window.google.maps.Marker({
347356
position: { lat: rawLocation.latitude, lng: rawLocation.longitude },
348357
map: map,
349-
icon: svgMarker,
350-
title: "Vehicle state " + state + " Trip Status " + status,
358+
icon: markerSymbols.background,
359+
clickable: false,
360+
zIndex: 9,
351361
});
352-
dataMakers.push(locationForLog);
362+
363+
const chevronMarker = new window.google.maps.Marker({
364+
position: { lat: rawLocation.latitude, lng: rawLocation.longitude },
365+
map: map,
366+
icon: markerSymbols.chevron,
367+
zIndex: 10,
368+
});
369+
370+
dataMakers.push(backgroundMarker, chevronMarker);
353371
}
354-
// TODO: for non-vehicle api calls could attempt to interpolate the location
355372
}, [props.selectedRow]);
356373

357374
for (const toggle of props.toggles) {

src/TripLogs.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* TripLogs.js
2+
* src/TripLogs.js
33
*
44
* Processes raw logs into 'trip segments'. A trip segment might
55
* be an individual trip, a contiguous non-trip region, or the route
@@ -9,6 +9,7 @@ import _ from "lodash";
99
import Trip from "./Trip";
1010
import HighVelocityJump from "./HighVelocityJump";
1111
import MissingUpdate from "./MissingUpdate";
12+
import { log } from "./Utils";
1213

1314
const maxDistanceForDwell = 20; // meters
1415
const requiredUpdatesForDwell = 12; // aka 2 minute assuming update vehicle request at 10 seconds
@@ -96,16 +97,20 @@ function adjustFieldFormat(log, origPath, newPath, stringToTrim) {
9697
}
9798

9899
function processRawLogs(rawLogs, solutionType) {
99-
console.log(`Processing ${rawLogs.length} raw logs for ${solutionType}`);
100+
log(`Processing ${rawLogs.length} raw logs for ${solutionType}`);
100101
const origLogs = rawLogs.map(toLowerKeys);
101102
const isReversed =
102103
origLogs.length > 1 &&
103104
new Date(origLogs[0].timestamp) >
104105
new Date(origLogs[origLogs.length - 1].timestamp);
105-
console.log(`Raw logs are ${isReversed ? "reversed" : "chronological"}`);
106+
log(`Raw logs are ${isReversed ? "reversed" : "chronological"}`);
106107

107108
let sortedLogs = isReversed ? _.reverse(origLogs) : origLogs;
108109
let newLogs = [];
110+
let lastKnownLocation = null;
111+
let lastKnownHeading = 0;
112+
const vehiclePath =
113+
solutionType === "LMFS" ? "request.deliveryvehicle" : "request.vehicle";
109114

110115
for (let idx = 0; idx < sortedLogs.length; idx++) {
111116
const origLog = sortedLogs[idx];
@@ -185,6 +190,18 @@ function processRawLogs(rawLogs, solutionType) {
185190
);
186191
}
187192

193+
// Creating lastlocation for trip rows so that these still show the last known car marker
194+
const currentLocation = _.get(newLog, `${vehiclePath}.lastlocation`);
195+
if (currentLocation?.rawlocation) {
196+
lastKnownLocation = currentLocation.rawlocation;
197+
lastKnownHeading = currentLocation.heading;
198+
} else if (lastKnownLocation) {
199+
_.set(newLog, `${vehiclePath}.lastlocation`, {
200+
rawlocation: lastKnownLocation,
201+
heading: lastKnownHeading,
202+
});
203+
}
204+
188205
newLogs.push(newLog);
189206
}
190207
}
@@ -195,7 +212,7 @@ function processRawLogs(rawLogs, solutionType) {
195212

196213
class TripLogs {
197214
constructor(rawLogs, solutionType) {
198-
console.log(
215+
log(
199216
`Initializing TripLogs with ${rawLogs.length} raw logs for ${solutionType}`
200217
);
201218
this.initialize(rawLogs, solutionType);
@@ -250,11 +267,9 @@ class TripLogs {
250267
this.processTripSegments();
251268
this.debouncedGetHighVelocityJumps = _.debounce(
252269
(minDate, maxDate, callback) => {
253-
console.log("debouncedGetHighVelocityJumps executing");
270+
log("debouncedGetHighVelocityJumps executing");
254271
const jumps = this.getHighVelocityJumps(minDate, maxDate);
255-
console.log(
256-
`debouncedGetHighVelocityJumps found ${jumps.length} jumps`
257-
);
272+
log(`debouncedGetHighVelocityJumps found ${jumps.length} jumps`);
258273
callback(jumps);
259274
},
260275
300
@@ -331,7 +346,7 @@ class TripLogs {
331346
* updates.
332347
*/
333348
getETADeltas(minDate, maxDate) {
334-
console.log(`Getting ETA deltas between ${minDate} and ${maxDate}`);
349+
log(`Getting ETA deltas between ${minDate} and ${maxDate}`);
335350
let prevEntry;
336351
this.etaDeltas = this.getRawLogs_(minDate, maxDate)
337352
.filter(
@@ -366,9 +381,7 @@ class TripLogs {
366381
* at an unrealistic velocity.
367382
*/
368383
getHighVelocityJumps(minDate, maxDate) {
369-
console.log(
370-
`Getting high velocity jumps between ${minDate} and ${maxDate}`
371-
);
384+
log(`Getting high velocity jumps between ${minDate} and ${maxDate}`);
372385

373386
let prevEntry;
374387
let entries = this.getRawLogs_(minDate, maxDate)
@@ -384,7 +397,7 @@ class TripLogs {
384397
.compact()
385398
.value();
386399

387-
console.log(`Created ${entries.length} HighVelocityJump instances`);
400+
log(`Created ${entries.length} HighVelocityJump instances`);
388401

389402
const velocityJumps = HighVelocityJump.getSignificantJumps(entries);
390403
console.log(`Found ${velocityJumps.length} high velocity jumps`);
@@ -410,7 +423,7 @@ class TripLogs {
410423
* description of the very simplistic algo used here.
411424
*/
412425
getDwellLocations(minDate, maxDate) {
413-
console.log(`Getting dwell locations between ${minDate} and ${maxDate}`);
426+
log(`Getting dwell locations between ${minDate} and ${maxDate}`);
414427
const dwellLocations = [];
415428
_.forEach(this.rawLogs, (le) => {
416429
const lastLocation = le.lastlocation;
@@ -470,7 +483,7 @@ class TripLogs {
470483
}
471484

472485
processTripSegments() {
473-
console.log("Processing trip segments");
486+
log("Processing trip segments");
474487
let curTripId = "this is not a segment";
475488
let curTripData = undefined;
476489
let tripIdx = 0;

0 commit comments

Comments
 (0)