Skip to content

Commit

Permalink
ObjectsAround: fix - use correct getCenter (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Dec 29, 2023
1 parent f6d20e1 commit 7c3baf6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/services/getCenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface NamedBbox {
n: number;
}

const getBbox = (coordinates: Position[]): NamedBbox => {
export const getBbox = (coordinates: Position[]): NamedBbox => {
const [firstX, firstY] = coordinates[0];
const initialBbox = { w: firstX, s: firstY, e: firstX, n: firstY };

Expand Down
29 changes: 27 additions & 2 deletions src/services/overpassAroundToSkeletons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { Feature, LineString, Point } from './types';
import {
Feature,
LineString,
Point,
FeatureGeometry,
isPoint,
isWay,
Position,
} from './types';

import { getPoiClass } from './getPoiClass';
import { getCenter } from './getCenter';
import { getBbox } from './getCenter';

export const getCenter = (geometry: FeatureGeometry): Position => {
if (isPoint(geometry)) {
return geometry.coordinates;
}

if (isWay(geometry) && geometry.coordinates?.length) {
const { w, s, e, n } = getBbox(geometry.coordinates); // [WSEN]
const lon = (w + e) / 2; // flat earth rulezz
const lat = (s + n) / 2;
return [lon, lat];
}

// relation
return undefined;
};

const notNull = (x) => x != null;

Expand Down

1 comment on commit 7c3baf6

@vercel
Copy link

@vercel vercel bot commented on 7c3baf6 Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.