@atlas-composer/preset-library
v2.7.0
Published
Curated collection of composite map projection presets for Atlas Composer
Maintainers
Readme
@atlas-composer/preset-library
Composite map presets of Atlas Composer.
This package publishes the presets of the Atlas Composer app, such as France with its overseas territories or the USA with Alaska and Hawaii, and a catalog that describes them. A composite-custom preset is a configuration of @atlas-composer/specification, which @atlas-composer/projection-loader turns into a d3 projection.
Installation
npm install @atlas-composer/preset-library @atlas-composer/projection-loader d3-geoUsage
import { getPreset } from '@atlas-composer/preset-library'
import { ProjectionLoader } from '@atlas-composer/projection-loader'
import { d3ProjectionFactories } from '@atlas-composer/projection-loader/helpers'
import * as d3 from 'd3-geo'
const loader = new ProjectionLoader()
loader.registerAll(d3ProjectionFactories)
const config = await getPreset('france-standard')
if (config) {
const projection = loader.load(config, { width: 800, height: 600 })
const path = d3.geoPath(projection)
}loader.load validates the configuration and throws a ConfigValidationError for a configuration that the format refuses. validateConfig of the loader returns { valid, errors, warnings } without throwing.
listPresets() returns the composite-custom presets, and listPresets({ includeViewModes: true }) returns every preset:
import { listPresets } from '@atlas-composer/preset-library'
for (const preset of listPresets({ atlasId: 'france' }))
console.log(preset.id, preset.name)Each preset file is also published by its path, @atlas-composer/preset-library/<atlas>/<identifier>:
import config from '@atlas-composer/preset-library/france/france-standard' with { type: 'json' }Catalog
catalog.presets has an entry for each preset, keyed by its identifier. An entry has:
id, the identifier of the preset, such asfrance-standard;nameanddescription, in English;atlasIdandregion, the identifier of the atlas, such asfrance;type:composite-custom,built-in-composite,splitorunified;tags:['default']for the default preset of the atlas,[]for the others.
catalog.version is the version of the package.
The built-in-composite, split and unified presets describe the views of the Atlas Composer app. getPreset loads a composite-custom preset, and returns undefined for the other types.
Atlases
The package serves the configuration of each atlas at @atlas-composer/preset-library/atlases/<atlas>, and its schema at @atlas-composer/preset-library/schemas/atlas.schema. An atlas configuration names the territories, their codes, bounds and centers, the rules that cut them out of Natural Earth, and the territory collections. dataSources names the files that the app loads.
buildTerritories(config, source) builds one GeoJSON feature per territory of an atlas. The example reads world-atlas with topojson-client, @types/topojson-client and @types/topojson-specification:
import type { Topology } from 'topojson-specification'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { buildTerritories, createNaturalEarthSource } from '@atlas-composer/preset-library'
import config from '@atlas-composer/preset-library/atlases/france' with { type: 'json' }
import { feature } from 'topojson-client'
const require = createRequire(import.meta.url)
const topology: Topology = JSON.parse(readFileSync(require.resolve('world-atlas/countries-50m.json'), 'utf8'))
const source = createNaturalEarthSource(feature(topology, topology.objects.countries), '50m')
const { collection } = buildTerritories(config, source)- A Natural Earth source goes through the extraction rules of the atlas. The polygon indices of these rules count the polygons of
countries-50m.jsonofworld-atlas2.0.2, and another version ofworld-atlascuts the territories at the wrong polygons. An atlas of every country, such asworld, reads any resolution, and the code of each territory isWD-<id>. - At another resolution, such as
10m,createNaturalEarthSource(features, '10m', features50m)takes the features ofcountries-50m.jsontoo, andbuildTerritoriesrefuses an atlas with rules without them. Each polygon of the source goes to the territory of the 50m polygon of the same id that contains its centroid or, without one, of the 50m polygon with the nearest vertex. A polygon farther than 50 km from it and outside the bounds of its territory, such as an islet that Natural Earth draws at 10m only, is left out of the geometry and listed inleftOutPolygons. - A source
{ kind: 'by-code', features }takes features that carry the code of a territory inproperties.code, such asFR-GF, and gathers them by code. - The rings of the features are oriented as d3-geo reads them, exterior rings clockwise.
rewindToRfc7946orients a planar geometry as RFC 7946 asks. buildTerritoriesthrows aTerritoryBuildErrorwhoseissuesname the missing or unknown codes, the indices out of range, the duplicated territories without source, the rings that cross the antimeridian, a source by code for an atlas of every country, and the refused resolution.
API
getPreset(id)- Load the configuration of acomposite-custompresetgetPresetMetadata(id)- Get the catalog entry of a presetgetPresetPath(id)- Get the path of the preset file, such asfrance/france-standard.jsongetAllPresets()- Get every catalog entrylistPresets(options)- Filter the presets byatlasId,type,regionandtags;includeViewModesadds thebuilt-in-composite,splitandunifiedpresetsgetPresetsForAtlas(atlasId)- List thecomposite-custompresets of an atlasgetDefaultPreset(atlasId)- Get thecomposite-custompreset taggeddefaultof an atlas, else its firstcomposite-custompresetlistCompositePresets()- List thecomposite-custompresetslistViewModePresets()- List thebuilt-in-composite,splitandunifiedpresetsbuildTerritories(config, source)- Build one feature per territory of an atlascreateNaturalEarthSource(features, resolution, ruleFeatures?)- Build a source from the features of a Natural Earth topology, with the features of the 50m topology for another resolutionRULES_RESOLUTION- The resolution whose polygons the indices of the extraction rules count,50mlistAtlases()- List the atlas identifiers, in alphabetical orderlistRegions()- List the atlas identifiers, in the order of the registry of the Atlas Composer app,configs/atlas-registry.jsonlistTypes()- List the preset typesisViewModeType(type)- Check if a type isbuilt-in-composite,splitorunified
License
MIT © ShallowRed
