From e1b4c9f5dfd3b4e2b31bd873b4380a420dcd1685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zbytovsk=C3=BD?= Date: Sun, 29 Jan 2023 22:17:06 +0100 Subject: [PATCH 1/2] FeaturePanel: fetch 1000 items from overpass --- src/services/osmApi.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/osmApi.ts b/src/services/osmApi.ts index 3536f4d63..830e7cc87 100644 --- a/src/services/osmApi.ts +++ b/src/services/osmApi.ts @@ -155,9 +155,9 @@ export const insertOsmNote = async (point: Position, text: string) => { const getAroundUrl = ([lat, lon]: Position) => `https://overpass-api.de/api/interpreter?data=${encodeURIComponent( `[timeout:5][out:json];( - relation[~"."~"."](around:50,${lon},${lat}); - way[~"."~"."](around:50,${lon},${lat}); - node[~"."~"."](around:50,${lon},${lat}); + relation[~"."~"."](around:500,${lon},${lat}); + way[~"."~"."](around:1000,${lon},${lat}); + node[~"."~"."](around:1000,${lon},${lat}); );out 20 body qt center;`, // some will be filtered out )}`; From 536825bda7353992fd21cfec5b8a92baa9d873d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zbytovsk=C3=BD?= Date: Sun, 29 Jan 2023 22:45:07 +0100 Subject: [PATCH 2/2] try to sort it by distance - broken?? --- src/components/FeaturePanel/ObjectsAround.tsx | 12 ++++----- src/services/osmApi.ts | 25 +++++++++++++++---- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/components/FeaturePanel/ObjectsAround.tsx b/src/components/FeaturePanel/ObjectsAround.tsx index 05c061192..32e8f6507 100644 --- a/src/components/FeaturePanel/ObjectsAround.tsx +++ b/src/components/FeaturePanel/ObjectsAround.tsx @@ -25,7 +25,7 @@ const useLoadingState = () => { setError(undefined); }; const failAround = (err) => { - setError(err instanceof FetchError ? err.message : err); + setError(err.message ? err.message : JSON.stringify(err)); setLoading(false); }; return { around, error, loading, startAround, finishAround, failAround }; @@ -90,11 +90,11 @@ export const ObjectsAround = ({ advanced }) => { if (item.properties.subclass === 'building:part') return false; return true; }) - .sort( - (a, b) => - (b.properties.class === 'home' ? -5 : Object.keys(b.tags).length) - // leave address points at the bottom - Object.keys(a.tags).length, - ) + // .sort( + // (a, b) => + // (b.properties.class === 'home' ? -5 : Object.keys(b.tags).length) - // leave address points at the bottom + // Object.keys(a.tags).length, + // ) .slice(0, 10); return ( diff --git a/src/services/osmApi.ts b/src/services/osmApi.ts index 830e7cc87..6ed27ee96 100644 --- a/src/services/osmApi.ts +++ b/src/services/osmApi.ts @@ -155,13 +155,28 @@ export const insertOsmNote = async (point: Position, text: string) => { const getAroundUrl = ([lat, lon]: Position) => `https://overpass-api.de/api/interpreter?data=${encodeURIComponent( `[timeout:5][out:json];( - relation[~"."~"."](around:500,${lon},${lat}); - way[~"."~"."](around:1000,${lon},${lat}); - node[~"."~"."](around:1000,${lon},${lat}); - );out 20 body qt center;`, // some will be filtered out + relation[~"."~"."](around:50,${lon},${lat}); + way[~"."~"."](around:50,${lon},${lat}); + node[~"."~"."](around:50,${lon},${lat}); + );out 400 body qt center;`, // some will be filtered out )}`; +// intentionaly wrong distance, but faster +const getDist = (center: Position, point: Position) => + Math.sqrt( + Math.pow(center[0] - point[0], 2) + Math.pow(center[1] - point[1], 2), + ); + export const fetchAroundFeature = async (point: Position) => { const response = await fetchJson(getAroundUrl(point)); - return overpassAroundToSkeletons(response); + const features = overpassAroundToSkeletons(response); + return features.sort((a, b) => { + if (a.center === undefined || b.center === undefined) { + return 100; + } + if (b.properties.class === 'home') { + return -1; + } + return getDist(a.center, point) - getDist(b.center, point); + }); };