@atlas-composer/projection-loader 1.0.0 → 1.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -1
- package/dist/d3-projection-helpers.d.ts +1 -1
- package/dist/d3-projection-helpers.js.map +1 -1
- package/dist/index.d.ts +28 -9
- package/dist/index.js +87 -19
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
> Zero-dependency standalone loader for composite map projections with plugin architecture
|
|
4
4
|
|
|
5
|
-
A lightweight, framework-agnostic library for loading composite map projections exported from [Atlas composer](https://github.com/ShallowRed/atlas-composer). Features a plugin architecture that lets you register only the projections you need
|
|
5
|
+
A lightweight, framework-agnostic library for loading composite map projections exported from [Atlas composer](https://github.com/ShallowRed/atlas-composer). Features a plugin architecture that lets you register only the projections you need.
|
|
6
|
+
|
|
7
|
+
**✨ NEW**: Now supports the updated preset format from Atlas composer 2.0+ with backward compatibility for legacy exports.
|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
@@ -86,6 +88,54 @@ const projection = loadCompositeProjection(config, { width: 800, height: 600 })
|
|
|
86
88
|
|
|
87
89
|
**Result**: ~6KB instead of ~100KB (94% reduction) 🎉
|
|
88
90
|
|
|
91
|
+
## Configuration Format Support
|
|
92
|
+
|
|
93
|
+
The loader supports multiple configuration formats for maximum compatibility:
|
|
94
|
+
|
|
95
|
+
### New Format (Atlas composer 2.0+)
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"version": "1.0",
|
|
99
|
+
"metadata": { "atlasId": "france", "atlasName": "France" },
|
|
100
|
+
"pattern": "single-focus",
|
|
101
|
+
"referenceScale": 2700,
|
|
102
|
+
"territories": [
|
|
103
|
+
{
|
|
104
|
+
"code": "FR-MET",
|
|
105
|
+
"projection": {
|
|
106
|
+
"id": "conic-conformal",
|
|
107
|
+
"family": "CONIC",
|
|
108
|
+
"parameters": {
|
|
109
|
+
"rotate": [-3, -46.2, 0],
|
|
110
|
+
"scaleMultiplier": 1
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"layout": { "translateOffset": [0, 0] }
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Legacy Format (Atlas composer 1.x)
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"version": "1.0",
|
|
123
|
+
"territories": [
|
|
124
|
+
{
|
|
125
|
+
"code": "FR-MET",
|
|
126
|
+
"projectionId": "conic-conformal",
|
|
127
|
+
"parameters": {
|
|
128
|
+
"scale": 2700,
|
|
129
|
+
"baseScale": 2700,
|
|
130
|
+
"scaleMultiplier": 1
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The loader automatically detects and handles both formats seamlessly.
|
|
138
|
+
|
|
89
139
|
## Observable Plot Integration
|
|
90
140
|
|
|
91
141
|
```typescript
|
|
@@ -47,7 +47,7 @@ declare const naturalEarth1: ProjectionFactory;
|
|
|
47
47
|
declare const equalEarth: ProjectionFactory;
|
|
48
48
|
/**
|
|
49
49
|
* Object containing all standard D3 projection factories
|
|
50
|
-
* Keyed by the projection ID used in Atlas
|
|
50
|
+
* Keyed by the projection ID used in Atlas composer configurations
|
|
51
51
|
*/
|
|
52
52
|
declare const d3ProjectionFactories: Record<string, ProjectionFactory>;
|
|
53
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/d3-projection-helpers.ts"],"names":[],"mappings":";;;;AAoCO,IAAM,kBAAA,GAAwC,MAAY,KAAA,CAAA,qBAAA;AAC1D,IAAM,oBAAA,GAA0C,MAAY,KAAA,CAAA,uBAAA;AAC5D,IAAM,QAAA,GAA8B,MAAY,KAAA,CAAA,WAAA;AAChD,IAAM,YAAA,G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EACb,qBAAA;AAAA,EACA,wBAAA;AAAA,EACA,yBAAA;AAAA;AAAA,EAGA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF","file":"d3-projection-helpers.js","sourcesContent":["/**\n * D3 Projection Helpers\n *\n * Optional companion file that provides ready-to-use D3 projection factory mappings.\n * This file has dependencies on d3-geo and d3-geo-projection, but the main loader does not.\n *\n * Users can import this to quickly register all standard D3 projections, or they can\n * selectively import only the projections they need for tree-shaking.\n *\n * @example\n * ```typescript\n * // Register all projections at once\n * import { registerProjections } from './standalone-projection-loader'\n * import { d3ProjectionFactories } from './d3-projection-helpers'\n *\n * registerProjections(d3ProjectionFactories)\n * ```\n *\n * @example\n * ```typescript\n * // Tree-shakeable: import only what you need\n * import { registerProjection } from './standalone-projection-loader'\n * import { mercator, albers } from './d3-projection-helpers'\n *\n * registerProjection('mercator', mercator)\n * registerProjection('albers', albers)\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { ProjectionFactory } from './standalone-projection-loader'\nimport * as d3Geo from 'd3-geo'\nimport * as d3GeoProjection from 'd3-geo-projection'\n\n// Azimuthal projections\nexport const azimuthalEqualArea: ProjectionFactory = () => d3Geo.geoAzimuthalEqualArea()\nexport const azimuthalEquidistant: ProjectionFactory = () => d3Geo.geoAzimuthalEquidistant()\nexport const gnomonic: ProjectionFactory = () => d3Geo.geoGnomonic()\nexport const orthographic: ProjectionFactory = () => d3Geo.geoOrthographic()\nexport const stereographic: ProjectionFactory = () => d3Geo.geoStereographic()\n\n// Conic projections\nexport const conicConformal: ProjectionFactory = () => d3Geo.geoConicConformal()\nexport const conicEqualArea: ProjectionFactory = () => d3Geo.geoConicEqualArea()\nexport const conicEquidistant: ProjectionFactory = () => d3Geo.geoConicEquidistant()\nexport const albers: ProjectionFactory = () => d3Geo.geoAlbers()\n\n// Cylindrical projections\nexport const mercator: ProjectionFactory = () => d3Geo.geoMercator()\nexport const transverseMercator: ProjectionFactory = () => d3Geo.geoTransverseMercator()\nexport const equirectangular: ProjectionFactory = () => d3Geo.geoEquirectangular()\nexport const naturalEarth1: ProjectionFactory = () => (d3GeoProjection as any).geoNaturalEarth1()\n\n// Other projections\nexport const equalEarth: ProjectionFactory = () => d3Geo.geoEqualEarth()\n\n/**\n * Object containing all standard D3 projection factories\n * Keyed by the projection ID used in Atlas
|
|
1
|
+
{"version":3,"sources":["../src/d3-projection-helpers.ts"],"names":[],"mappings":";;;;AAoCO,IAAM,kBAAA,GAAwC,MAAY,KAAA,CAAA,qBAAA;AAC1D,IAAM,oBAAA,GAA0C,MAAY,KAAA,CAAA,uBAAA;AAC5D,IAAM,QAAA,GAA8B,MAAY,KAAA,CAAA,WAAA;AAChD,IAAM,YAAA,GAAkC,MAAY,KAAA,CAAA,eAAA;AACpD,IAAM,aAAA,GAAmC,MAAY,KAAA,CAAA,gBAAA;AAGrD,IAAM,cAAA,GAAoC,MAAY,KAAA,CAAA,iBAAA;AACtD,IAAM,cAAA,GAAoC,MAAY,KAAA,CAAA,iBAAA;AACtD,IAAM,gBAAA,GAAsC,MAAY,KAAA,CAAA,mBAAA;AACxD,IAAM,MAAA,GAA4B,MAAY,KAAA,CAAA,SAAA;AAG9C,IAAM,QAAA,GAA8B,MAAY,KAAA,CAAA,WAAA;AAChD,IAAM,kBAAA,GAAwC,MAAY,KAAA,CAAA,qBAAA;AAC1D,IAAM,eAAA,GAAqC,MAAY,KAAA,CAAA,kBAAA;AACvD,IAAM,aAAA,GAAmC,MAA+B,eAAA,CAAA,gBAAA;AAGxE,IAAM,UAAA,GAAgC,MAAY,KAAA,CAAA,aAAA;AAMlD,IAAM,qBAAA,GAA2D;AAAA;AAAA,EAEtE,sBAAA,EAAwB,kBAAA;AAAA,EACxB,uBAAA,EAAyB,oBAAA;AAAA,EACzB,UAAA,EAAY,QAAA;AAAA,EACZ,cAAA,EAAgB,YAAA;AAAA,EAChB,eAAA,EAAiB,aAAA;AAAA;AAAA,EAGjB,iBAAA,EAAmB,cAAA;AAAA,EACnB,kBAAA,EAAoB,cAAA;AAAA,EACpB,mBAAA,EAAqB,gBAAA;AAAA,EACrB,QAAA,EAAU,MAAA;AAAA;AAAA,EAGV,UAAA,EAAY,QAAA;AAAA,EACZ,qBAAA,EAAuB,kBAAA;AAAA,EACvB,iBAAA,EAAmB,eAAA;AAAA,EACnB,iBAAA,EAAmB,aAAA;AAAA;AAAA,EAGnB,aAAA,EAAe;AACjB;AAeO,SAAS,yBACd,UAAA,EACM;AACN,EAAA,UAAA,CAAW,qBAAqB,CAAA;AAClC;AAKO,SAAS,yBAAA,GAAsC;AACpD,EAAA,OAAO,MAAA,CAAO,KAAK,qBAAqB,CAAA;AAC1C;AAGA,IAAO,6BAAA,GAAQ;AAAA,EACb,qBAAA;AAAA,EACA,wBAAA;AAAA,EACA,yBAAA;AAAA;AAAA,EAGA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF","file":"d3-projection-helpers.js","sourcesContent":["/**\n * D3 Projection Helpers\n *\n * Optional companion file that provides ready-to-use D3 projection factory mappings.\n * This file has dependencies on d3-geo and d3-geo-projection, but the main loader does not.\n *\n * Users can import this to quickly register all standard D3 projections, or they can\n * selectively import only the projections they need for tree-shaking.\n *\n * @example\n * ```typescript\n * // Register all projections at once\n * import { registerProjections } from './standalone-projection-loader'\n * import { d3ProjectionFactories } from './d3-projection-helpers'\n *\n * registerProjections(d3ProjectionFactories)\n * ```\n *\n * @example\n * ```typescript\n * // Tree-shakeable: import only what you need\n * import { registerProjection } from './standalone-projection-loader'\n * import { mercator, albers } from './d3-projection-helpers'\n *\n * registerProjection('mercator', mercator)\n * registerProjection('albers', albers)\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { ProjectionFactory } from './standalone-projection-loader'\nimport * as d3Geo from 'd3-geo'\nimport * as d3GeoProjection from 'd3-geo-projection'\n\n// Azimuthal projections\nexport const azimuthalEqualArea: ProjectionFactory = () => d3Geo.geoAzimuthalEqualArea()\nexport const azimuthalEquidistant: ProjectionFactory = () => d3Geo.geoAzimuthalEquidistant()\nexport const gnomonic: ProjectionFactory = () => d3Geo.geoGnomonic()\nexport const orthographic: ProjectionFactory = () => d3Geo.geoOrthographic()\nexport const stereographic: ProjectionFactory = () => d3Geo.geoStereographic()\n\n// Conic projections\nexport const conicConformal: ProjectionFactory = () => d3Geo.geoConicConformal()\nexport const conicEqualArea: ProjectionFactory = () => d3Geo.geoConicEqualArea()\nexport const conicEquidistant: ProjectionFactory = () => d3Geo.geoConicEquidistant()\nexport const albers: ProjectionFactory = () => d3Geo.geoAlbers()\n\n// Cylindrical projections\nexport const mercator: ProjectionFactory = () => d3Geo.geoMercator()\nexport const transverseMercator: ProjectionFactory = () => d3Geo.geoTransverseMercator()\nexport const equirectangular: ProjectionFactory = () => d3Geo.geoEquirectangular()\nexport const naturalEarth1: ProjectionFactory = () => (d3GeoProjection as any).geoNaturalEarth1()\n\n// Other projections\nexport const equalEarth: ProjectionFactory = () => d3Geo.geoEqualEarth()\n\n/**\n * Object containing all standard D3 projection factories\n * Keyed by the projection ID used in Atlas composer configurations\n */\nexport const d3ProjectionFactories: Record<string, ProjectionFactory> = {\n // Azimuthal\n 'azimuthal-equal-area': azimuthalEqualArea,\n 'azimuthal-equidistant': azimuthalEquidistant,\n 'gnomonic': gnomonic,\n 'orthographic': orthographic,\n 'stereographic': stereographic,\n\n // Conic\n 'conic-conformal': conicConformal,\n 'conic-equal-area': conicEqualArea,\n 'conic-equidistant': conicEquidistant,\n 'albers': albers,\n\n // Cylindrical\n 'mercator': mercator,\n 'transverse-mercator': transverseMercator,\n 'equirectangular': equirectangular,\n 'natural-earth-1': naturalEarth1,\n\n // Other\n 'equal-earth': equalEarth,\n}\n\n/**\n * Convenience function to register all D3 projections at once\n *\n * @example\n * ```typescript\n * import { registerProjections } from './standalone-projection-loader'\n * import { registerAllD3Projections } from './d3-projection-helpers'\n *\n * registerAllD3Projections(registerProjections)\n * ```\n *\n * @param registerFn - The registerProjections function from the loader\n */\nexport function registerAllD3Projections(\n registerFn: (factories: Record<string, ProjectionFactory>) => void,\n): void {\n registerFn(d3ProjectionFactories)\n}\n\n/**\n * Get list of available D3 projection IDs\n */\nexport function getAvailableD3Projections(): string[] {\n return Object.keys(d3ProjectionFactories)\n}\n\n// Default export\nexport default {\n d3ProjectionFactories,\n registerAllD3Projections,\n getAvailableD3Projections,\n\n // Individual projections for tree-shaking\n azimuthalEqualArea,\n azimuthalEquidistant,\n gnomonic,\n orthographic,\n stereographic,\n conicConformal,\n conicEqualArea,\n conicEquidistant,\n albers,\n mercator,\n transverseMercator,\n equirectangular,\n naturalEarth1,\n equalEarth,\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,10 @@ interface ProjectionLike {
|
|
|
55
55
|
(): [[number, number], [number, number]] | null;
|
|
56
56
|
(extent: [[number, number], [number, number]] | null): ProjectionLike;
|
|
57
57
|
};
|
|
58
|
+
clipAngle?: {
|
|
59
|
+
(): number;
|
|
60
|
+
(angle: number): ProjectionLike;
|
|
61
|
+
};
|
|
58
62
|
stream?: (stream: StreamLike) => StreamLike;
|
|
59
63
|
precision?: {
|
|
60
64
|
(): number;
|
|
@@ -88,32 +92,47 @@ interface ExportedConfig {
|
|
|
88
92
|
metadata: {
|
|
89
93
|
atlasId: string;
|
|
90
94
|
atlasName: string;
|
|
95
|
+
exportDate?: string;
|
|
96
|
+
createdWith?: string;
|
|
97
|
+
notes?: string;
|
|
91
98
|
};
|
|
92
99
|
pattern: string;
|
|
93
|
-
referenceScale
|
|
100
|
+
referenceScale?: number;
|
|
101
|
+
canvasDimensions?: {
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
};
|
|
94
105
|
territories: Territory[];
|
|
95
106
|
}
|
|
96
107
|
interface Territory {
|
|
97
108
|
code: string;
|
|
98
109
|
name: string;
|
|
99
110
|
role: string;
|
|
100
|
-
projectionId
|
|
101
|
-
projectionFamily
|
|
102
|
-
|
|
111
|
+
projectionId?: string;
|
|
112
|
+
projectionFamily?: string;
|
|
113
|
+
projection?: {
|
|
114
|
+
id: string;
|
|
115
|
+
family: string;
|
|
116
|
+
parameters: ProjectionParameters;
|
|
117
|
+
};
|
|
118
|
+
parameters?: ProjectionParameters;
|
|
103
119
|
layout: Layout;
|
|
104
120
|
bounds: [[number, number], [number, number]];
|
|
105
121
|
}
|
|
106
122
|
interface ProjectionParameters {
|
|
107
123
|
center?: [number, number];
|
|
108
124
|
rotate?: [number, number, number];
|
|
109
|
-
scale
|
|
110
|
-
baseScale
|
|
111
|
-
scaleMultiplier
|
|
125
|
+
scale?: number;
|
|
126
|
+
baseScale?: number;
|
|
127
|
+
scaleMultiplier?: number;
|
|
112
128
|
parallels?: [number, number];
|
|
129
|
+
translate?: [number, number];
|
|
130
|
+
clipAngle?: number;
|
|
131
|
+
precision?: number;
|
|
113
132
|
}
|
|
114
133
|
interface Layout {
|
|
115
|
-
translateOffset
|
|
116
|
-
clipExtent
|
|
134
|
+
translateOffset?: [number, number];
|
|
135
|
+
clipExtent?: [[number, number], [number, number]] | null;
|
|
117
136
|
}
|
|
118
137
|
/**
|
|
119
138
|
* Options for creating the composite projection
|
package/dist/index.js
CHANGED
|
@@ -29,17 +29,29 @@ function createProjectionWrapper(project) {
|
|
|
29
29
|
return null;
|
|
30
30
|
return [point[0] * _scale + _translate[0], point[1] * _scale + _translate[1]];
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
Object.defineProperty(projection, "scale", {
|
|
33
|
+
value(...args) {
|
|
34
|
+
if (args.length > 0) {
|
|
35
|
+
_scale = args[0];
|
|
36
|
+
return projection;
|
|
37
|
+
}
|
|
34
38
|
return _scale;
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
},
|
|
40
|
+
writable: true,
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true
|
|
37
43
|
});
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
Object.defineProperty(projection, "translate", {
|
|
45
|
+
value(...args) {
|
|
46
|
+
if (args.length > 0) {
|
|
47
|
+
_translate = args[0];
|
|
48
|
+
return projection;
|
|
49
|
+
}
|
|
40
50
|
return _translate;
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
},
|
|
52
|
+
writable: true,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true
|
|
43
55
|
});
|
|
44
56
|
return projection;
|
|
45
57
|
}
|
|
@@ -52,7 +64,7 @@ function loadCompositeProjection(config, options) {
|
|
|
52
64
|
throw new Error("Configuration must contain at least one territory");
|
|
53
65
|
}
|
|
54
66
|
const subProjections = config.territories.map((territory) => {
|
|
55
|
-
const proj = createSubProjection(territory, width, height);
|
|
67
|
+
const proj = createSubProjection(territory, width, height, config.referenceScale);
|
|
56
68
|
return {
|
|
57
69
|
territory,
|
|
58
70
|
projection: proj,
|
|
@@ -162,8 +174,36 @@ function loadCompositeProjection(config, options) {
|
|
|
162
174
|
}
|
|
163
175
|
return compositeProjection;
|
|
164
176
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
177
|
+
function inferProjectionIdFromFamily(family, parameters) {
|
|
178
|
+
switch (family.toUpperCase()) {
|
|
179
|
+
case "CYLINDRICAL":
|
|
180
|
+
return "mercator";
|
|
181
|
+
// Most common cylindrical projection
|
|
182
|
+
case "CONIC":
|
|
183
|
+
return parameters.parallels ? "conic-conformal" : "conic-equal-area";
|
|
184
|
+
case "AZIMUTHAL":
|
|
185
|
+
return "azimuthal-equal-area";
|
|
186
|
+
default:
|
|
187
|
+
console.warn(`Unknown projection family: ${family}, falling back to mercator`);
|
|
188
|
+
return "mercator";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function createSubProjection(territory, width, height, referenceScale) {
|
|
192
|
+
let projectionId;
|
|
193
|
+
let parameters;
|
|
194
|
+
const { layout } = territory;
|
|
195
|
+
if (territory.projection) {
|
|
196
|
+
projectionId = territory.projection.id;
|
|
197
|
+
parameters = territory.projection.parameters;
|
|
198
|
+
} else if (territory.projectionId && territory.parameters) {
|
|
199
|
+
projectionId = territory.projectionId;
|
|
200
|
+
parameters = territory.parameters;
|
|
201
|
+
} else if (territory.projectionFamily && territory.parameters) {
|
|
202
|
+
projectionId = inferProjectionIdFromFamily(territory.projectionFamily, territory.parameters);
|
|
203
|
+
parameters = territory.parameters;
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(`Territory ${territory.code} missing projection configuration`);
|
|
206
|
+
}
|
|
167
207
|
const factory = projectionRegistry.get(projectionId);
|
|
168
208
|
if (!factory) {
|
|
169
209
|
const registered = getRegisteredProjections();
|
|
@@ -177,21 +217,43 @@ function createSubProjection(territory, width, height) {
|
|
|
177
217
|
projection.center(parameters.center);
|
|
178
218
|
}
|
|
179
219
|
if (parameters.rotate && projection.rotate) {
|
|
180
|
-
|
|
220
|
+
const rotate = Array.isArray(parameters.rotate) ? [...parameters.rotate, 0, 0].slice(0, 3) : [0, 0, 0];
|
|
221
|
+
projection.rotate(rotate);
|
|
181
222
|
}
|
|
182
223
|
if (parameters.parallels && projection.parallels) {
|
|
183
|
-
|
|
224
|
+
const parallels = Array.isArray(parameters.parallels) ? [...parameters.parallels, 0].slice(0, 2) : [0, 60];
|
|
225
|
+
projection.parallels(parallels);
|
|
184
226
|
}
|
|
185
227
|
if (projection.scale) {
|
|
186
|
-
|
|
228
|
+
if (parameters.scale) {
|
|
229
|
+
projection.scale(parameters.scale);
|
|
230
|
+
} else if (parameters.scaleMultiplier) {
|
|
231
|
+
const effectiveReferenceScale = referenceScale || 2700;
|
|
232
|
+
const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier;
|
|
233
|
+
projection.scale(calculatedScale);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (parameters.clipAngle && projection.clipAngle) {
|
|
237
|
+
projection.clipAngle(parameters.clipAngle);
|
|
238
|
+
}
|
|
239
|
+
if (parameters.precision && projection.precision) {
|
|
240
|
+
projection.precision(parameters.precision);
|
|
187
241
|
}
|
|
188
242
|
if (projection.translate) {
|
|
189
|
-
const [offsetX, offsetY] = layout.translateOffset;
|
|
243
|
+
const [offsetX, offsetY] = layout.translateOffset || [0, 0];
|
|
190
244
|
projection.translate([
|
|
191
245
|
width / 2 + offsetX,
|
|
192
246
|
height / 2 + offsetY
|
|
193
247
|
]);
|
|
194
248
|
}
|
|
249
|
+
if (parameters.translate && projection.translate) {
|
|
250
|
+
const currentTranslate = projection.translate();
|
|
251
|
+
const [additionalX, additionalY] = parameters.translate;
|
|
252
|
+
projection.translate([
|
|
253
|
+
currentTranslate[0] + additionalX,
|
|
254
|
+
currentTranslate[1] + additionalY
|
|
255
|
+
]);
|
|
256
|
+
}
|
|
195
257
|
if (layout.clipExtent && projection.clipExtent) {
|
|
196
258
|
projection.clipExtent(layout.clipExtent);
|
|
197
259
|
}
|
|
@@ -214,11 +276,17 @@ function validateConfig(config) {
|
|
|
214
276
|
throw new Error("Configuration must have at least one territory");
|
|
215
277
|
}
|
|
216
278
|
for (const territory of config.territories) {
|
|
217
|
-
if (!territory.code
|
|
218
|
-
throw new Error(`Territory missing required
|
|
279
|
+
if (!territory.code) {
|
|
280
|
+
throw new Error(`Territory missing required field 'code': ${JSON.stringify(territory)}`);
|
|
281
|
+
}
|
|
282
|
+
const hasLegacyFormat = territory.projectionId && territory.parameters;
|
|
283
|
+
const hasNewFormat = territory.projection && territory.projection.id && territory.projection.parameters;
|
|
284
|
+
const hasIncompleteFormat = territory.projectionFamily && territory.parameters;
|
|
285
|
+
if (!hasLegacyFormat && !hasNewFormat && !hasIncompleteFormat) {
|
|
286
|
+
throw new Error(`Territory ${territory.code} missing projection configuration. Available fields: ${Object.keys(territory).join(", ")}`);
|
|
219
287
|
}
|
|
220
|
-
if (!territory.
|
|
221
|
-
throw new Error(`Territory ${territory.code} missing
|
|
288
|
+
if (!territory.bounds) {
|
|
289
|
+
throw new Error(`Territory ${territory.code} missing bounds`);
|
|
222
290
|
}
|
|
223
291
|
}
|
|
224
292
|
return true;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/standalone-projection-loader.ts"],"names":[],"mappings":";AA+IA,IAAM,kBAAA,uBAAyB,GAAA,EAA+B;AAiBvD,SAAS,kBAAA,CAAmB,IAAY,OAAA,EAAkC;AAC/E,EAAA,kBAAA,CAAmB,GAAA,CAAI,IAAI,OAAO,CAAA;AACpC;AAmBO,SAAS,oBAAoB,SAAA,EAAoD;AACtF,EAAA,KAAA,MAAW,CAAC,EAAA,EAAI,OAAO,KAAK,MAAA,CAAO,OAAA,CAAQ,SAAS,CAAA,EAAG;AACrD,IAAA,kBAAA,CAAmB,IAAI,OAAO,CAAA;AAAA,EAChC;AACF;AAQO,SAAS,qBAAqB,EAAA,EAAqB;AACxD,EAAA,OAAO,kBAAA,CAAmB,OAAO,EAAE,CAAA;AACrC;AAKO,SAAS,gBAAA,GAAyB;AACvC,EAAA,kBAAA,CAAmB,KAAA,EAAM;AAC3B;AAOO,SAAS,wBAAA,GAAqC;AACnD,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,kBAAA,CAAmB,IAAA,EAAM,CAAA;AAC7C;AAQO,SAAS,uBAAuB,EAAA,EAAqB;AAC1D,EAAA,OAAO,kBAAA,CAAmB,IAAI,EAAE,CAAA;AAClC;AAMA,SAAS,wBACP,OAAA,EACgB;AAChB,EAAA,IAAI,MAAA,GAAS,GAAA;AACb,EAAA,IAAI,UAAA,GAA+B,CAAC,GAA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CAAA;AAAA,IAC5E;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT;AAkBO,SAAS,YAAA,CACd,YACA,OAAA,EACgB;AAChB,EAAA,IAAI,MAAA;AAEJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAA,CAAK,MAAM,UAAU,CAAA;AAAA,EAChC,SACO,KAAA,EAAO;AACZ,IAAA,MAAM,IAAI,MAAM,CAAA,cAAA,EAAiB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAe,CAAA,CAAE,CAAA;AAAA,EAC7F;AAEA,EAAA,cAAA,CAAe,MAAM,CAAA;AACrB,EAAA,OAAO,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAChD","file":"index.js","sourcesContent":["/**\n * Standalone Composite Projection Loader (Zero Dependencies)\n *\n * A pure JavaScript/TypeScript module that consumes exported composite projection\n * configurations and creates D3-compatible projections using a plugin architecture.\n *\n * This package has ZERO dependencies. Users must register projection factories\n * before loading configurations.\n *\n * @example\n * ```typescript\n * // Register projections first\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from './standalone-projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Then load your configuration\n * const projection = loadCompositeProjection(config, { width: 800, height: 600 })\n * ```\n *\n * @packageDocumentation\n */\n\n/**\n * Generic projection-like interface that matches D3 projections\n * without requiring d3-geo as a dependency\n *\n * Note: D3 projections use getter/setter pattern where calling without\n * arguments returns the current value, and with arguments sets and returns this.\n */\nexport interface ProjectionLike {\n (coordinates: [number, number]): [number, number] | null\n center?: {\n (): [number, number]\n (center: [number, number]): ProjectionLike\n }\n rotate?: {\n (): [number, number, number]\n (angles: [number, number, number]): ProjectionLike\n }\n parallels?: {\n (): [number, number]\n (parallels: [number, number]): ProjectionLike\n }\n scale?: {\n (): number\n (scale: number): ProjectionLike\n }\n translate?: {\n (): [number, number]\n (translate: [number, number]): ProjectionLike\n }\n clipExtent?: {\n (): [[number, number], [number, number]] | null\n (extent: [[number, number], [number, number]] | null): ProjectionLike\n }\n stream?: (stream: StreamLike) => StreamLike\n precision?: {\n (): number\n (precision: number): ProjectionLike\n }\n fitExtent?: (extent: [[number, number], [number, number]], object: any) => ProjectionLike\n fitSize?: (size: [number, number], object: any) => ProjectionLike\n fitWidth?: (width: number, object: any) => ProjectionLike\n fitHeight?: (height: number, object: any) => ProjectionLike\n}\n\n/**\n * Stream protocol interface for D3 geographic transforms\n */\nexport interface StreamLike {\n point: (x: number, y: number) => void\n lineStart: () => void\n lineEnd: () => void\n polygonStart: () => void\n polygonEnd: () => void\n sphere?: () => void\n}\n\n/**\n * Factory function that creates a projection instance\n */\nexport type ProjectionFactory = () => ProjectionLike\n\n/**\n * Exported configuration format (subset needed for loading)\n */\nexport interface ExportedConfig {\n version: string\n metadata: {\n atlasId: string\n atlasName: string\n }\n pattern: string\n referenceScale: number\n territories: Territory[]\n}\n\nexport interface Territory {\n code: string\n name: string\n role: string\n projectionId: string\n projectionFamily: string\n parameters: ProjectionParameters\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n scale: number\n baseScale: number\n scaleMultiplier: number\n parallels?: [number, number]\n}\n\nexport interface Layout {\n translateOffset: [number, number]\n clipExtent: [[number, number], [number, number]] | null\n}\n\n/**\n * Options for creating the composite projection\n */\nexport interface LoaderOptions {\n /** Canvas width in pixels */\n width: number\n /** Canvas height in pixels */\n height: number\n /** Whether to apply clipping to territories (default: true) */\n enableClipping?: boolean\n /** Debug mode - logs territory selection (default: false) */\n debug?: boolean\n}\n\n/**\n * Runtime registry for projection factories\n * Users must register projections before loading configurations\n */\nconst projectionRegistry = new Map<string, ProjectionFactory>()\n\n/**\n * Register a projection factory with a given ID\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection } from '@atlas-composer/projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n * ```\n *\n * @param id - Projection identifier (e.g., 'mercator', 'albers')\n * @param factory - Function that creates a new projection instance\n */\nexport function registerProjection(id: string, factory: ProjectionFactory): void {\n projectionRegistry.set(id, factory)\n}\n\n/**\n * Register multiple projections at once\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjections } from '@atlas-composer/projection-loader'\n *\n * registerProjections({\n * 'mercator': () => d3.geoMercator(),\n * 'albers': () => d3.geoAlbers(),\n * 'conic-equal-area': () => d3.geoConicEqualArea()\n * })\n * ```\n *\n * @param factories - Object mapping projection IDs to factory functions\n */\nexport function registerProjections(factories: Record<string, ProjectionFactory>): void {\n for (const [id, factory] of Object.entries(factories)) {\n registerProjection(id, factory)\n }\n}\n\n/**\n * Unregister a projection\n *\n * @param id - Projection identifier to remove\n * @returns True if the projection was removed, false if it wasn't registered\n */\nexport function unregisterProjection(id: string): boolean {\n return projectionRegistry.delete(id)\n}\n\n/**\n * Clear all registered projections\n */\nexport function clearProjections(): void {\n projectionRegistry.clear()\n}\n\n/**\n * Get list of currently registered projection IDs\n *\n * @returns Array of registered projection identifiers\n */\nexport function getRegisteredProjections(): string[] {\n return Array.from(projectionRegistry.keys())\n}\n\n/**\n * Check if a projection is registered\n *\n * @param id - Projection identifier to check\n * @returns True if the projection is registered\n */\nexport function isProjectionRegistered(id: string): boolean {\n return projectionRegistry.has(id)\n}\n\n/**\n * Create a minimal projection wrapper (similar to d3.geoProjection)\n * This allows us to avoid the d3-geo dependency\n */\nfunction createProjectionWrapper(\n project: (lambda: number, phi: number) => [number, number] | null,\n): ProjectionLike {\n let _scale = 150\n let _translate: [number, number] = [480, 250]\n\n const projection = function (coordinates: [number, number]): [number, number] | null {\n const point = project(coordinates[0] * Math.PI / 180, coordinates[1] * Math.PI / 180)\n if (!point)\n return null\n return [point[0] * _scale + _translate[0], point[1] * _scale + _translate[1]]\n } as ProjectionLike\n\n // D3-style getter/setter for scale\n projection.scale = ((s?: number): any => {\n if (arguments.length === 0)\n return _scale\n _scale = s!\n return projection\n }) as any\n\n // D3-style getter/setter for translate\n projection.translate = ((t?: [number, number]): any => {\n if (arguments.length === 0)\n return _translate\n _translate = t!\n return projection\n }) as any\n\n return projection\n}\n\n/**\n * Create a D3-compatible projection from an exported composite projection configuration\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Load configuration\n * const config = JSON.parse(jsonString)\n *\n * // Create projection\n * const projection = loadCompositeProjection(config, {\n * width: 800,\n * height: 600\n * })\n *\n * // Use with D3\n * const path = d3.geoPath(projection)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n *\n * @param config - Exported composite projection configuration\n * @param options - Canvas dimensions and options\n * @returns D3-compatible projection that routes geometry to appropriate sub-projections\n */\nexport function loadCompositeProjection(\n config: ExportedConfig,\n options: LoaderOptions,\n): ProjectionLike {\n const { width, height, debug = false } = options\n\n // Validate configuration version\n if (config.version !== '1.0') {\n throw new Error(`Unsupported configuration version: ${config.version}`)\n }\n\n if (!config.territories || config.territories.length === 0) {\n throw new Error('Configuration must contain at least one territory')\n }\n\n // Create sub-projections for each territory\n const subProjections = config.territories.map((territory) => {\n const proj = createSubProjection(territory, width, height)\n\n return {\n territory,\n projection: proj,\n bounds: territory.bounds,\n }\n })\n\n if (debug) {\n console.log('[CompositeProjection] Created sub-projections:', {\n territories: config.territories.map(t => ({ code: t.code, name: t.name })),\n count: subProjections.length,\n })\n }\n\n // Create composite projection using custom stream multiplexing\n const compositeProjection = createProjectionWrapper((lambda: number, phi: number) => {\n // Convert radians to degrees for bounds checking\n const lon = (lambda * 180) / Math.PI\n const lat = (phi * 180) / Math.PI\n\n // Find which territory this point belongs to\n let selectedProj = null\n for (const { projection, bounds } of subProjections) {\n if (\n lon >= bounds[0][0] && lon <= bounds[1][0]\n && lat >= bounds[0][1] && lat <= bounds[1][1]\n ) {\n selectedProj = projection\n break\n }\n }\n\n // If no territory matched, use first projection (fallback)\n if (!selectedProj && subProjections[0]) {\n selectedProj = subProjections[0].projection\n }\n\n // Project the point (should always have a projection by this point)\n return selectedProj!([lambda, phi])\n })\n\n // Implement stream multiplexing for proper geometry routing\n compositeProjection.stream = function (stream: StreamLike): StreamLike {\n let activeStream: StreamLike | null = null\n let bufferedPoints: Array<[number, number]> = []\n let activeTerritoryCode = ''\n\n return {\n point(lon: number, lat: number) {\n // Buffer points until we can determine which territory they belong to\n bufferedPoints.push([lon, lat])\n\n // If we have an active stream, forward the point\n if (activeStream) {\n const lonDeg = (lon * 180) / Math.PI\n const latDeg = (lat * 180) / Math.PI\n\n if (debug) {\n console.log(`[Stream] Point: [${lonDeg.toFixed(2)}, ${latDeg.toFixed(2)}] → ${activeTerritoryCode}`)\n }\n\n activeStream.point(lon, lat)\n }\n },\n\n lineStart() {\n // Determine which territory this line belongs to\n if (bufferedPoints.length > 0 && bufferedPoints[0]) {\n const [lon, lat] = bufferedPoints[0]\n const lonDeg = (lon * 180) / Math.PI\n const latDeg = (lat * 180) / Math.PI\n\n // Find matching territory\n for (const { territory, projection, bounds } of subProjections) {\n if (\n lonDeg >= bounds[0][0] && lonDeg <= bounds[1][0]\n && latDeg >= bounds[0][1] && latDeg <= bounds[1][1]\n ) {\n // Use the projection's stream if available\n if (projection.stream) {\n activeStream = projection.stream(stream)\n activeTerritoryCode = territory.code\n }\n\n if (debug) {\n console.log(`[Stream] Line started in territory: ${territory.code}`)\n }\n break\n }\n }\n\n // Fallback to first projection\n if (!activeStream && subProjections[0]) {\n const firstProj = subProjections[0].projection\n if (firstProj.stream) {\n activeStream = firstProj.stream(stream)\n activeTerritoryCode = subProjections[0].territory.code\n }\n\n if (debug) {\n console.log(`[Stream] Line started (fallback): ${activeTerritoryCode}`)\n }\n }\n }\n\n if (activeStream) {\n activeStream.lineStart()\n\n // Replay buffered points\n for (const [lon, lat] of bufferedPoints) {\n activeStream.point(lon, lat)\n }\n }\n\n bufferedPoints = []\n },\n\n lineEnd() {\n if (activeStream) {\n activeStream.lineEnd()\n }\n },\n\n polygonStart() {\n bufferedPoints = []\n activeStream = null\n },\n\n polygonEnd() {\n if (activeStream) {\n activeStream.polygonEnd()\n }\n activeStream = null\n },\n\n sphere() {\n // Not supported in composite projections\n if (debug) {\n console.warn('[Stream] sphere() called - not supported in composite projections')\n }\n },\n }\n }\n\n // Set reasonable defaults for the composite projection\n // Note: Individual territories handle their own scale/translate\n if (compositeProjection.scale) {\n compositeProjection.scale(1)\n }\n if (compositeProjection.translate) {\n compositeProjection.translate([width / 2, height / 2])\n }\n\n return compositeProjection\n}\n\n/**\n * Create a sub-projection for a single territory\n */\nfunction createSubProjection(\n territory: Territory,\n width: number,\n height: number,\n): ProjectionLike {\n const { projectionId, parameters, layout } = territory\n\n // Get projection factory from registry\n const factory = projectionRegistry.get(projectionId)\n if (!factory) {\n const registered = getRegisteredProjections()\n const availableList = registered.length > 0 ? registered.join(', ') : 'none'\n throw new Error(\n `Projection \"${projectionId}\" is not registered. `\n + `Available projections: ${availableList}. `\n + `Use registerProjection('${projectionId}', factory) to register it.`,\n )\n }\n\n // Create projection instance\n const projection = factory()\n\n // Apply parameters\n if (parameters.center && projection.center) {\n projection.center(parameters.center)\n }\n\n if (parameters.rotate && projection.rotate) {\n projection.rotate(parameters.rotate)\n }\n\n if (parameters.parallels && projection.parallels) {\n projection.parallels(parameters.parallels)\n }\n\n if (projection.scale) {\n projection.scale(parameters.scale)\n }\n\n // Apply layout translate\n if (projection.translate) {\n const [offsetX, offsetY] = layout.translateOffset\n projection.translate([\n width / 2 + offsetX,\n height / 2 + offsetY,\n ])\n }\n\n // Apply clipping if specified\n if (layout.clipExtent && projection.clipExtent) {\n projection.clipExtent(layout.clipExtent)\n }\n\n return projection\n}\n\n/**\n * Validate an exported configuration\n *\n * @param config - Configuration to validate\n * @returns True if valid, throws error otherwise\n */\nexport function validateConfig(config: any): config is ExportedConfig {\n if (!config || typeof config !== 'object') {\n throw new Error('Configuration must be an object')\n }\n\n if (!config.version) {\n throw new Error('Configuration must have a version field')\n }\n\n if (!config.metadata || !config.metadata.atlasId) {\n throw new Error('Configuration must have metadata with atlasId')\n }\n\n if (!config.territories || !Array.isArray(config.territories)) {\n throw new Error('Configuration must have territories array')\n }\n\n if (config.territories.length === 0) {\n throw new Error('Configuration must have at least one territory')\n }\n\n // Validate each territory\n for (const territory of config.territories) {\n if (!territory.code || !territory.projectionId) {\n throw new Error(`Territory missing required fields: ${JSON.stringify(territory)}`)\n }\n\n if (!territory.parameters || !territory.bounds) {\n throw new Error(`Territory ${territory.code} missing parameters or bounds`)\n }\n }\n\n return true\n}\n\n/**\n * Load composite projection from JSON string\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadFromJSON } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n *\n * // Load from JSON\n * const jsonString = fs.readFileSync('france-composite.json', 'utf-8')\n * const projection = loadFromJSON(jsonString, { width: 800, height: 600 })\n * ```\n */\nexport function loadFromJSON(\n jsonString: string,\n options: LoaderOptions,\n): ProjectionLike {\n let config: any\n\n try {\n config = JSON.parse(jsonString)\n }\n catch (error) {\n throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`)\n }\n\n validateConfig(config)\n return loadCompositeProjection(config, options)\n}\n\n// Default export\nexport default {\n // Core loading functions\n loadCompositeProjection,\n loadFromJSON,\n validateConfig,\n\n // Registry management\n registerProjection,\n registerProjections,\n unregisterProjection,\n clearProjections,\n getRegisteredProjections,\n isProjectionRegistered,\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/standalone-projection-loader.ts"],"names":[],"mappings":";AAqKA,IAAM,kBAAA,uBAAyB,GAAA,EAA+B;AAiBvD,SAAS,kBAAA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,CAAA,CAAE,CAAA;AAAA,IACxI;AAEA,IAAA,IAAI,CAAC,UAAU,MAAA,EAAQ;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,UAAA,EAAa,SAAA,CAAU,IAAI,CAAA,eAAA,CAAiB,CAAA;AAAA,IAC9D;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT;AAkBO,SAAS,YAAA,CACd,YACA,OAAA,EACgB;AAChB,EAAA,IAAI,MAAA;AAEJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAA,CAAK,MAAM,UAAU,CAAA;AAAA,EAChC,SACO,KAAA,EAAO;AACZ,IAAA,MAAM,IAAI,MAAM,CAAA,cAAA,EAAiB,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,eAAe,CAAA,CAAE,CAAA;AAAA,EAC7F;AAEA,EAAA,cAAA,CAAe,MAAM,CAAA;AACrB,EAAA,OAAO,uBAAA,CAAwB,QAAQ,OAAO,CAAA;AAChD","file":"index.js","sourcesContent":["/**\n * Standalone Composite Projection Loader (Zero Dependencies)\n *\n * A pure JavaScript/TypeScript module that consumes exported composite projection\n * configurations and creates D3-compatible projections using a plugin architecture.\n *\n * This package has ZERO dependencies. Users must register projection factories\n * before loading configurations.\n *\n * @example\n * ```typescript\n * // Register projections first\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from './standalone-projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Then load your configuration\n * const projection = loadCompositeProjection(config, { width: 800, height: 600 })\n * ```\n *\n * @packageDocumentation\n */\n\n/**\n * Generic projection-like interface that matches D3 projections\n * without requiring d3-geo as a dependency\n *\n * Note: D3 projections use getter/setter pattern where calling without\n * arguments returns the current value, and with arguments sets and returns this.\n */\nexport interface ProjectionLike {\n (coordinates: [number, number]): [number, number] | null\n center?: {\n (): [number, number]\n (center: [number, number]): ProjectionLike\n }\n rotate?: {\n (): [number, number, number]\n (angles: [number, number, number]): ProjectionLike\n }\n parallels?: {\n (): [number, number]\n (parallels: [number, number]): ProjectionLike\n }\n scale?: {\n (): number\n (scale: number): ProjectionLike\n }\n translate?: {\n (): [number, number]\n (translate: [number, number]): ProjectionLike\n }\n clipExtent?: {\n (): [[number, number], [number, number]] | null\n (extent: [[number, number], [number, number]] | null): ProjectionLike\n }\n clipAngle?: {\n (): number\n (angle: number): ProjectionLike\n }\n stream?: (stream: StreamLike) => StreamLike\n precision?: {\n (): number\n (precision: number): ProjectionLike\n }\n fitExtent?: (extent: [[number, number], [number, number]], object: any) => ProjectionLike\n fitSize?: (size: [number, number], object: any) => ProjectionLike\n fitWidth?: (width: number, object: any) => ProjectionLike\n fitHeight?: (height: number, object: any) => ProjectionLike\n}\n\n/**\n * Stream protocol interface for D3 geographic transforms\n */\nexport interface StreamLike {\n point: (x: number, y: number) => void\n lineStart: () => void\n lineEnd: () => void\n polygonStart: () => void\n polygonEnd: () => void\n sphere?: () => void\n}\n\n/**\n * Factory function that creates a projection instance\n */\nexport type ProjectionFactory = () => ProjectionLike\n\n/**\n * Exported configuration format (subset needed for loading)\n */\nexport interface ExportedConfig {\n version: string\n metadata: {\n atlasId: string\n atlasName: string\n exportDate?: string\n createdWith?: string\n notes?: string\n }\n pattern: string\n referenceScale?: number\n canvasDimensions?: {\n width: number\n height: number\n }\n territories: Territory[]\n}\n\nexport interface Territory {\n code: string\n name: string\n role: string\n // Support multiple formats\n projectionId?: string // Legacy format\n projectionFamily?: string // Migration script format\n projection?: {\n id: string\n family: string\n parameters: ProjectionParameters\n } // New format\n parameters?: ProjectionParameters // Used in legacy and migration formats\n layout: Layout\n bounds: [[number, number], [number, number]]\n}\n\nexport interface ProjectionParameters {\n center?: [number, number]\n rotate?: [number, number, number]\n // Legacy format support\n scale?: number\n baseScale?: number\n scaleMultiplier?: number\n parallels?: [number, number]\n // Additional parameters from new format\n translate?: [number, number]\n clipAngle?: number\n precision?: number\n}\n\nexport interface Layout {\n translateOffset?: [number, number] // Make optional for migration script format\n clipExtent?: [[number, number], [number, number]] | null\n}\n\n/**\n * Options for creating the composite projection\n */\nexport interface LoaderOptions {\n /** Canvas width in pixels */\n width: number\n /** Canvas height in pixels */\n height: number\n /** Whether to apply clipping to territories (default: true) */\n enableClipping?: boolean\n /** Debug mode - logs territory selection (default: false) */\n debug?: boolean\n}\n\n/**\n * Runtime registry for projection factories\n * Users must register projections before loading configurations\n */\nconst projectionRegistry = new Map<string, ProjectionFactory>()\n\n/**\n * Register a projection factory with a given ID\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection } from '@atlas-composer/projection-loader'\n *\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n * ```\n *\n * @param id - Projection identifier (e.g., 'mercator', 'albers')\n * @param factory - Function that creates a new projection instance\n */\nexport function registerProjection(id: string, factory: ProjectionFactory): void {\n projectionRegistry.set(id, factory)\n}\n\n/**\n * Register multiple projections at once\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjections } from '@atlas-composer/projection-loader'\n *\n * registerProjections({\n * 'mercator': () => d3.geoMercator(),\n * 'albers': () => d3.geoAlbers(),\n * 'conic-equal-area': () => d3.geoConicEqualArea()\n * })\n * ```\n *\n * @param factories - Object mapping projection IDs to factory functions\n */\nexport function registerProjections(factories: Record<string, ProjectionFactory>): void {\n for (const [id, factory] of Object.entries(factories)) {\n registerProjection(id, factory)\n }\n}\n\n/**\n * Unregister a projection\n *\n * @param id - Projection identifier to remove\n * @returns True if the projection was removed, false if it wasn't registered\n */\nexport function unregisterProjection(id: string): boolean {\n return projectionRegistry.delete(id)\n}\n\n/**\n * Clear all registered projections\n */\nexport function clearProjections(): void {\n projectionRegistry.clear()\n}\n\n/**\n * Get list of currently registered projection IDs\n *\n * @returns Array of registered projection identifiers\n */\nexport function getRegisteredProjections(): string[] {\n return Array.from(projectionRegistry.keys())\n}\n\n/**\n * Check if a projection is registered\n *\n * @param id - Projection identifier to check\n * @returns True if the projection is registered\n */\nexport function isProjectionRegistered(id: string): boolean {\n return projectionRegistry.has(id)\n}\n\n/**\n * Create a minimal projection wrapper (similar to d3.geoProjection)\n * This allows us to avoid the d3-geo dependency\n */\nfunction createProjectionWrapper(\n project: (lambda: number, phi: number) => [number, number] | null,\n): ProjectionLike {\n let _scale = 150\n let _translate: [number, number] = [480, 250]\n\n const projection: any = function (coordinates: [number, number]): [number, number] | null {\n const point = project(coordinates[0] * Math.PI / 180, coordinates[1] * Math.PI / 180)\n if (!point)\n return null\n return [point[0] * _scale + _translate[0], point[1] * _scale + _translate[1]]\n }\n\n // D3-style getter/setter for scale\n Object.defineProperty(projection, 'scale', {\n value(...args: any[]): any {\n if (args.length > 0) {\n _scale = args[0]\n return projection\n }\n return _scale\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n\n // D3-style getter/setter for translate\n Object.defineProperty(projection, 'translate', {\n value(...args: any[]): any {\n if (args.length > 0) {\n _translate = args[0]\n return projection\n }\n return _translate\n },\n writable: true,\n enumerable: true,\n configurable: true,\n })\n\n return projection as ProjectionLike\n}\n\n/**\n * Create a D3-compatible projection from an exported composite projection configuration\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadCompositeProjection } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n * registerProjection('albers', () => d3.geoAlbers())\n *\n * // Load configuration\n * const config = JSON.parse(jsonString)\n *\n * // Create projection\n * const projection = loadCompositeProjection(config, {\n * width: 800,\n * height: 600\n * })\n *\n * // Use with D3\n * const path = d3.geoPath(projection)\n * svg.selectAll('path')\n * .data(countries.features)\n * .join('path')\n * .attr('d', path)\n * ```\n *\n * @param config - Exported composite projection configuration\n * @param options - Canvas dimensions and options\n * @returns D3-compatible projection that routes geometry to appropriate sub-projections\n */\nexport function loadCompositeProjection(\n config: ExportedConfig,\n options: LoaderOptions,\n): ProjectionLike {\n const { width, height, debug = false } = options\n\n // Validate configuration version\n if (config.version !== '1.0') {\n throw new Error(`Unsupported configuration version: ${config.version}`)\n }\n\n if (!config.territories || config.territories.length === 0) {\n throw new Error('Configuration must contain at least one territory')\n }\n\n // Create sub-projections for each territory\n const subProjections = config.territories.map((territory) => {\n const proj = createSubProjection(territory, width, height, config.referenceScale)\n\n return {\n territory,\n projection: proj,\n bounds: territory.bounds,\n }\n })\n\n if (debug) {\n console.log('[CompositeProjection] Created sub-projections:', {\n territories: config.territories.map(t => ({ code: t.code, name: t.name })),\n count: subProjections.length,\n })\n }\n\n // Create composite projection using custom stream multiplexing\n const compositeProjection = createProjectionWrapper((lambda: number, phi: number) => {\n // Convert radians to degrees for bounds checking\n const lon = (lambda * 180) / Math.PI\n const lat = (phi * 180) / Math.PI\n\n // Find which territory this point belongs to\n let selectedProj = null\n for (const { projection, bounds } of subProjections) {\n if (\n lon >= bounds[0][0] && lon <= bounds[1][0]\n && lat >= bounds[0][1] && lat <= bounds[1][1]\n ) {\n selectedProj = projection\n break\n }\n }\n\n // If no territory matched, use first projection (fallback)\n if (!selectedProj && subProjections[0]) {\n selectedProj = subProjections[0].projection\n }\n\n // Project the point (should always have a projection by this point)\n return selectedProj!([lambda, phi])\n })\n\n // Implement stream multiplexing for proper geometry routing\n compositeProjection.stream = function (stream: StreamLike): StreamLike {\n let activeStream: StreamLike | null = null\n let bufferedPoints: Array<[number, number]> = []\n let activeTerritoryCode = ''\n\n return {\n point(lon: number, lat: number) {\n // Buffer points until we can determine which territory they belong to\n bufferedPoints.push([lon, lat])\n\n // If we have an active stream, forward the point\n if (activeStream) {\n const lonDeg = (lon * 180) / Math.PI\n const latDeg = (lat * 180) / Math.PI\n\n if (debug) {\n console.log(`[Stream] Point: [${lonDeg.toFixed(2)}, ${latDeg.toFixed(2)}] → ${activeTerritoryCode}`)\n }\n\n activeStream.point(lon, lat)\n }\n },\n\n lineStart() {\n // Determine which territory this line belongs to\n if (bufferedPoints.length > 0 && bufferedPoints[0]) {\n const [lon, lat] = bufferedPoints[0]\n const lonDeg = (lon * 180) / Math.PI\n const latDeg = (lat * 180) / Math.PI\n\n // Find matching territory\n for (const { territory, projection, bounds } of subProjections) {\n if (\n lonDeg >= bounds[0][0] && lonDeg <= bounds[1][0]\n && latDeg >= bounds[0][1] && latDeg <= bounds[1][1]\n ) {\n // Use the projection's stream if available\n if (projection.stream) {\n activeStream = projection.stream(stream)\n activeTerritoryCode = territory.code\n }\n\n if (debug) {\n console.log(`[Stream] Line started in territory: ${territory.code}`)\n }\n break\n }\n }\n\n // Fallback to first projection\n if (!activeStream && subProjections[0]) {\n const firstProj = subProjections[0].projection\n if (firstProj.stream) {\n activeStream = firstProj.stream(stream)\n activeTerritoryCode = subProjections[0].territory.code\n }\n\n if (debug) {\n console.log(`[Stream] Line started (fallback): ${activeTerritoryCode}`)\n }\n }\n }\n\n if (activeStream) {\n activeStream.lineStart()\n\n // Replay buffered points\n for (const [lon, lat] of bufferedPoints) {\n activeStream.point(lon, lat)\n }\n }\n\n bufferedPoints = []\n },\n\n lineEnd() {\n if (activeStream) {\n activeStream.lineEnd()\n }\n },\n\n polygonStart() {\n bufferedPoints = []\n activeStream = null\n },\n\n polygonEnd() {\n if (activeStream) {\n activeStream.polygonEnd()\n }\n activeStream = null\n },\n\n sphere() {\n // Not supported in composite projections\n if (debug) {\n console.warn('[Stream] sphere() called - not supported in composite projections')\n }\n },\n }\n }\n\n // Set reasonable defaults for the composite projection\n // Note: Individual territories handle their own scale/translate\n if (compositeProjection.scale) {\n compositeProjection.scale(1)\n }\n if (compositeProjection.translate) {\n compositeProjection.translate([width / 2, height / 2])\n }\n\n return compositeProjection\n}\n\n/**\n * Infer projection ID from family and parameters (for migration script format)\n */\nfunction inferProjectionIdFromFamily(family: string, parameters: ProjectionParameters): string {\n // Common projection mappings based on family and parameters\n switch (family.toUpperCase()) {\n case 'CYLINDRICAL':\n return 'mercator' // Most common cylindrical projection\n case 'CONIC':\n return parameters.parallels ? 'conic-conformal' : 'conic-equal-area'\n case 'AZIMUTHAL':\n return 'azimuthal-equal-area'\n default:\n // Fallback to mercator if we can't determine\n console.warn(`Unknown projection family: ${family}, falling back to mercator`)\n return 'mercator'\n }\n}\n\n/**\n * Create a sub-projection for a single territory\n */\nfunction createSubProjection(\n territory: Territory,\n width: number,\n height: number,\n referenceScale?: number,\n): ProjectionLike {\n // Extract projection info and parameters from multiple formats\n let projectionId: string\n let parameters: ProjectionParameters\n const { layout } = territory\n\n if (territory.projection) {\n // New format: nested projection object\n projectionId = territory.projection.id\n parameters = territory.projection.parameters\n }\n else if (territory.projectionId && territory.parameters) {\n // Legacy format: direct properties\n projectionId = territory.projectionId\n parameters = territory.parameters\n }\n else if (territory.projectionFamily && territory.parameters) {\n // Migration script format: has projectionFamily but missing projectionId\n // Try to infer projection ID from family and parameters\n projectionId = inferProjectionIdFromFamily(territory.projectionFamily as string, territory.parameters)\n parameters = territory.parameters\n }\n else {\n throw new Error(`Territory ${territory.code} missing projection configuration`)\n }\n\n // Get projection factory from registry\n const factory = projectionRegistry.get(projectionId)\n if (!factory) {\n const registered = getRegisteredProjections()\n const availableList = registered.length > 0 ? registered.join(', ') : 'none'\n throw new Error(\n `Projection \"${projectionId}\" is not registered. `\n + `Available projections: ${availableList}. `\n + `Use registerProjection('${projectionId}', factory) to register it.`,\n )\n }\n\n // Create projection instance\n const projection = factory()\n\n // Apply parameters\n if (parameters.center && projection.center) {\n projection.center(parameters.center)\n }\n\n if (parameters.rotate && projection.rotate) {\n // Ensure rotate has exactly 3 elements\n const rotate = Array.isArray(parameters.rotate)\n ? [...parameters.rotate, 0, 0].slice(0, 3) as [number, number, number]\n : [0, 0, 0] as [number, number, number]\n projection.rotate(rotate)\n }\n\n if (parameters.parallels && projection.parallels) {\n // Ensure parallels has exactly 2 elements\n const parallels = Array.isArray(parameters.parallels)\n ? [...parameters.parallels, 0].slice(0, 2) as [number, number]\n : [0, 60] as [number, number]\n projection.parallels(parallels)\n }\n\n // Handle scale - support both legacy (scale) and new (scaleMultiplier + referenceScale) formats\n if (projection.scale) {\n if (parameters.scale) {\n // Legacy format: use direct scale value\n projection.scale(parameters.scale)\n }\n else if (parameters.scaleMultiplier) {\n // New format: calculate scale from reference scale and multiplier\n const effectiveReferenceScale = referenceScale || 2700 // Default reference scale\n const calculatedScale = effectiveReferenceScale * parameters.scaleMultiplier\n projection.scale(calculatedScale)\n }\n }\n\n // Apply additional parameters\n if (parameters.clipAngle && projection.clipAngle) {\n projection.clipAngle(parameters.clipAngle)\n }\n\n if (parameters.precision && projection.precision) {\n projection.precision(parameters.precision)\n }\n\n // Apply layout translate\n if (projection.translate) {\n const [offsetX, offsetY] = layout.translateOffset || [0, 0] // Default to center if missing\n projection.translate([\n width / 2 + offsetX,\n height / 2 + offsetY,\n ])\n }\n\n // Apply parameter-level translate (additional adjustment)\n if (parameters.translate && projection.translate) {\n const currentTranslate = projection.translate()\n const [additionalX, additionalY] = parameters.translate\n projection.translate([\n currentTranslate[0] + additionalX,\n currentTranslate[1] + additionalY,\n ])\n }\n\n // Apply clipping if specified\n if (layout.clipExtent && projection.clipExtent) {\n projection.clipExtent(layout.clipExtent)\n }\n\n return projection\n}\n\n/**\n * Validate an exported configuration\n *\n * @param config - Configuration to validate\n * @returns True if valid, throws error otherwise\n */\nexport function validateConfig(config: any): config is ExportedConfig {\n if (!config || typeof config !== 'object') {\n throw new Error('Configuration must be an object')\n }\n\n if (!config.version) {\n throw new Error('Configuration must have a version field')\n }\n\n if (!config.metadata || !config.metadata.atlasId) {\n throw new Error('Configuration must have metadata with atlasId')\n }\n\n if (!config.territories || !Array.isArray(config.territories)) {\n throw new Error('Configuration must have territories array')\n }\n\n if (config.territories.length === 0) {\n throw new Error('Configuration must have at least one territory')\n }\n\n // Validate each territory\n for (const territory of config.territories) {\n if (!territory.code) {\n throw new Error(`Territory missing required field 'code': ${JSON.stringify(territory)}`)\n }\n\n // Check for projection info in either format\n const hasLegacyFormat = territory.projectionId && territory.parameters\n const hasNewFormat = territory.projection && territory.projection.id && territory.projection.parameters\n const hasIncompleteFormat = territory.projectionFamily && territory.parameters // Migration script format\n\n if (!hasLegacyFormat && !hasNewFormat && !hasIncompleteFormat) {\n throw new Error(`Territory ${territory.code} missing projection configuration. Available fields: ${Object.keys(territory).join(', ')}`)\n }\n\n if (!territory.bounds) {\n throw new Error(`Territory ${territory.code} missing bounds`)\n }\n }\n\n return true\n}\n\n/**\n * Load composite projection from JSON string\n *\n * @example\n * ```typescript\n * import * as d3 from 'd3-geo'\n * import { registerProjection, loadFromJSON } from '@atlas-composer/projection-loader'\n *\n * // Register projections first\n * registerProjection('mercator', () => d3.geoMercator())\n *\n * // Load from JSON\n * const jsonString = fs.readFileSync('france-composite.json', 'utf-8')\n * const projection = loadFromJSON(jsonString, { width: 800, height: 600 })\n * ```\n */\nexport function loadFromJSON(\n jsonString: string,\n options: LoaderOptions,\n): ProjectionLike {\n let config: any\n\n try {\n config = JSON.parse(jsonString)\n }\n catch (error) {\n throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`)\n }\n\n validateConfig(config)\n return loadCompositeProjection(config, options)\n}\n\n// Default export\nexport default {\n // Core loading functions\n loadCompositeProjection,\n loadFromJSON,\n validateConfig,\n\n // Registry management\n registerProjection,\n registerProjections,\n unregisterProjection,\n clearProjections,\n getRegisteredProjections,\n isProjectionRegistered,\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlas-composer/projection-loader",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "Zero-dependency standalone loader for composite map projections with plugin architecture",
|
|
4
|
+
"version": "1.1.0-rc.1",
|
|
5
|
+
"description": "Zero-dependency standalone loader for composite map projections with plugin architecture. Supports Atlas composer 2.0+ presets with backward compatibility.",
|
|
6
6
|
"author": "Lucas Poulain (ShallowRed)",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/ShallowRed/atlas-composer/tree/main/packages/projection-loader#readme",
|
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
"build": "tsup",
|
|
51
51
|
"dev": "tsup --watch",
|
|
52
52
|
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
53
55
|
"size": "size-limit",
|
|
54
56
|
"size:why": "size-limit --why"
|
|
55
57
|
},
|
|
@@ -82,7 +84,10 @@
|
|
|
82
84
|
"devDependencies": {
|
|
83
85
|
"@size-limit/preset-small-lib": "^11.2.0",
|
|
84
86
|
"@types/d3-geo": "^3.1.0",
|
|
87
|
+
"d3-geo": "^3.1.1",
|
|
88
|
+
"d3-geo-projection": "^4.0.0",
|
|
85
89
|
"tsup": "^8.0.0",
|
|
86
|
-
"typescript": "~5.9.3"
|
|
90
|
+
"typescript": "~5.9.3",
|
|
91
|
+
"vitest": "^3.2.4"
|
|
87
92
|
}
|
|
88
93
|
}
|