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

Don't overzoom large (city-sized) POIs #161

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions web/frontend/src/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default defineComponent({
address: address,
key: feature.properties.osm_id,
position: position,
bbox: feature.bbox,
gid: feature?.properties?.gid,
});
}
Expand Down
15 changes: 13 additions & 2 deletions web/frontend/src/pages/PlacePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ import SearchBox from 'src/components/SearchBox.vue';

async function loadPlacePage(router: Router, canonicalName: string) {
const poi = await decanonicalizePoi(canonicalName);
if (poi === undefined) {
return poi;
}

if (poi?.position) {
if (poi.bbox) {
// prefer bounds when available so we don't "overzoom" on a large
// entity like an entire city.
getBaseMap()?.fitBounds(poi.bbox, { maxZoom: 16 });
michaelkirk marked this conversation as resolved.
Show resolved Hide resolved
} else if (poi.position) {
getBaseMap()?.flyTo([poi.position.long, poi.position.lat], 16);
}

if (poi.position) {
getBaseMap()?.pushMarker(
'active_marker',
new Marker({ color: '#111111' }).setLngLat([
Expand All @@ -39,8 +49,9 @@ async function loadPlacePage(router: Router, canonicalName: string) {
])
);
getBaseMap()?.removeMarkersExcept(['active_marker']);
return poi;
}

return poi;
}

export default defineComponent({
Expand Down
2 changes: 2 additions & 0 deletions web/frontend/src/utils/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface POI {
name?: string | null;
address?: string | null;
position?: LongLat;
bbox?: [number, number, number, number];
michaelkirk marked this conversation as resolved.
Show resolved Hide resolved
gid?: string;
}

Expand Down Expand Up @@ -137,6 +138,7 @@ export async function decanonicalizePoi(
address: address,
key: feature.properties.osm_id,
position: position,
bbox: feature.bbox,
gid: feature?.properties?.gid,
};
}
Expand Down