Skip to content

Commit 505a8bc

Browse files
committed
DBC22-1589: removed all automatic panning on map load
1 parent 9bc28aa commit 505a8bc

File tree

1 file changed

+22
-16
lines changed
  • src/frontend/src/Components

1 file changed

+22
-16
lines changed

src/frontend/src/Components/Map.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export default function MapWrapper({
102102
const { mapContext, setMapContext } = useContext(MapContext);
103103

104104
// Refs
105-
const isInitialMount = useRef(true);
105+
const isInitialMountLocation = useRef(true);
106+
const isInitialMountRoute = useRef(true);
106107
const mapElement = useRef();
107108
const mapRef = useRef();
108109
const popup = useRef();
@@ -410,20 +411,23 @@ export default function MapWrapper({
410411
resetHoveredStates(null);
411412
});
412413

413-
if (!camera) {
414-
// if there is no parameter for shifting the view, pan to my location
415-
toggleMyLocation();
416-
}
417-
418-
loadData();
414+
loadData(true);
419415
});
420416

421417
useEffect(() => {
422418
if (searchLocationFrom && searchLocationFrom.length) {
423-
if (locationPinRef.current) {
424-
mapRef.current.removeOverlay(locationPinRef.current);
419+
if (isInitialMountLocation.current) {
420+
isInitialMountLocation.current = false;
421+
422+
} else {
423+
// Don't center/remove existing overlay on first load
424+
if (locationPinRef.current) {
425+
mapRef.current.removeOverlay(locationPinRef.current);
426+
}
427+
428+
centerMap(searchLocationFrom[0].geometry.coordinates);
425429
}
426-
centerMap(searchLocationFrom[0].geometry.coordinates);
430+
427431
setLocationPin(
428432
searchLocationFrom[0].geometry.coordinates,
429433
blueLocationMarkup,
@@ -434,8 +438,8 @@ export default function MapWrapper({
434438
}, [searchLocationFrom]);
435439

436440
useEffect(() => {
437-
if (isInitialMount.current) { // Do nothing on first load
438-
isInitialMount.current = false;
441+
if (isInitialMountRoute.current) { // Do nothing on first load
442+
isInitialMountRoute.current = false;
439443
return;
440444
}
441445

@@ -444,7 +448,7 @@ export default function MapWrapper({
444448
mapRef.current.removeLayer(mapLayers.current['routeLayer']);
445449
}
446450

447-
loadData();
451+
loadData(false);
448452
}, [selectedRoute]);
449453

450454
useEffect(() => {
@@ -533,7 +537,7 @@ export default function MapWrapper({
533537
// }
534538
}
535539

536-
const loadData = () => {
540+
const loadData = (isInitialMount) => {
537541
if (selectedRoute && selectedRoute.routeFound) {
538542
const routeLayer = getRouteLayer(selectedRoute, mapRef.current.getView().getProjection().getCode());
539543
mapLayers.current['routeLayer'] = routeLayer;
@@ -544,8 +548,10 @@ export default function MapWrapper({
544548
loadEvents(selectedRoute);
545549
loadFerries();
546550

547-
// Zoom/pan to route
548-
fitMap(selectedRoute.route, mapView);
551+
// Zoom/pan to route on route updates
552+
if (!isInitialMount) {
553+
fitMap(selectedRoute.route, mapView);
554+
}
549555

550556
} else {
551557
// Clear and update data

0 commit comments

Comments
 (0)