@maplat/transform 0.2.3 → 0.4.0
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/LICENSE +224 -224
- package/README.ja.md +68 -68
- package/README.md +143 -143
- package/dist/index.d.ts +28 -23
- package/dist/maplat_transform.js +515 -444
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +40 -44
- package/src/compiled-state.ts +211 -0
- package/src/edgeutils.ts +47 -47
- package/src/geometry.ts +247 -248
- package/src/index.ts +398 -567
- package/src/triangulation.ts +179 -179
- package/src/types.ts +122 -0
- package/dist/index.html +0 -39
- package/dist/maplat_transform.cjs +0 -1
package/README.md
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
# Maplat Transform
|
|
2
|
-
|
|
3
|
-
A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
|
|
4
|
-
This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
|
|
5
|
-
|
|
6
|
-
日本語のREADMEは[こちら](./README.ja.md)
|
|
7
|
-
|
|
8
|
-
## Key Features
|
|
9
|
-
|
|
10
|
-
- **Import Transformation Definitions:** Import and build internal structures from transformation definitions generated by Maplat
|
|
11
|
-
- **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
|
|
12
|
-
- **Topology Preservation:** Maintains homeomorphic properties during transformation
|
|
13
|
-
- **Multiple Coordinate System Support:** Handles transformations between various coordinate systems including standard orthogonal coordinates, Y-axis inverted coordinates, and distorted coordinates like bird's-eye views
|
|
14
|
-
- **State Management:** Save and restore transformation states
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
### npm
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
npm install @maplat/transform
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### JSR (JavaScript Registry)
|
|
25
|
-
|
|
26
|
-
```sh
|
|
27
|
-
# For Deno
|
|
28
|
-
deno add @maplat/transform
|
|
29
|
-
|
|
30
|
-
# For npm/Node.js
|
|
31
|
-
npx jsr add @maplat/transform
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Deno
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
// Using JSR (recommended)
|
|
38
|
-
import { Transform } from "jsr:@maplat/transform";
|
|
39
|
-
|
|
40
|
-
// Using deno.json import map
|
|
41
|
-
import { Transform } from "@maplat/transform";
|
|
42
|
-
|
|
43
|
-
// Or directly from npm
|
|
44
|
-
import { Transform } from "npm:@maplat/transform";
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Browser
|
|
48
|
-
|
|
49
|
-
```html
|
|
50
|
-
<script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Basic Usage
|
|
54
|
-
|
|
55
|
-
### Node.js/npm
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
import { Transform } from '@maplat/transform';
|
|
59
|
-
|
|
60
|
-
// Import transformation definition
|
|
61
|
-
const transform = new Transform();
|
|
62
|
-
transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
|
|
63
|
-
|
|
64
|
-
// Forward transformation (source → target coordinate system)
|
|
65
|
-
const transformed = transform.transform([100, 100], false);
|
|
66
|
-
|
|
67
|
-
// Backward transformation (target → source coordinate system)
|
|
68
|
-
const restored = transform.transform(transformed, true);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Deno
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
import { Transform } from "../src/index.ts";
|
|
75
|
-
|
|
76
|
-
// Load compiled data from file
|
|
77
|
-
const compiledJson = await Deno.readTextFile('./compiled.json');
|
|
78
|
-
const compiledData = JSON.parse(compiledJson);
|
|
79
|
-
|
|
80
|
-
// Create and configure transform
|
|
81
|
-
const transform = new Transform();
|
|
82
|
-
transform.setCompiled(compiledData);
|
|
83
|
-
|
|
84
|
-
// Use the same API as Node.js
|
|
85
|
-
const transformed = transform.transform([100, 100], false);
|
|
86
|
-
const restored = transform.transform(transformed, true);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Error Handling
|
|
90
|
-
|
|
91
|
-
The library may throw errors in the following cases:
|
|
92
|
-
|
|
93
|
-
- Transformation errors in strict mode
|
|
94
|
-
- Attempting backward transformation when not allowed
|
|
95
|
-
- Invalid data structure during transformation
|
|
96
|
-
|
|
97
|
-
If errors occur, the transformation definition data needs to be modified. Please use editor tools that incorporate [@maplat/tin](https://github.com/code4history/MaplatTin/) to modify transformation definitions.
|
|
98
|
-
|
|
99
|
-
## Development
|
|
100
|
-
|
|
101
|
-
### Running Tests
|
|
102
|
-
|
|
103
|
-
#### Node.js
|
|
104
|
-
```sh
|
|
105
|
-
npm test
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
#### Deno
|
|
109
|
-
```sh
|
|
110
|
-
deno task test
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Running Examples
|
|
114
|
-
|
|
115
|
-
#### Deno
|
|
116
|
-
```sh
|
|
117
|
-
# Run the example
|
|
118
|
-
deno run --allow-read examples/deno-example.ts
|
|
119
|
-
|
|
120
|
-
# Or using deno task
|
|
121
|
-
cd examples && deno run --allow-read deno-example.ts
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Important Note
|
|
125
|
-
|
|
126
|
-
This library specializes in executing coordinate transformations and does not include functionality for generating or editing transformation definitions. If you need to create or edit transformation definitions, please use the [@maplat/tin](https://github.com/code4history/MaplatTin/) package.
|
|
127
|
-
|
|
128
|
-
## Deno Support
|
|
129
|
-
|
|
130
|
-
This library fully supports Deno. See the [Deno Usage Guide](./docs/DENO_USAGE.md) for detailed instructions on using MaplatTransform with Deno.
|
|
131
|
-
|
|
132
|
-
## License
|
|
133
|
-
|
|
134
|
-
Maplat Limited License 1.1
|
|
135
|
-
|
|
136
|
-
Copyright (c) 2024 Code for History
|
|
137
|
-
|
|
138
|
-
### Developers
|
|
139
|
-
|
|
140
|
-
- Kohei Otsuka
|
|
141
|
-
- Code for History
|
|
142
|
-
|
|
143
|
-
We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTransform/issues).
|
|
1
|
+
# Maplat Transform
|
|
2
|
+
|
|
3
|
+
A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
|
|
4
|
+
This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
|
|
5
|
+
|
|
6
|
+
日本語のREADMEは[こちら](./README.ja.md)
|
|
7
|
+
|
|
8
|
+
## Key Features
|
|
9
|
+
|
|
10
|
+
- **Import Transformation Definitions:** Import and build internal structures from transformation definitions generated by Maplat
|
|
11
|
+
- **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
|
|
12
|
+
- **Topology Preservation:** Maintains homeomorphic properties during transformation
|
|
13
|
+
- **Multiple Coordinate System Support:** Handles transformations between various coordinate systems including standard orthogonal coordinates, Y-axis inverted coordinates, and distorted coordinates like bird's-eye views
|
|
14
|
+
- **State Management:** Save and restore transformation states
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### npm
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @maplat/transform
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### JSR (JavaScript Registry)
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
# For Deno
|
|
28
|
+
deno add @maplat/transform
|
|
29
|
+
|
|
30
|
+
# For npm/Node.js
|
|
31
|
+
npx jsr add @maplat/transform
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Deno
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Using JSR (recommended)
|
|
38
|
+
import { Transform } from "jsr:@maplat/transform";
|
|
39
|
+
|
|
40
|
+
// Using deno.json import map
|
|
41
|
+
import { Transform } from "@maplat/transform";
|
|
42
|
+
|
|
43
|
+
// Or directly from npm
|
|
44
|
+
import { Transform } from "npm:@maplat/transform";
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Browser
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Basic Usage
|
|
54
|
+
|
|
55
|
+
### Node.js/npm
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
import { Transform } from '@maplat/transform';
|
|
59
|
+
|
|
60
|
+
// Import transformation definition
|
|
61
|
+
const transform = new Transform();
|
|
62
|
+
transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
|
|
63
|
+
|
|
64
|
+
// Forward transformation (source → target coordinate system)
|
|
65
|
+
const transformed = transform.transform([100, 100], false);
|
|
66
|
+
|
|
67
|
+
// Backward transformation (target → source coordinate system)
|
|
68
|
+
const restored = transform.transform(transformed, true);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Deno
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Transform } from "../src/index.ts";
|
|
75
|
+
|
|
76
|
+
// Load compiled data from file
|
|
77
|
+
const compiledJson = await Deno.readTextFile('./compiled.json');
|
|
78
|
+
const compiledData = JSON.parse(compiledJson);
|
|
79
|
+
|
|
80
|
+
// Create and configure transform
|
|
81
|
+
const transform = new Transform();
|
|
82
|
+
transform.setCompiled(compiledData);
|
|
83
|
+
|
|
84
|
+
// Use the same API as Node.js
|
|
85
|
+
const transformed = transform.transform([100, 100], false);
|
|
86
|
+
const restored = transform.transform(transformed, true);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Error Handling
|
|
90
|
+
|
|
91
|
+
The library may throw errors in the following cases:
|
|
92
|
+
|
|
93
|
+
- Transformation errors in strict mode
|
|
94
|
+
- Attempting backward transformation when not allowed
|
|
95
|
+
- Invalid data structure during transformation
|
|
96
|
+
|
|
97
|
+
If errors occur, the transformation definition data needs to be modified. Please use editor tools that incorporate [@maplat/tin](https://github.com/code4history/MaplatTin/) to modify transformation definitions.
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
### Running Tests
|
|
102
|
+
|
|
103
|
+
#### Node.js
|
|
104
|
+
```sh
|
|
105
|
+
npm test
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Deno
|
|
109
|
+
```sh
|
|
110
|
+
deno task test
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Running Examples
|
|
114
|
+
|
|
115
|
+
#### Deno
|
|
116
|
+
```sh
|
|
117
|
+
# Run the example
|
|
118
|
+
deno run --allow-read examples/deno-example.ts
|
|
119
|
+
|
|
120
|
+
# Or using deno task
|
|
121
|
+
cd examples && deno run --allow-read deno-example.ts
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Important Note
|
|
125
|
+
|
|
126
|
+
This library specializes in executing coordinate transformations and does not include functionality for generating or editing transformation definitions. If you need to create or edit transformation definitions, please use the [@maplat/tin](https://github.com/code4history/MaplatTin/) package.
|
|
127
|
+
|
|
128
|
+
## Deno Support
|
|
129
|
+
|
|
130
|
+
This library fully supports Deno. See the [Deno Usage Guide](./docs/DENO_USAGE.md) for detailed instructions on using MaplatTransform with Deno.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
Maplat Limited License 1.1
|
|
135
|
+
|
|
136
|
+
Copyright (c) 2024 Code for History
|
|
137
|
+
|
|
138
|
+
### Developers
|
|
139
|
+
|
|
140
|
+
- Kohei Otsuka
|
|
141
|
+
- Code for History
|
|
142
|
+
|
|
143
|
+
We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTransform/issues).
|
package/dist/index.d.ts
CHANGED
|
@@ -5,21 +5,18 @@ import { Polygon } from 'geojson';
|
|
|
5
5
|
import { Position } from 'geojson';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* - forw: 順方向(ソース → ターゲット)
|
|
10
|
-
* - bakw: 逆方向(ターゲット → ソース)
|
|
8
|
+
* Directional selector shared across the codebase.
|
|
11
9
|
*/
|
|
12
10
|
export declare type BiDirectionKey = "forw" | "bakw";
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
declare type Centroid = Feature<Point>;
|
|
15
13
|
|
|
16
14
|
export declare type CentroidBD = {
|
|
17
15
|
[key in BiDirectionKey]?: Centroid;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
22
|
-
* 変換に必要な全ての情報を含む
|
|
19
|
+
* Serialized structure generated by MaplatTin and consumed by Transform.
|
|
23
20
|
*/
|
|
24
21
|
export declare interface Compiled {
|
|
25
22
|
version?: number;
|
|
@@ -42,6 +39,9 @@ export declare interface Compiled {
|
|
|
42
39
|
xy?: number[];
|
|
43
40
|
}
|
|
44
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Historical serialization format prior to 2.00703.
|
|
44
|
+
*/
|
|
45
45
|
export declare interface CompiledLegacy extends Compiled {
|
|
46
46
|
tins?: TinsBD;
|
|
47
47
|
centroid?: CentroidBD;
|
|
@@ -96,7 +96,7 @@ export declare type IndexedTinsBD = {
|
|
|
96
96
|
[key in BiDirectionKey]?: IndexedTins;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
declare type Kinks = FeatureCollection<Point>;
|
|
100
100
|
|
|
101
101
|
export declare type KinksBD = {
|
|
102
102
|
[key in BiDirectionKey]?: Kinks;
|
|
@@ -113,7 +113,7 @@ export declare type KinksBD = {
|
|
|
113
113
|
export declare function normalizeEdges(edges: EdgeSet[] | EdgeSetLegacy[], version?: number): EdgeSet[];
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
116
|
+
* Two-way coordinate pair: [source, target].
|
|
117
117
|
*/
|
|
118
118
|
export declare type PointSet = [Position, Position];
|
|
119
119
|
|
|
@@ -137,18 +137,12 @@ export declare type PropertyTriKey = "a" | "b" | "c";
|
|
|
137
137
|
export declare function rotateVerticesTriangle(tins: Tins): Tins;
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
* - strict: 厳密モード(交差なしを保証)
|
|
142
|
-
* - auto: 自動モード(可能な限り厳密に)
|
|
143
|
-
* - loose: 緩和モード(交差を許容)
|
|
140
|
+
* Strictness flags supported during transformation.
|
|
144
141
|
*/
|
|
145
142
|
export declare type StrictMode = "strict" | "auto" | "loose";
|
|
146
143
|
|
|
147
144
|
/**
|
|
148
|
-
*
|
|
149
|
-
* - strict: 厳密モード生成成功
|
|
150
|
-
* - auto: 厳密モードでエラー
|
|
151
|
-
* - loose: 緩和モード
|
|
145
|
+
* Result of strictness evaluation.
|
|
152
146
|
*/
|
|
153
147
|
export declare type StrictStatus = "strict" | "strict_error" | "loose";
|
|
154
148
|
|
|
@@ -200,6 +194,19 @@ export declare class Transform {
|
|
|
200
194
|
stateFull: boolean;
|
|
201
195
|
stateTriangle?: Tri;
|
|
202
196
|
stateBackward?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Optional properties for MaplatCore extension
|
|
199
|
+
* These properties allow consuming applications to extend Transform instances
|
|
200
|
+
* with additional metadata without requiring Module Augmentation
|
|
201
|
+
*/
|
|
202
|
+
/** Layer priority for rendering order */
|
|
203
|
+
priority?: number;
|
|
204
|
+
/** Layer importance for display decisions */
|
|
205
|
+
importance?: number;
|
|
206
|
+
/** Bounds in XY (source) coordinate system */
|
|
207
|
+
xyBounds?: Feature<Polygon>;
|
|
208
|
+
/** Bounds in Mercator (Web Mercator) coordinate system */
|
|
209
|
+
mercBounds?: Feature<Polygon>;
|
|
203
210
|
constructor();
|
|
204
211
|
/**
|
|
205
212
|
* コンパイルされた設定を適用します
|
|
@@ -214,6 +221,8 @@ export declare class Transform {
|
|
|
214
221
|
* 4. インデックスの作成
|
|
215
222
|
*/
|
|
216
223
|
setCompiled(compiled: Compiled | CompiledLegacy): void;
|
|
224
|
+
private applyModernState;
|
|
225
|
+
private applyLegacyState;
|
|
217
226
|
/**
|
|
218
227
|
* TINネットワークのインデックスを作成します
|
|
219
228
|
*
|
|
@@ -254,9 +263,7 @@ export declare function transformArr(point: Feature<Point>, tins: Tins, indexedT
|
|
|
254
263
|
export declare type Tri = Feature<Polygon, PropertiesTri>;
|
|
255
264
|
|
|
256
265
|
/**
|
|
257
|
-
*
|
|
258
|
-
* - plain: 通常モード
|
|
259
|
-
* - birdeye: 鳥瞰図モード
|
|
266
|
+
* Vertex interpolation modes.
|
|
260
267
|
*/
|
|
261
268
|
export declare type VertexMode = "plain" | "birdeye";
|
|
262
269
|
|
|
@@ -271,16 +278,14 @@ declare type WeightBuffer = {
|
|
|
271
278
|
};
|
|
272
279
|
|
|
273
280
|
/**
|
|
274
|
-
*
|
|
281
|
+
* Weight buffers indexed by node id for both directions.
|
|
275
282
|
*/
|
|
276
283
|
export declare type WeightBufferBD = {
|
|
277
284
|
[key in BiDirectionKey]?: WeightBuffer;
|
|
278
285
|
};
|
|
279
286
|
|
|
280
287
|
/**
|
|
281
|
-
* Y
|
|
282
|
-
* - follow: Y軸の向きを維持
|
|
283
|
-
* - invert: Y軸の向きを反転
|
|
288
|
+
* Y-axis handling directive.
|
|
284
289
|
*/
|
|
285
290
|
export declare type YaxisMode = "follow" | "invert";
|
|
286
291
|
|