diff --git a/scripts/members-data.test.ts b/scripts/members-data.test.ts index f93189f..46f33dd 100644 --- a/scripts/members-data.test.ts +++ b/scripts/members-data.test.ts @@ -10,7 +10,7 @@ countries.registerLocale(en) const read = (p: string) => loadYaml(readFileSync(resolve(__dirname, '..', p), 'utf-8')) const ORG_CATEGORIES = ['founding', 'corporate', 'small', 'nonprofit', 'university'] -const COUNTRIES = ['United States', 'France', 'Norway', 'Japan', 'United Kingdom', 'Austria'] +const COUNTRIES = ['United States', 'France', 'Norway', 'Japan', 'United Kingdom', 'Austria', 'Hong Kong'] describe('members data', () => { const members = read('src/data/members.yaml') as any[] diff --git a/src/components/MembersGlobe.astro b/src/components/MembersGlobe.astro index 8d79410..08057af 100644 --- a/src/components/MembersGlobe.astro +++ b/src/components/MembersGlobe.astro @@ -32,13 +32,54 @@ const projection = geoOrthographic() ) const pathGen = geoPath(projection) +// Hong Kong has no polygon in Natural Earth 110m — it is part of the CN +// feature. Highlight the containing polygon alongside the member country. +const FEATURE_FALLBACKS: Record = { '344': '156' } const memberById = new Map(stats.map((s) => [s.id, s])) -const countryPaths = worldShapes.features.map((f) => { +// reverse: feature id -> stat for member countries without their own polygon +const memberByFeatureFallback = new Map( + Object.entries(FEATURE_FALLBACKS).map(([memberId, featureId]) => [featureId, memberById.get(memberId)]), +) + +// UN compliance: Natural Earth ships de-facto states without ISO 3166-1 codes +// (Somaliland, N. Cyprus, Kosovo). Fold their geometry into the UN member state +// they belong to, so they never appear as countries on the map. +const UN_INTO: Record = { + 'N. Cyprus': '196', // Cyprus + Somaliland: '706', // Somalia + Kosovo: '688', // Serbia (UNSCR 1244) +} +const unMerge = (features: Array>) => { + const byId = new Map>() + for (const f of features) { + if (f.id != null) byId.set(String(f.id).padStart(3, '0'), f) + } + const merged = new Map>() + for (const f of features) { + if (f.id != null) { + merged.set(String(f.id).padStart(3, '0'), f) + continue + } + const parentId = UN_INTO[(f.properties as { name?: string })?.name ?? ''] + const parent = parentId ? merged.get(parentId) : undefined + if (!parent) continue // unknown entity: excluded rather than shown as a country + appendGeometry(parent, f) + } + return [...merged.values()] +} +const appendGeometry = (parent: Record, child: Record) => { + const ringsOf = (g: Record) => + (g.type === 'MultiPolygon' ? g.coordinates : g.type === 'Polygon' ? [g.coordinates] : []) as unknown[][] + const coords = [...ringsOf(parent.geometry), ...ringsOf(child.geometry)] + parent.geometry = { type: 'MultiPolygon', coordinates: coords } +} +const displayFeatures = unMerge(worldShapes.features) +const countryPaths = displayFeatures.map((f) => { const id = String(f.id).padStart(3, '0') return { id, d: pathGen(f), - stat: memberById.get(id), + stat: memberById.get(id) ?? memberByFeatureFallback.get(id), } }) const graticuleD = pathGen(geoGraticule10()) @@ -61,7 +102,7 @@ const serializedRotate = JSON.stringify(INITIAL_ROTATE) label(s)).join(', ')}`} @@ -84,6 +125,15 @@ const serializedRotate = JSON.stringify(INITIAL_ROTATE) )) } +