@maplibre/geojson-vt 5.0.2 → 5.0.4
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 +5 -5
- package/dist/clip.d.ts +3 -0
- package/dist/clip.d.ts.map +1 -0
- package/dist/clip.test.d.ts +2 -0
- package/dist/clip.test.d.ts.map +1 -0
- package/dist/convert.d.ts +9 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/definitions.d.ts +85 -0
- package/dist/definitions.d.ts.map +1 -0
- package/dist/difference.d.ts +67 -0
- package/dist/difference.d.ts.map +1 -0
- package/dist/difference.test.d.ts +2 -0
- package/dist/difference.test.d.ts.map +1 -0
- package/dist/feature.d.ts +12 -0
- package/dist/feature.d.ts.map +1 -0
- package/dist/geojson-vt-dev.js +63 -34
- package/dist/geojson-vt.js +1 -1
- package/dist/geojson-vt.mjs +63 -34
- package/dist/geojson-vt.mjs.map +1 -1
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/simplify.d.ts +9 -0
- package/dist/simplify.d.ts.map +1 -0
- package/dist/simplify.test.d.ts +2 -0
- package/dist/simplify.test.d.ts.map +1 -0
- package/dist/tile.d.ts +40 -0
- package/dist/tile.d.ts.map +1 -0
- package/dist/transform.d.ts +27 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.d.ts.map +1 -0
- package/package.json +9 -3
- package/src/clip.ts +3 -3
- package/src/convert.ts +4 -4
- package/src/definitions.ts +1 -1
- package/src/difference.ts +4 -4
- package/src/feature.ts +4 -4
- package/src/index.ts +19 -14
- package/src/tile.ts +71 -43
- package/src/transform.ts +31 -16
- package/src/wrap.ts +3 -3
package/dist/wrap.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAqB,MAAM,eAAe,CAAC;AAGnG,wBAAgB,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,wBAAwB,EAAE,CAehH"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maplibre/geojson-vt",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "Slice GeoJSON data into vector tiles efficiently",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports":
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/geojson-vt.mjs",
|
|
10
|
+
"default": "./dist/geojson-vt.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
7
13
|
"sideEffects": false,
|
|
8
14
|
"keywords": [
|
|
9
15
|
"spatial",
|
|
@@ -13,7 +19,7 @@
|
|
|
13
19
|
],
|
|
14
20
|
"author": "Vladimir Agafonkin",
|
|
15
21
|
"module": "dist/geojson-vt.mjs",
|
|
16
|
-
"main": "dist/geojson-vt
|
|
22
|
+
"main": "dist/geojson-vt.js",
|
|
17
23
|
"typings": "dist/index.d.ts",
|
|
18
24
|
"jsdelivr": "dist/geojson-vt.js",
|
|
19
25
|
"unpkg": "dist/geojson-vt.js",
|
package/src/clip.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import {createFeature} from './feature';
|
|
3
|
-
import type {
|
|
3
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, StartEndSizeArray } from './definitions';
|
|
4
4
|
|
|
5
5
|
/* clip features between two vertical or horizontal axis-parallel lines:
|
|
6
6
|
* | |
|
|
@@ -12,7 +12,7 @@ import type { GeoJSONVTFeature, GeoJSONVTOptions, StartEndSizeArray } from './de
|
|
|
12
12
|
* axis: 0 for x, 1 for y
|
|
13
13
|
* minAll and maxAll: minimum and maximum coordinate value for all features
|
|
14
14
|
*/
|
|
15
|
-
export function clip(features:
|
|
15
|
+
export function clip(features: GeoJSONVTInternalFeature[], scale: number, k1: number, k2: number, axis: number, minAll: number, maxAll: number, options: GeoJSONVTOptions): GeoJSONVTInternalFeature[] | null {
|
|
16
16
|
k1 /= scale;
|
|
17
17
|
k2 /= scale;
|
|
18
18
|
|
|
@@ -24,7 +24,7 @@ export function clip(features: GeoJSONVTFeature[], scale: number, k1: number, k2
|
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const clipped:
|
|
27
|
+
const clipped: GeoJSONVTInternalFeature[] = [];
|
|
28
28
|
|
|
29
29
|
for (const feature of features) {
|
|
30
30
|
const min = axis === 0 ? feature.minX : feature.minY;
|
package/src/convert.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import {simplify} from './simplify';
|
|
3
3
|
import {createFeature} from './feature';
|
|
4
|
-
import type {
|
|
4
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, StartEndSizeArray } from './definitions';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
|
|
@@ -9,8 +9,8 @@ import type { GeoJSONVTFeature, GeoJSONVTOptions, StartEndSizeArray } from './de
|
|
|
9
9
|
* @param options
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export function convert(data: GeoJSON.GeoJSON, options: GeoJSONVTOptions):
|
|
13
|
-
const features:
|
|
12
|
+
export function convert(data: GeoJSON.GeoJSON, options: GeoJSONVTOptions): GeoJSONVTInternalFeature[] {
|
|
13
|
+
const features: GeoJSONVTInternalFeature[] = [];
|
|
14
14
|
|
|
15
15
|
switch (data.type) {
|
|
16
16
|
case 'FeatureCollection':
|
|
@@ -28,7 +28,7 @@ export function convert(data: GeoJSON.GeoJSON, options: GeoJSONVTOptions): GeoJS
|
|
|
28
28
|
return features;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function convertFeature(features:
|
|
31
|
+
function convertFeature(features: GeoJSONVTInternalFeature[], geojson: GeoJSON.Feature, options: GeoJSONVTOptions, index?: number) {
|
|
32
32
|
if (!geojson.geometry) return;
|
|
33
33
|
|
|
34
34
|
if (geojson.geometry.type === 'GeometryCollection') {
|
package/src/definitions.ts
CHANGED
|
@@ -78,7 +78,7 @@ export type GeometryTypeMap = {
|
|
|
78
78
|
|
|
79
79
|
export type GeometryType = "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon";
|
|
80
80
|
|
|
81
|
-
export type
|
|
81
|
+
export type GeoJSONVTInternalFeature = {
|
|
82
82
|
[K in GeometryType]: PartialGeoJSONVTFeature & {
|
|
83
83
|
type: K;
|
|
84
84
|
geometry: GeometryTypeMap[K];
|
package/src/difference.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {convert} from './convert';
|
|
2
2
|
import {wrap} from './wrap';
|
|
3
|
-
import type {
|
|
3
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions } from './definitions';
|
|
4
4
|
|
|
5
5
|
export type GeoJSONVTSourceDiff = {
|
|
6
6
|
/**
|
|
@@ -61,13 +61,13 @@ type HashedGeoJSONVTSourceDiff = {
|
|
|
61
61
|
* @param options
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
|
-
export function applySourceDiff(source:
|
|
64
|
+
export function applySourceDiff(source: GeoJSONVTInternalFeature[], dataDiff: GeoJSONVTSourceDiff, options: GeoJSONVTOptions) {
|
|
65
65
|
|
|
66
66
|
// convert diff to sets/maps for o(1) lookups
|
|
67
67
|
const diff = diffToHashed(dataDiff);
|
|
68
68
|
|
|
69
69
|
// collection for features that will be affected by this update
|
|
70
|
-
let affected:
|
|
70
|
+
let affected: GeoJSONVTInternalFeature[] = [];
|
|
71
71
|
|
|
72
72
|
// full removal - clear everything before applying diff
|
|
73
73
|
if (diff.removeAll) {
|
|
@@ -136,7 +136,7 @@ export function applySourceDiff(source: GeoJSONVTFeature[], dataDiff: GeoJSONVTS
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// return an updated geojsonvt simplified feature
|
|
139
|
-
function getUpdatedFeature(vtFeature:
|
|
139
|
+
function getUpdatedFeature(vtFeature: GeoJSONVTInternalFeature, update: GeoJSONVTFeatureDiff, options: GeoJSONVTOptions): GeoJSONVTInternalFeature | null {
|
|
140
140
|
const changeGeometry = !!update.newGeometry;
|
|
141
141
|
|
|
142
142
|
const changeProps =
|
package/src/feature.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GeoJSONVTInternalFeature, GeometryType, GeometryTypeMap } from "./definitions";
|
|
2
2
|
|
|
3
3
|
export type SupportedGeometries = GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.LineString | GeoJSON.MultiLineString | GeoJSON.Polygon | GeoJSON.MultiPolygon;
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ export type SupportedGeometries = GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.L
|
|
|
10
10
|
* @param tags - the feature's properties
|
|
11
11
|
* @returns the created feature
|
|
12
12
|
*/
|
|
13
|
-
export function createFeature<T extends GeometryType>(id: number | string | undefined, type: T, geom: GeometryTypeMap[T], tags: GeoJSON.GeoJsonProperties):
|
|
13
|
+
export function createFeature<T extends GeometryType>(id: number | string | undefined, type: T, geom: GeometryTypeMap[T], tags: GeoJSON.GeoJsonProperties): GeoJSONVTInternalFeature {
|
|
14
14
|
// This is mostly for TypeScript type narrowing
|
|
15
15
|
const data = { type, geom } as { [K in GeometryType]: { type: K, geom: GeometryTypeMap[K] } }[GeometryType];
|
|
16
16
|
|
|
@@ -23,7 +23,7 @@ export function createFeature<T extends GeometryType>(id: number | string | unde
|
|
|
23
23
|
minY: Infinity,
|
|
24
24
|
maxX: -Infinity,
|
|
25
25
|
maxY: -Infinity
|
|
26
|
-
} as
|
|
26
|
+
} as GeoJSONVTInternalFeature;
|
|
27
27
|
|
|
28
28
|
switch (data.type) {
|
|
29
29
|
case 'Point':
|
|
@@ -54,7 +54,7 @@ export function createFeature<T extends GeometryType>(id: number | string | unde
|
|
|
54
54
|
return feature;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function calcLineBBox(feature:
|
|
57
|
+
function calcLineBBox(feature: GeoJSONVTInternalFeature, geom: number[]) {
|
|
58
58
|
for (let i = 0; i < geom.length; i += 3) {
|
|
59
59
|
feature.minX = Math.min(feature.minX, geom[i]);
|
|
60
60
|
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {convert} from './convert';
|
|
3
3
|
import {clip} from './clip';
|
|
4
4
|
import {wrap} from './wrap';
|
|
5
|
-
import {transformTile, type
|
|
6
|
-
import {createTile, type
|
|
5
|
+
import {transformTile, type GeoJSONVTFeature, type GeoJSONVTFeatureNonPoint, type GeoJSONVTFeaturePoint, type GeoJSONVTTile} from './transform';
|
|
6
|
+
import {createTile, type GeoJSONVTInternalTile, type GeoJSONVTInternalTileFeature, type GeoJSONVTInternalTileFeaturePoint, type GeoJSONVTInternalTileFeaturNonPoint} from './tile';
|
|
7
7
|
import {applySourceDiff, type GeoJSONVTFeatureDiff, type GeoJSONVTSourceDiff} from './difference';
|
|
8
|
-
import type {
|
|
8
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, GeometryType, GeometryTypeMap, PartialGeoJSONVTFeature, StartEndSizeArray } from './definitions';
|
|
9
9
|
|
|
10
10
|
const defaultOptions: GeoJSONVTOptions = {
|
|
11
11
|
maxZoom: 14,
|
|
@@ -27,13 +27,13 @@ const defaultOptions: GeoJSONVTOptions = {
|
|
|
27
27
|
class GeoJSONVT {
|
|
28
28
|
private options: GeoJSONVTOptions;
|
|
29
29
|
/** @internal */
|
|
30
|
-
public tiles: {[key: string]:
|
|
30
|
+
public tiles: {[key: string]: GeoJSONVTInternalTile};
|
|
31
31
|
private tileCoords: {z: number, x: number, y: number, id: number}[];
|
|
32
32
|
/** @internal */
|
|
33
33
|
public stats: {[key: string]: number} = {};
|
|
34
34
|
/** @internal */
|
|
35
35
|
public total: number = 0;
|
|
36
|
-
private source?:
|
|
36
|
+
private source?: GeoJSONVTInternalFeature[];
|
|
37
37
|
|
|
38
38
|
constructor(data: GeoJSON.GeoJSON, options: GeoJSONVTOptions) {
|
|
39
39
|
options = this.options = Object.assign({}, defaultOptions, options);
|
|
@@ -96,7 +96,7 @@ class GeoJSONVT {
|
|
|
96
96
|
* @param cx - target tile x coordinate
|
|
97
97
|
* @param cy - target tile y coordinate
|
|
98
98
|
*/
|
|
99
|
-
splitTile(features:
|
|
99
|
+
splitTile(features: GeoJSONVTInternalFeature[], z: number, x: number, y: number, cz?: number, cx?: number, cy?: number) {
|
|
100
100
|
|
|
101
101
|
const stack = [features, z, x, y];
|
|
102
102
|
const options = this.options;
|
|
@@ -107,7 +107,7 @@ class GeoJSONVT {
|
|
|
107
107
|
y = stack.pop() as number;
|
|
108
108
|
x = stack.pop() as number;
|
|
109
109
|
z = stack.pop() as number;
|
|
110
|
-
features = stack.pop() as
|
|
110
|
+
features = stack.pop() as GeoJSONVTInternalFeature[];
|
|
111
111
|
|
|
112
112
|
const z2 = 1 << z;
|
|
113
113
|
const id = toID(z, x, y);
|
|
@@ -195,7 +195,7 @@ class GeoJSONVT {
|
|
|
195
195
|
* @param y - tile y coordinate
|
|
196
196
|
* @returns the transformed tile or null if not found
|
|
197
197
|
*/
|
|
198
|
-
getTile(z: number | string, x: number | string, y: number | string):
|
|
198
|
+
getTile(z: number | string, x: number | string, y: number | string): GeoJSONVTTile | null {
|
|
199
199
|
z = +z;
|
|
200
200
|
x = +x;
|
|
201
201
|
y = +y;
|
|
@@ -247,7 +247,7 @@ class GeoJSONVT {
|
|
|
247
247
|
* @internal
|
|
248
248
|
* @param features
|
|
249
249
|
*/
|
|
250
|
-
invalidateTiles(features:
|
|
250
|
+
invalidateTiles(features: GeoJSONVTInternalFeature[]) {
|
|
251
251
|
const options = this.options;
|
|
252
252
|
const {debug} = options;
|
|
253
253
|
|
|
@@ -374,16 +374,21 @@ export default function geojsonvt(data: GeoJSON.GeoJSON, options?: GeoJSONVTOpti
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
export type {
|
|
377
|
-
|
|
377
|
+
GeoJSONVTInternalFeature,
|
|
378
378
|
GeoJSONVTOptions,
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
GeoJSONVTInternalTile,
|
|
380
|
+
GeoJSONVTInternalTileFeature,
|
|
381
381
|
GeometryType,
|
|
382
382
|
PartialGeoJSONVTFeature,
|
|
383
383
|
GeoJSONVT,
|
|
384
384
|
GeometryTypeMap,
|
|
385
385
|
StartEndSizeArray,
|
|
386
|
-
|
|
386
|
+
GeoJSONVTTile,
|
|
387
|
+
GeoJSONVTFeature,
|
|
387
388
|
GeoJSONVTSourceDiff,
|
|
388
|
-
GeoJSONVTFeatureDiff
|
|
389
|
+
GeoJSONVTFeatureDiff,
|
|
390
|
+
GeoJSONVTFeaturePoint,
|
|
391
|
+
GeoJSONVTFeatureNonPoint,
|
|
392
|
+
GeoJSONVTInternalTileFeaturePoint,
|
|
393
|
+
GeoJSONVTInternalTileFeaturNonPoint
|
|
389
394
|
};
|
package/src/tile.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, StartEndSizeArray } from "./definitions";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type GeoJSONVTInternalTileFeaturePoint = {
|
|
4
4
|
id? : number | string | undefined;
|
|
5
|
-
type: 1
|
|
5
|
+
type: 1;
|
|
6
6
|
tags: GeoJSON.GeoJsonProperties | null;
|
|
7
|
-
geometry: number[]
|
|
7
|
+
geometry: number[];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type GeoJSONVTInternalTileFeaturNonPoint = {
|
|
11
|
+
id? : number | string | undefined;
|
|
12
|
+
type: 2 | 3;
|
|
13
|
+
tags: GeoJSON.GeoJsonProperties | null;
|
|
14
|
+
geometry: number[][];
|
|
15
|
+
}
|
|
16
|
+
export type GeoJSONVTInternalTileFeature = GeoJSONVTInternalTileFeaturePoint | GeoJSONVTInternalTileFeaturNonPoint;
|
|
17
|
+
|
|
18
|
+
export type GeoJSONVTInternalTile = {
|
|
19
|
+
features: GeoJSONVTInternalTileFeature[];
|
|
12
20
|
numPoints: number;
|
|
13
21
|
numSimplified: number;
|
|
14
22
|
numFeatures: number;
|
|
@@ -20,7 +28,7 @@ export type GeoJSONVTTile = {
|
|
|
20
28
|
minY: number;
|
|
21
29
|
maxX: number;
|
|
22
30
|
maxY: number;
|
|
23
|
-
source:
|
|
31
|
+
source: GeoJSONVTInternalFeature[] | null;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/**
|
|
@@ -32,15 +40,15 @@ export type GeoJSONVTTile = {
|
|
|
32
40
|
* @param options - the options object
|
|
33
41
|
* @returns the created tile
|
|
34
42
|
*/
|
|
35
|
-
export function createTile(features:
|
|
43
|
+
export function createTile(features: GeoJSONVTInternalFeature[], z: number, tx: number, ty: number, options: GeoJSONVTOptions): GeoJSONVTInternalTile {
|
|
36
44
|
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
37
45
|
|
|
38
46
|
const tile = {
|
|
39
|
-
features: [] as
|
|
47
|
+
features: [] as GeoJSONVTInternalTileFeature[],
|
|
40
48
|
numPoints: 0,
|
|
41
49
|
numSimplified: 0,
|
|
42
50
|
numFeatures: features.length,
|
|
43
|
-
source: null as
|
|
51
|
+
source: null as GeoJSONVTInternalFeature[] | null,
|
|
44
52
|
x: tx,
|
|
45
53
|
y: ty,
|
|
46
54
|
z,
|
|
@@ -58,62 +66,82 @@ export function createTile(features: GeoJSONVTFeature[], z: number, tx: number,
|
|
|
58
66
|
return tile;
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
function addFeature(tile:
|
|
62
|
-
const simplified: number[] | number[][] = [];
|
|
63
|
-
|
|
69
|
+
function addFeature(tile: GeoJSONVTInternalTile, feature: GeoJSONVTInternalFeature, tolerance: number, options: GeoJSONVTOptions) {
|
|
64
70
|
tile.minX = Math.min(tile.minX, feature.minX);
|
|
65
71
|
tile.minY = Math.min(tile.minY, feature.minY);
|
|
66
72
|
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
67
73
|
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
68
74
|
|
|
75
|
+
let tags = feature.tags || null;
|
|
76
|
+
|
|
77
|
+
let tileFeature: GeoJSONVTInternalTileFeature;
|
|
78
|
+
|
|
69
79
|
switch (feature.type) {
|
|
70
80
|
case 'Point':
|
|
71
|
-
case 'MultiPoint':
|
|
81
|
+
case 'MultiPoint': {
|
|
82
|
+
const geometry: number[] = [];
|
|
72
83
|
for (let i = 0; i < feature.geometry.length; i += 3) {
|
|
73
|
-
|
|
84
|
+
geometry.push(feature.geometry[i] , feature.geometry[i + 1]);
|
|
74
85
|
tile.numPoints++;
|
|
75
86
|
tile.numSimplified++;
|
|
76
87
|
}
|
|
88
|
+
if (!geometry.length) return;
|
|
89
|
+
tileFeature = {
|
|
90
|
+
type: 1,
|
|
91
|
+
tags: tags,
|
|
92
|
+
geometry: geometry
|
|
93
|
+
}
|
|
77
94
|
break;
|
|
78
|
-
|
|
79
|
-
case 'LineString':
|
|
80
|
-
|
|
95
|
+
}
|
|
96
|
+
case 'LineString': {
|
|
97
|
+
const geometry: number[][] = [];
|
|
98
|
+
addLine(geometry, feature.geometry, tile, tolerance, false, false);
|
|
99
|
+
if (!geometry.length) return;
|
|
100
|
+
if (options.lineMetrics) {
|
|
101
|
+
tags = {};
|
|
102
|
+
for (const key in feature.tags) tags[key] = feature.tags[key];
|
|
103
|
+
// HM TODO: replace with geojsonvt
|
|
104
|
+
tags['mapbox_clip_start'] = feature.geometry.start / feature.geometry.size;
|
|
105
|
+
tags['mapbox_clip_end'] = feature.geometry.end / feature.geometry.size;
|
|
106
|
+
}
|
|
107
|
+
tileFeature = {
|
|
108
|
+
type: 2,
|
|
109
|
+
tags: tags,
|
|
110
|
+
geometry: geometry
|
|
111
|
+
}
|
|
81
112
|
break;
|
|
82
|
-
|
|
113
|
+
}
|
|
83
114
|
case 'MultiLineString':
|
|
84
|
-
case 'Polygon':
|
|
115
|
+
case 'Polygon': {
|
|
116
|
+
const geometry: number[][] = [];
|
|
85
117
|
for (let i = 0; i < feature.geometry.length; i++) {
|
|
86
|
-
addLine(
|
|
118
|
+
addLine(geometry, feature.geometry[i], tile, tolerance, feature.type === 'Polygon', i === 0);
|
|
119
|
+
}
|
|
120
|
+
if (!geometry.length) return;
|
|
121
|
+
tileFeature = {
|
|
122
|
+
type: feature.type === 'Polygon' ? 3 : 2,
|
|
123
|
+
tags: tags,
|
|
124
|
+
geometry: geometry
|
|
87
125
|
}
|
|
88
126
|
break;
|
|
89
|
-
|
|
90
|
-
case 'MultiPolygon':
|
|
127
|
+
}
|
|
128
|
+
case 'MultiPolygon': {
|
|
129
|
+
const geometry: number[][] = [];
|
|
91
130
|
for (let k = 0; k < feature.geometry.length; k++) {
|
|
92
131
|
const polygon = feature.geometry[k];
|
|
93
132
|
for (let i = 0; i < polygon.length; i++) {
|
|
94
|
-
addLine(
|
|
133
|
+
addLine(geometry, polygon[i], tile, tolerance, true, i === 0);
|
|
95
134
|
}
|
|
96
135
|
}
|
|
136
|
+
if (!geometry.length) return;
|
|
137
|
+
tileFeature = {
|
|
138
|
+
type: 3,
|
|
139
|
+
tags: tags,
|
|
140
|
+
geometry: geometry
|
|
141
|
+
}
|
|
97
142
|
break;
|
|
143
|
+
}
|
|
98
144
|
}
|
|
99
|
-
if (!simplified.length) return;
|
|
100
|
-
|
|
101
|
-
let tags = feature.tags || null;
|
|
102
|
-
|
|
103
|
-
if (feature.type === 'LineString' && options.lineMetrics) {
|
|
104
|
-
tags = {};
|
|
105
|
-
for (const key in feature.tags) tags[key] = feature.tags[key];
|
|
106
|
-
// HM TODO: replace with geojsonvt
|
|
107
|
-
tags['mapbox_clip_start'] = feature.geometry.start / feature.geometry.size;
|
|
108
|
-
tags['mapbox_clip_end'] = feature.geometry.end / feature.geometry.size;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const tileFeature: GeoJSONVTTileFeature = {
|
|
112
|
-
geometry: simplified,
|
|
113
|
-
type: feature.type === 'Polygon' || feature.type === 'MultiPolygon' ? 3 :
|
|
114
|
-
(feature.type === 'LineString' || feature.type === 'MultiLineString' ? 2 : 1),
|
|
115
|
-
tags
|
|
116
|
-
};
|
|
117
145
|
|
|
118
146
|
if (feature.id !== null) {
|
|
119
147
|
tileFeature.id = feature.id;
|
|
@@ -122,7 +150,7 @@ function addFeature(tile: GeoJSONVTTile, feature: GeoJSONVTFeature, tolerance: n
|
|
|
122
150
|
tile.features.push(tileFeature);
|
|
123
151
|
}
|
|
124
152
|
|
|
125
|
-
function addLine(result: number[][], geom: StartEndSizeArray, tile:
|
|
153
|
+
function addLine(result: number[][], geom: StartEndSizeArray, tile: GeoJSONVTInternalTile, tolerance: number, isPolygon: boolean, isOuter: boolean) {
|
|
126
154
|
const sqTolerance = tolerance * tolerance;
|
|
127
155
|
|
|
128
156
|
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) {
|
package/src/transform.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GeoJSONVTInternalTile } from "./tile";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type GeoJSONVTFeaturePoint = {
|
|
4
|
+
id? : number | string | undefined;
|
|
5
|
+
type: 1;
|
|
6
|
+
tags: GeoJSON.GeoJsonProperties | null;
|
|
7
|
+
geometry: [number, number][]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type GeoJSONVTFeatureNonPoint = {
|
|
11
|
+
id? : number | string | undefined;
|
|
12
|
+
type: 2 | 3;
|
|
13
|
+
tags: GeoJSON.GeoJsonProperties | null;
|
|
14
|
+
geometry: [number, number][][]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type GeoJSONVTFeature = GeoJSONVTFeaturePoint | GeoJSONVTFeatureNonPoint;
|
|
18
|
+
|
|
19
|
+
export type GeoJSONVTTile = GeoJSONVTInternalTile & {
|
|
4
20
|
transformed: true;
|
|
5
|
-
|
|
21
|
+
features: GeoJSONVTFeature[]
|
|
6
22
|
}
|
|
7
23
|
|
|
8
24
|
/**
|
|
@@ -12,9 +28,9 @@ export type GeoJSONVTTransformedTile = GeoJSONVTTile & {
|
|
|
12
28
|
* @param extent - the tile extent (usually 4096)
|
|
13
29
|
* @returns the transformed tile
|
|
14
30
|
*/
|
|
15
|
-
export function transformTile(tile:
|
|
31
|
+
export function transformTile(tile: GeoJSONVTInternalTile, extent: number): GeoJSONVTTile {
|
|
16
32
|
if (tile.transformed) {
|
|
17
|
-
return tile as
|
|
33
|
+
return tile as GeoJSONVTTile;
|
|
18
34
|
}
|
|
19
35
|
|
|
20
36
|
const z2 = 1 << tile.z;
|
|
@@ -22,29 +38,28 @@ export function transformTile(tile: GeoJSONVTTile, extent: number): GeoJSONVTTra
|
|
|
22
38
|
const ty = tile.y;
|
|
23
39
|
|
|
24
40
|
for (const feature of tile.features) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (type === 1) {
|
|
31
|
-
for (let j = 0; j < geom.length; j += 2) {
|
|
32
|
-
(feature.geometry as [number, number][]).push(transformPoint(geom[j] as number, geom[j + 1] as number, extent, z2, tx, ty));
|
|
41
|
+
if (feature.type === 1) {
|
|
42
|
+
const pointGeometry: [number, number][] = []
|
|
43
|
+
for (let j = 0; j < feature.geometry.length; j += 2) {
|
|
44
|
+
pointGeometry.push(transformPoint(feature.geometry[j], feature.geometry[j + 1], extent, z2, tx, ty));
|
|
33
45
|
}
|
|
46
|
+
(feature as unknown as GeoJSONVTFeaturePoint).geometry = pointGeometry;
|
|
34
47
|
continue;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
const geometry: [number, number][][] = [];
|
|
51
|
+
for (const singleGeom of feature.geometry) {
|
|
38
52
|
const ring: [number, number][] = [];
|
|
39
53
|
for (let k = 0; k < singleGeom.length; k += 2) {
|
|
40
54
|
ring.push(transformPoint(singleGeom[k], singleGeom[k + 1], extent, z2, tx, ty));
|
|
41
55
|
}
|
|
42
|
-
|
|
56
|
+
geometry.push(ring);
|
|
43
57
|
}
|
|
58
|
+
(feature as unknown as GeoJSONVTFeatureNonPoint).geometry = geometry;
|
|
44
59
|
}
|
|
45
60
|
tile.transformed = true;
|
|
46
61
|
|
|
47
|
-
return tile as
|
|
62
|
+
return tile as GeoJSONVTTile;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
function transformPoint(x: number, y: number, extent: number, z2: number, tx: number, ty: number): [number, number] {
|
package/src/wrap.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import {clip} from './clip';
|
|
3
|
-
import type {
|
|
3
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, StartEndSizeArray } from './definitions';
|
|
4
4
|
import {createFeature} from './feature';
|
|
5
5
|
|
|
6
|
-
export function wrap(features:
|
|
6
|
+
export function wrap(features: GeoJSONVTInternalFeature[], options: GeoJSONVTOptions): GeoJSONVTInternalFeature[] {
|
|
7
7
|
const buffer = options.buffer / options.extent;
|
|
8
8
|
let merged = features;
|
|
9
9
|
|
|
@@ -20,7 +20,7 @@ export function wrap(features: GeoJSONVTFeature[], options: GeoJSONVTOptions): G
|
|
|
20
20
|
return merged;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function shiftFeatureCoords(features:
|
|
23
|
+
function shiftFeatureCoords(features: GeoJSONVTInternalFeature[], offset: number): GeoJSONVTInternalFeature[] {
|
|
24
24
|
const newFeatures = [];
|
|
25
25
|
|
|
26
26
|
for (const feature of features) {
|