Skip to content

Commit

Permalink
general: add offline country resolution (zbycz#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored May 15, 2024
1 parent 040704c commit bda6186
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions __mocks__/next-codegrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
resolveCountryCode: jest.fn().mockReturnValue(undefined),
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"lodash": "^4.17.21",
"maplibre-gl": "^3.3.1",
"next": "^13.4.3",
"next-codegrid": "^1.0.2",
"next-cookies": "^2.0.3",
"next-pwa": "^5.2.21",
"osm-auth": "^2.4.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/FeaturePanel/Coordinates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const Coords = ({ coords }: Props) => {
return (
<span title="latitude, longitude (y, x)" ref={anchorRef}>
{positionToDeg(coords)}
{feature.countryCode && ` (${feature.countryCode.toUpperCase()})`}
<Menu
anchorEl={anchorRef.current}
open={opened}
Expand Down
3 changes: 3 additions & 0 deletions src/services/osmApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resolveCountryCode } from 'next-codegrid';
import {
FetchError,
getApiId,
Expand Down Expand Up @@ -103,6 +104,8 @@ const fetchFeatureWithCenter = async (apiId: OsmApiId) => {
feature.center = center;
}

feature.countryCode = await resolveCountryCode(feature.center); // takes 0-100ms for first resolution, then instant

return addSchemaToFeature(feature);
};

Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface Feature {
osmappLabel?: string;
};
center: Position;
countryCode?: string; // ISO3166-1 code, undefined = no country
roundedCenter?: LonLatRounded;
ssrFeatureImage?: Image;
error?: 'network' | 'unknown' | '404' | '500'; // etc.
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5742,6 +5742,11 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

next-codegrid@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/next-codegrid/-/next-codegrid-1.0.2.tgz#e36a297fd6b6eaf4425eb8736d96157bc59c09fc"
integrity sha512-7gp+Q49ies8UNczepSv9taS9ZcganKJYkjjWDjd718sOjAsP7m2xL2QyrxsH7xlUKR5SDX1YYfcv7+eKs6Iolg==

next-cookies@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/next-cookies/-/next-cookies-2.0.3.tgz#5a3eabcb6afa9b4d4ade69dfaaad749d16cd4a9a"
Expand Down

0 comments on commit bda6186

Please sign in to comment.