Skip to content

Commit 0a02d85

Browse files
fatbirdray-oxd
authored andcommitted
DBC22-5228 Feedback changes
1 parent 9bcda14 commit 0a02d85

2 files changed

Lines changed: 37 additions & 16 deletions

File tree

src/frontend/src/Components/map/Map.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,41 @@ export default function DriveBCMap(props) {
370370
const [showLocationAccessError, setShowLocationAccessError] = useState(false);
371371

372372
const loadMyLocation = () => {
373-
// per DBC22-5228, clicking button always moves to user's current location
374-
if ('geolocation' in navigator) {
375-
navigator.geolocation.getCurrentPosition((position) => {
376-
const { latitude, longitude } = position.coords;
377-
if (
378-
position.coords.longitude <= -113.7 &&
379-
position.coords.longitude >= -139.3 &&
380-
position.coords.latitude <= 60.1 &&
381-
position.coords.latitude >= 48.2
382-
) {
383-
setZoomPan(mapView, 9, fromLonLat([longitude, latitude]));
384-
}
385-
});
386-
}
387-
388373
if (!locationSet.current) {
389374
setMyLocationLoading(true);
390375
} else {
376+
// per DBC22-5228, clicking button always moves to user's current location
377+
if ('geolocation' in navigator) {
378+
navigator.geolocation.getCurrentPosition(
379+
(position) => {
380+
const { latitude, longitude } = position.coords;
381+
if (
382+
position.coords.longitude <= -113.7 &&
383+
position.coords.longitude >= -139.3 &&
384+
position.coords.latitude <= 60.1 &&
385+
position.coords.latitude >= 48.2
386+
) {
387+
setZoomPan(mapView, 9, fromLonLat([longitude, latitude]));
388+
}
389+
},
390+
(error) => {
391+
// The user has blocked location access
392+
if (error.code === error.PERMISSION_DENIED) {
393+
setShowLocationAccessError(true);
394+
setMyLocationLoading(false);
395+
396+
} else {
397+
// Zoom out and center to BC if location not available
398+
setZoomPan(mapView, 9, fromLonLat([-126.5, 54.2]));
399+
setMyLocationLoading(false);
400+
}
401+
},
402+
{
403+
maximumAge: 30000, // 30 seconds
404+
}
405+
);
406+
}
407+
391408
dispatch(updateSearchLocationFromWithMyLocation([locationSet.current]));
392409
}
393410
}

src/frontend/src/Components/map/helpers/map.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const zoomOut = (mapView) => {
8383
export const toggleMyLocation = (mapRef, mapView, setMyLocationLoading, setMyLocation, setShowLocationAccessError) => {
8484
if ('geolocation' in navigator) {
8585
navigator.geolocation.getCurrentPosition(
86-
position => {
86+
(position) => {
8787
const { latitude, longitude } = position.coords;
8888
if (
8989
position.coords.longitude <= -113.7 &&
@@ -112,6 +112,7 @@ export const toggleMyLocation = (mapRef, mapView, setMyLocationLoading, setMyLoc
112112
};
113113

114114
setMyLocation(myLocation);
115+
setZoomPan(mapView, 9, fromLonLat([longitude, latitude]));
115116
setMyLocationLoading(false);
116117

117118
} else {
@@ -132,6 +133,9 @@ export const toggleMyLocation = (mapRef, mapView, setMyLocationLoading, setMyLoc
132133
setMyLocationLoading(false);
133134
}
134135
},
136+
{
137+
maximumAge: 30000, // 30 seconds
138+
}
135139
);
136140
}
137141
}

0 commit comments

Comments
 (0)