-
Notifications
You must be signed in to change notification settings - Fork 42
fix(maps): remove New Zealand #105
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| import countriesAtlasJson from 'world-atlas/countries-110m.json' | ||
| import detailedCountriesAtlasJson from 'world-atlas/countries-50m.json' | ||
| import landAtlasJson from 'world-atlas/land-110m.json' | ||
| import detailedLandAtlasJson from 'world-atlas/land-50m.json' | ||
| import { geoGraticule, geoGraticule10 } from 'd3-geo' | ||
| import { | ||
| geoCentroid, | ||
| geoContains, | ||
| geoGraticule, | ||
| geoGraticule10, | ||
| } from 'd3-geo' | ||
| import { feature } from 'topojson-client' | ||
| import { simplifyPolygonGeometry } from './simplify-geo' | ||
| import type { | ||
|
|
@@ -13,6 +19,8 @@ import type { | |
|
|
||
| type AtlasTopology = Parameters<typeof feature>[0] | ||
|
|
||
| const excludedCountryName = 'New Zealand' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, the context of this variable's usage is self-explanatory enough. While this is only a small catch, I think that unless we plan on changing or extending excluded countries it may be better to just call it something like |
||
|
|
||
| export type CountryGeometry = Extract< | ||
| GeoGeometryObjects, | ||
| { type: 'Polygon' | 'MultiPolygon' } | ||
|
|
@@ -53,6 +61,8 @@ export const worldCountries: readonly CountryFeature[] = | |
| return [] | ||
| } | ||
|
|
||
| if (entry.properties.name === excludedCountryName) return [] | ||
|
|
||
| return [ | ||
| { | ||
| type: 'Feature', | ||
|
|
@@ -65,9 +75,9 @@ export const worldCountries: readonly CountryFeature[] = | |
| ] | ||
| }) | ||
|
|
||
| if (worldCountries.length !== 177) { | ||
| if (worldCountries.length !== 176) { | ||
| throw new TypeError( | ||
| `Expected 177 world-atlas countries, got ${worldCountries.length}`, | ||
| `Expected 176 world-atlas countries after excluding ${excludedCountryName}, got ${worldCountries.length}`, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -77,14 +87,19 @@ export const worldCountryCollection: ExtendedFeatureCollection<CountryFeature> = | |
| features: [...worldCountries], | ||
| } | ||
|
|
||
| export const worldLand = convertLand(landAtlasJson, 'world-atlas land-110m') | ||
| export const worldLand = convertLandWithoutExcludedCountry( | ||
| landAtlasJson, | ||
| countriesAtlasJson, | ||
| 'world-atlas 110m', | ||
| ) | ||
| export const previewWorldLand: LandFeature = { | ||
| ...worldLand, | ||
| geometry: simplifyPolygonGeometry(worldLand.geometry, 2), | ||
| } | ||
| export const detailedWorldLand = convertLand( | ||
| export const detailedWorldLand = convertLandWithoutExcludedCountry( | ||
| detailedLandAtlasJson, | ||
| 'world-atlas land-50m', | ||
| detailedCountriesAtlasJson, | ||
| 'world-atlas 50m', | ||
| ) | ||
|
|
||
| function atlasTopology(value: unknown, label: string): AtlasTopology { | ||
|
|
@@ -94,23 +109,62 @@ function atlasTopology(value: unknown, label: string): AtlasTopology { | |
| return value | ||
| } | ||
|
|
||
| function convertLand(value: unknown, label: string): LandFeature { | ||
| const topology = atlasTopology(value, label) | ||
| const landObject = topology.objects.land | ||
| function convertLandWithoutExcludedCountry( | ||
| landValue: unknown, | ||
| countriesValue: unknown, | ||
| label: string, | ||
| ): LandFeature { | ||
| const countriesTopology = atlasTopology(countriesValue, `${label} countries`) | ||
| const countriesObject = countriesTopology.objects.countries | ||
| if (!countriesObject) { | ||
| throw new TypeError(`${label} is missing countries`) | ||
| } | ||
|
|
||
| const convertedCountries = feature(countriesTopology, countriesObject) | ||
| if (convertedCountries.type !== 'FeatureCollection') { | ||
| throw new TypeError(`${label} countries did not produce a collection`) | ||
| } | ||
| const excludedCountry = convertedCountries.features.find( | ||
| (country) => | ||
| isRecord(country.properties) && | ||
| country.properties.name === excludedCountryName, | ||
| ) | ||
| if (!excludedCountry || !isCountryGeometry(excludedCountry.geometry)) { | ||
| throw new TypeError(`${label} did not contain ${excludedCountryName}`) | ||
| } | ||
|
|
||
| const landTopology = atlasTopology(landValue, `${label} land`) | ||
| const landObject = landTopology.objects.land | ||
| if (!landObject) { | ||
| throw new TypeError(`${label} is missing land`) | ||
| } | ||
|
|
||
| const converted = feature(topology, landObject) | ||
| const convertedLand = feature(landTopology, landObject) | ||
| const land = | ||
| converted.type === 'FeatureCollection' ? converted.features[0] : converted | ||
| if (!land || land.type !== 'Feature' || !isCountryGeometry(land.geometry)) { | ||
| throw new TypeError(`${label} did not produce polygon geometry`) | ||
| convertedLand.type === 'FeatureCollection' | ||
| ? convertedLand.features[0] | ||
| : convertedLand | ||
| if (!land || !isCountryGeometry(land.geometry)) { | ||
| throw new TypeError(`${label} did not produce polygon land geometry`) | ||
| } | ||
|
|
||
| const polygons = | ||
| land.geometry.type === 'MultiPolygon' | ||
| ? land.geometry.coordinates | ||
| : [land.geometry.coordinates] | ||
| const includedPolygons = polygons.filter((coordinates) => { | ||
| const polygon: CountryGeometry = { type: 'Polygon', coordinates } | ||
| return !geoContains(excludedCountry, geoCentroid(polygon)) | ||
| }) | ||
| if (includedPolygons.length === polygons.length) { | ||
| throw new TypeError(`${label} land did not contain ${excludedCountryName}`) | ||
| } | ||
|
|
||
| return { | ||
| type: 'Feature', | ||
| geometry: land.geometry, | ||
| geometry: { | ||
| type: 'MultiPolygon', | ||
| coordinates: includedPolygons, | ||
| }, | ||
| properties: {}, | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this is unnecessary. New Zealand shouldn't have been on the map in the first place. It's just a fix, no need to say that the bug is no longer present.