Parcourir la source

Update bounds computation

Use D3's bounds computation per projection.
master
TheoryOfNekomata il y a 2 ans
Parent
révision
848a817436
12 fichiers modifiés avec 322 ajouts et 16 suppressions
  1. +1
    -0
      .gitignore
  2. BIN
      __fixtures__/gb.png
  3. BIN
      __fixtures__/jp.png
  4. BIN
      __fixtures__/mercator.png
  5. BIN
      __fixtures__/ph.png
  6. BIN
      __fixtures__/robinson.png
  7. BIN
      __fixtures__/ru.png
  8. BIN
      __fixtures__/sinusoidal.png
  9. BIN
      __fixtures__/us.png
  10. BIN
      __fixtures__/world.png
  11. +260
    -0
      assets/ne_10m_admin_0_countries.json
  12. +61
    -16
      src/index.ts

+ 1
- 0
.gitignore Voir le fichier

@@ -105,3 +105,4 @@ dist
.tern-port

.npmrc
assets/

BIN
__fixtures__/gb.png Voir le fichier

Avant Après
Largeur: 800  |  Hauteur: 406  |  Taille: 112 KiB

BIN
__fixtures__/jp.png Voir le fichier

Avant Après
Largeur: 800  |  Hauteur: 406  |  Taille: 108 KiB

BIN
__fixtures__/mercator.png Voir le fichier

Avant Après
Largeur: 461  |  Hauteur: 461  |  Taille: 54 KiB

BIN
__fixtures__/ph.png Voir le fichier

Avant Après
Largeur: 200  |  Hauteur: 320  |  Taille: 24 KiB Largeur: 800  |  Hauteur: 400  |  Taille: 98 KiB

BIN
__fixtures__/robinson.png Voir le fichier

Avant Après
Largeur: 461  |  Hauteur: 234  |  Taille: 54 KiB

BIN
__fixtures__/ru.png Voir le fichier

Avant Après
Largeur: 800  |  Hauteur: 406  |  Taille: 112 KiB

BIN
__fixtures__/sinusoidal.png Voir le fichier

Avant Après
Largeur: 461  |  Hauteur: 231  |  Taille: 46 KiB

BIN
__fixtures__/us.png Voir le fichier

Avant Après
Largeur: 800  |  Hauteur: 406  |  Taille: 112 KiB

BIN
__fixtures__/world.png Voir le fichier

Avant Après
Largeur: 4608  |  Hauteur: 4608  |  Taille: 7.1 MiB

+ 260
- 0
assets/ne_10m_admin_0_countries.json
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 61
- 16
src/index.ts Voir le fichier

@@ -1,6 +1,6 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { project, Bounds } from '@theoryofnekomata/orbis-core';
import { project, ProjectBounds } from '@theoryofnekomata/orbis-core';
import { writeFile } from 'fs/promises';
import { basename, dirname, resolve } from 'path';

@@ -8,10 +8,11 @@ type ProjectArgs = {
input: string,
projection: string,
output?: string,
bounds: Bounds,
bounds: ProjectBounds,
width?: number,
height?: number,
padding: [number, number],
country?: string,
};

const coerceNumber = (n?: string) => {
@@ -36,21 +37,62 @@ const coercePadding = (n?: string) => {
];
};

const coerceBounds = (n?: string): Bounds => {
const coerceBounds = (n?: string): ProjectBounds => {
if (typeof n !== 'string') {
return [
[-180, 90],
[180, -90],
] as Bounds;
return {
type: 'geojson',
value: {
type: 'Sphere',
},
};
}

return n
.split(';')
.map((p) => (
p
.split(',')
.map((c: string) => Number(c))
)) as Bounds;
const [boundsType, etcBounds] = n.split(':');

if (boundsType === 'geojson') {
const [geometryType, etcArgs] = etcBounds.split(';');

if (geometryType === 'Sphere') {
return {
type: boundsType,
value: {
type: geometryType,
},
};
}

if (geometryType === 'Polygon' || geometryType === 'MultiPolygon') {
return {
type: boundsType,
value: {
type: geometryType,
coordinates: JSON.parse(etcArgs),
},
};
}

return {
type: 'geojson',
value: {
type: 'Sphere',
},
};
}

if (boundsType === 'country') {
const [country] = etcBounds.split(';');
return {
type: boundsType,
value: country,
};
}

return {
type: 'geojson',
value: {
type: 'Sphere',
},
};
};

const main = async (argv: string | readonly string[]) => {
@@ -85,12 +127,15 @@ const main = async (argv: string | readonly string[]) => {
.coerce('height', coerceNumber)
.option('padding', {
alias: 'p',
default: [0, 0],
default: '0;0',
})
.coerce('padding', coercePadding)
.option('bounds', {
alias: 'b',
default: [[-180, 90], [180, -90]],
default: 'geojson:Sphere',
})
.option('country', {
alias: 'c',
})
.coerce('bounds', coerceBounds),
handler: async (projectArgvRaw) => {


Chargement…
Annuler
Enregistrer