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
This commit is contained in:
Paul Adamsen
2023-08-25 15:54:21 -04:00
committed by GitHub
parent 712c876115
commit 0f8e4eb960
2 changed files with 15 additions and 5 deletions

View File

@@ -279,8 +279,8 @@ exports[`DigitalTwinTab Render 1`] = `
alt="" alt=""
class="leaflet-tile" class="leaflet-tile"
role="presentation" role="presentation"
src="https://b.tile.openstreetmap.org/5/7/12.png" src="https://c.tile.openstreetmap.org/5/5/12.png"
style="width: 256px; height: 256px; left: -126px; top: -114px;" style="width: 256px; height: 256px; left: -30px; top: -95px;"
/> />
</div> </div>
</div> </div>
@@ -299,7 +299,7 @@ exports[`DigitalTwinTab Render 1`] = `
class="leaflet-marker-icon leaflet-zoom-hide leaflet-interactive" class="leaflet-marker-icon leaflet-zoom-hide leaflet-interactive"
role="button" role="button"
src="gray-marker.png" 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" tabindex="0"
title="TESTVIN1234567890" title="TESTVIN1234567890"
/> />

View File

@@ -85,13 +85,23 @@ const Component = (props) => {
}; };
const centerAroundMarkers = (points) => { 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) { if (lastMapCenter) {
let zoomLocation = JSON.parse(lastMapCenter) let zoomLocation = JSON.parse(lastMapCenter)
setCenter(zoomLocation.center); setCenter(zoomLocation.center);
setZoom(zoomLocation.zoom) setZoom(zoomLocation.zoom)
} else { } else {
let defaultLocationJSON = process.env.REACT_APP_HOME_MAP_DEFAULT_LOCATION;
let defaultLocation = JSON.parse(defaultLocationJSON)
setCenter([defaultLocation.lat, defaultLocation.lng]); setCenter([defaultLocation.lat, defaultLocation.lng]);
setZoom(defaultLocation.zoom); setZoom(defaultLocation.zoom);
} }