Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zooming when Map Bounds are not fitted #442

Merged
merged 9 commits into from
Jan 27, 2025
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/map-template/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.66.5] - 2025-01-27

## Fixed

- Fixed an issue with `startZoomLevel` prop causing the map starting in a random position.

## [1.66.4] - 2025-01-23

## Fixed
Expand Down
9 changes: 5 additions & 4 deletions packages/map-template/src/hooks/useMapBoundsDeterminer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const useMapBoundsDeterminer = () => {
/*
* When relevant state changes, run code to go to a location in the world.
*/
useEffect(() => {
useEffect(() => {
determineMapBounds();
}, [mapsIndoorsInstance, currentVenueName, locationId, kioskOriginLocationId, pitch, bearing, startZoomLevel, categories]);

Expand Down Expand Up @@ -116,7 +116,7 @@ const useMapBoundsDeterminer = () => {
} else if (currentVenue) {
// When showing a venue, the map is fitted to the bounds of the Venue with no padding.
setMapPositionKnown(currentVenue.geometry);
goTo(currentVenue.geometry, mapsIndoorsInstance, 0, 0, startZoomLevel, currentPitch, bearing);
goTo(currentVenue.geometry, mapsIndoorsInstance, 0, 0, startZoomLevel, currentPitch, bearing, mapPositionKnown);
Lucaci-Andrei marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -157,15 +157,16 @@ export default useMapBoundsDeterminer;
* @param {number} zoomLevel - Enforced zoom level.
* @param {number} pitch - Map pitch (tilt).
* @param {number} bearing - Mp bearing (rotation) in degrees from north.
* @param {boolean} [mapPositionKnown] - Checks if map position is known. Based on that, we can perform zooming to a specific geometry, once map is loaded.
*/
Lucaci-Andrei marked this conversation as resolved.
Show resolved Hide resolved
function goTo(geometry, mapsIndoorsInstance, paddingBottom, paddingLeft, zoomLevel, pitch, bearing) {
function goTo(geometry, mapsIndoorsInstance, paddingBottom, paddingLeft, zoomLevel, pitch, bearing, mapPositionKnown) {
mapsIndoorsInstance.getMapView().tilt(pitch || 0);
mapsIndoorsInstance.getMapView().rotate(bearing || 0);
mapsIndoorsInstance.goTo({ type: 'Feature', geometry, properties: {}}, {
maxZoom: zoomLevel ?? 22,
padding: { top: 0, right: 0, bottom: paddingBottom, left: paddingLeft },
}).then(() => {
if (zoomLevel) {
if (zoomLevel && mapPositionKnown !== false) {
mapsIndoorsInstance.setZoom(zoomLevel);
}
});
Expand Down
Loading