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

FeaturePanel: fetch 1000 items from overpass #130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions src/components/FeaturePanel/ObjectsAround.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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 (
Expand Down
19 changes: 17 additions & 2 deletions src/services/osmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,25 @@ const getAroundUrl = ([lat, lon]: Position) =>
relation[~"."~"."](around:50,${lon},${lat});
way[~"."~"."](around:50,${lon},${lat});
node[~"."~"."](around:50,${lon},${lat});
);out 20 body qt center;`, // some will be filtered out
);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);
});
};