Skip to content

Commit

Permalink
Avoid overzoom of small ways-POIs
Browse files Browse the repository at this point in the history
Some building POI's are stored as OSM ways, this means they have a bbox,
but using that bbox for zoom results in feeling a bit too close - losing
the valuable context of the surround block.

An example of a too-close bbox zoom that this commit fixes:

Victrola Coffee Roasters - "id": "way/206623301",
  • Loading branch information
michaelkirk committed Sep 17, 2022
1 parent 7eb5a47 commit 64e348b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions web/frontend/src/components/BaseMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,18 @@ export default defineComponent({
this.$data.flyToLocation = { center: location, zoom: zoom };
}
},
fitBounds: async function (bounds: LngLatBoundsLike) {
fitBounds: async function (
bounds: LngLatBoundsLike,
options: FitBoundsOptions = {}
) {
const permissionState = await geolocationPermissionState();
const defaultOptions = {
padding: Math.min(window.innerWidth, window.innerHeight) / 8,
};
options = { ...defaultOptions, ...(options || {}) };
if (this.$data.hasGeolocated === true || permissionState !== 'granted') {
map?.fitBounds(bounds, {
padding: Math.min(window.innerWidth, window.innerHeight) / 8,
});
map?.fitBounds(bounds, options);
} else {
this.$data.boundsToFit = bounds;
}
Expand Down
2 changes: 1 addition & 1 deletion web/frontend/src/pages/PlacePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function loadPlacePage(router: Router, canonicalName: string) {
if (poi.bbox) {
// prefer bounds when available so we don't "overzoom" on a large
// entity like an entire city.
getBaseMap()?.fitBounds(poi.bbox);
getBaseMap()?.fitBounds(poi.bbox, { maxZoom: 16 });
} else if (poi.position) {
getBaseMap()?.flyTo([poi.position.long, poi.position.lat], 16);
}
Expand Down

0 comments on commit 64e348b

Please sign in to comment.