From 0f8e4eb9601a151e8c8b5815e26992e6ba7a910b Mon Sep 17 00:00:00 2001 From: Paul Adamsen <117673433+pauladamseniii@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:54:21 -0400 Subject: [PATCH] CEC-4955 - Digital Twin map zooms to location of car (#428) * CEC-4955 - Digital twin show vehicle location * fix code smell * CEC-4955 - Zoom to location of car --- .../__snapshots__/DigitalTwinTab.test.jsx.snap | 6 +++--- src/components/VehicleMap/index.jsx | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/Cars/Status/__snapshots__/DigitalTwinTab.test.jsx.snap b/src/components/Cars/Status/__snapshots__/DigitalTwinTab.test.jsx.snap index 5e87a73..ea76d8e 100644 --- a/src/components/Cars/Status/__snapshots__/DigitalTwinTab.test.jsx.snap +++ b/src/components/Cars/Status/__snapshots__/DigitalTwinTab.test.jsx.snap @@ -279,8 +279,8 @@ exports[`DigitalTwinTab Render 1`] = ` alt="" class="leaflet-tile" role="presentation" - src="https://b.tile.openstreetmap.org/5/7/12.png" - style="width: 256px; height: 256px; left: -126px; top: -114px;" + src="https://c.tile.openstreetmap.org/5/5/12.png" + style="width: 256px; height: 256px; left: -30px; top: -95px;" /> @@ -299,7 +299,7 @@ exports[`DigitalTwinTab Render 1`] = ` class="leaflet-marker-icon leaflet-zoom-hide leaflet-interactive" role="button" src="gray-marker.png" - style="margin-left: -24px; margin-top: -42px; opacity: 0.9; left: -608px; top: -19px; z-index: -19;" + style="margin-left: -24px; margin-top: -42px; opacity: 0.9; left: 0px; top: 0px; z-index: 0; z-index: 0; z-index: 0; z-index: 0; z-index: 0; z-index: 0; z-index: 0; z-index: 0; z-index: 0;" tabindex="0" title="TESTVIN1234567890" /> diff --git a/src/components/VehicleMap/index.jsx b/src/components/VehicleMap/index.jsx index f5d9427..06423cb 100644 --- a/src/components/VehicleMap/index.jsx +++ b/src/components/VehicleMap/index.jsx @@ -85,13 +85,23 @@ const Component = (props) => { }; const centerAroundMarkers = (points) => { + let defaultLocationJSON = process.env.REACT_APP_HOME_MAP_DEFAULT_LOCATION; + let defaultLocation = JSON.parse(defaultLocationJSON) + + if (props.vin) { + // center is the location of the specified vin + if (points && points[0]) { + setCenter([points[0][0], points[0][1]]); + setZoom(defaultLocation.zoom); + return + } + } + if (lastMapCenter) { let zoomLocation = JSON.parse(lastMapCenter) setCenter(zoomLocation.center); setZoom(zoomLocation.zoom) } else { - let defaultLocationJSON = process.env.REACT_APP_HOME_MAP_DEFAULT_LOCATION; - let defaultLocation = JSON.parse(defaultLocationJSON) setCenter([defaultLocation.lat, defaultLocation.lng]); setZoom(defaultLocation.zoom); }