mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix: center named places on their own location
A place's bounds can reach far from the place itself; Tokyo's include remote Pacific islands, so the middle of its box is open ocean. Keep the geocoder's point for a named place and use it as the area's center, while bounds still decide what lies inside the area.
This commit is contained in:
1 parent
469b1e8d89
commit
0dbd6375fc
3 files changed
+38
-5
No files matched your search
+10
-2
@@ -75,7 +75,11 @@ export async function resolveArea(area, { services, signal } = {}) {
|
||||
'invalid_arguments',
|
||||
`No place matched "${area.place}"; try a more specific name or a bbox`,
|
||||
);
|
||||
return { label: place.name || area.place, ...place.bounds };
|
||||
return {
|
||||
label: place.name || area.place,
|
||||
...place.bounds,
|
||||
...(place.point ? { point: place.point } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function circleArea(lat, lon, radiusKm) {
|
||||
@@ -151,9 +155,13 @@ export function distanceKm(a, b) {
|
||||
return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h)));
|
||||
}
|
||||
|
||||
/** The center of a resolved area, handling boxes across the antimeridian. */
|
||||
/**
|
||||
* The center of a resolved area: a radius area's center, a named place's own
|
||||
* point, or the middle of a box (handling boxes across the antimeridian).
|
||||
*/
|
||||
export function areaCenter(area) {
|
||||
if (area.center) return { lat: area.center.lat, lon: area.center.lon };
|
||||
if (area.point) return { lat: area.point.lat, lon: area.point.lon };
|
||||
const width =
|
||||
area.west <= area.east
|
||||
? area.east - area.west
|
||||
|
||||
Reference in new issue
Block a user