CEC-4543 - Add location to digital twin map (#376)
This commit is contained in:
@@ -105,7 +105,7 @@ export const VehicleProvider = ({ children }) => {
|
||||
setBusy(true);
|
||||
const result = await api.getLocations(token);
|
||||
if (result.error)
|
||||
throw new Error(`Get locations vehicle paths error. ${result.message}`);
|
||||
throw new Error(`Get locations error. ${result.message}`);
|
||||
return result;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
|
||||
@@ -153,9 +153,9 @@ export const useVehicleContext = () => ({
|
||||
.fn()
|
||||
.mockResolvedValue({
|
||||
// tests only pass without mocking the data here
|
||||
// '3FAFP13P71R199267': [],
|
||||
// '3FAFP13P31R199430': [[16.891136999999986, 26.832352999999955], [56.891136999999986, 66.832352999999955], [26.891136999999986, 36.832352999999955]],
|
||||
// '3FAFP13P71R199060': [[36.891136999999986, 46.832352999999955], [76.891136999999986, 16.832352999999955]],
|
||||
// '3FAFP13P61R199390': [],
|
||||
}),
|
||||
getModels: jest.fn(() => {
|
||||
models = ["Ocean", "PEAR"];
|
||||
|
||||
@@ -7,7 +7,7 @@ import useStyles from "../useStyles";
|
||||
import GrayMarkerIcon from "../../assets/gray-marker.png";
|
||||
import GreenMarkerIcon from "../../assets/green-marker.png";
|
||||
import { logger } from "../../services/monitoring";
|
||||
import { ValidateLocationVehiclePathsData } from "../../utils/locations";
|
||||
import { ValidateLocationData, ValidateLocationVehiclePathsData } from "../../utils/locations";
|
||||
import { useUserContext } from "../Contexts/UserContext";
|
||||
import { useVehicleContext, VehicleProvider } from "../Contexts/VehicleContext";
|
||||
import { VehiclePopUp } from "../VehicleMap/popup";
|
||||
@@ -54,23 +54,32 @@ const ComponentVehiclePathsMap = (props) => {
|
||||
vinsParam += props.lookbackHours
|
||||
|
||||
return getLocationsVehiclePaths(accessToken, vinsParam)
|
||||
.then((result) => {
|
||||
.then(async (result) => {
|
||||
let resultArray = Object.entries(result)
|
||||
const points = []
|
||||
|
||||
// validate each location
|
||||
for (let vinLocations of resultArray) {
|
||||
// if there are points for the vin; skip if empty points array
|
||||
if (vinLocations[0] && vinLocations[1] && vinLocations[1][0]) {
|
||||
let path = []
|
||||
path[0] = vinLocations[0]
|
||||
path[1] = []
|
||||
for (let location of vinLocations[1]) {
|
||||
if (ValidateLocationVehiclePathsData(location) !== false) {
|
||||
path[1].push(location);
|
||||
if (vinLocations[0]) {
|
||||
let path = [];
|
||||
path[0] = vinLocations[0];
|
||||
path[1] = [];
|
||||
if (vinLocations[1] && vinLocations[1][0]) {
|
||||
for (let location of vinLocations[1]) {
|
||||
if (ValidateLocationVehiclePathsData(location) !== false) {
|
||||
path[1].push(location);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await getState(token, vinLocations[0]).then((stateResult) => {
|
||||
if (stateResult.data && stateResult.data.location) {
|
||||
if (ValidateLocationData(stateResult.data.location) !== false) {
|
||||
path[1].push([stateResult.data.location.latitude, stateResult.data.location.longitude]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
points.push(path)
|
||||
points.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user