@loaders.gl/mvt 4.2.1 → 4.3.0-alpha.2
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/dist/dist.dev.js +1784 -847
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +713 -640
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/parse-mvt.d.ts +2 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +15 -45
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/types.d.ts +1 -39
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +83 -0
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
- package/dist/lib/utils/geometry-utils.js +206 -0
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +72 -0
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/vector-tile/vector-tile-feature.js +342 -0
- package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
- package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
- package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/clip.d.ts +3 -3
- package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
- package/dist/lib/vector-tiler/convert.d.ts +18 -0
- package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/convert.js +8 -1
- package/dist/lib/vector-tiler/feature.d.ts +3 -0
- package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/tile.d.ts +4 -4
- package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform.d.ts +7 -0
- package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/wrap.d.ts +2 -2
- package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
- package/dist/mvt-loader.d.ts +19 -8
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +3 -2
- package/dist/mvt-source.d.ts +4 -4
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +7 -7
- package/dist/mvt-worker.js +1244 -762
- package/dist/table-tile-source.d.ts +118 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +370 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +3 -3
- package/src/lib/parse-mvt.ts +28 -66
- package/src/lib/parse-tilejson.ts +5 -5
- package/src/lib/types.ts +1 -39
- package/src/lib/utils/geometry-utils.ts +234 -0
- package/src/lib/vector-tile/vector-tile-feature.ts +416 -0
- package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
- package/src/lib/{geojson-tiler → vector-tiler}/clip.ts +4 -4
- package/src/lib/{geojson-tiler → vector-tiler}/convert.ts +19 -9
- package/src/lib/{geojson-tiler → vector-tiler}/feature.ts +3 -3
- package/src/lib/{geojson-tiler → vector-tiler}/tile.ts +10 -10
- package/src/lib/{geojson-tiler → vector-tiler}/transform.ts +2 -2
- package/src/lib/{geojson-tiler → vector-tiler}/wrap.ts +5 -5
- package/src/mvt-loader.ts +14 -6
- package/src/mvt-source.ts +9 -10
- package/src/table-tile-source.ts +508 -0
- package/dist/helpers/binary-util-functions.d.ts +0 -35
- package/dist/helpers/binary-util-functions.d.ts.map +0 -1
- package/dist/helpers/binary-util-functions.js +0 -114
- package/dist/helpers/mapbox-util-functions.d.ts +0 -29
- package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
- package/dist/helpers/mapbox-util-functions.js +0 -78
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -41
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
- package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/convert.d.ts +0 -10
- package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/feature.d.ts +0 -3
- package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js +0 -209
- package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/transform.d.ts +0 -7
- package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
- package/src/helpers/binary-util-functions.ts +0 -125
- package/src/helpers/mapbox-util-functions.ts +0 -82
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
- package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
- package/src/lib/geojson-tiler/geojson-tiler.ts +0 -283
- package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
- /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
- /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/clip.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/feature.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/tile.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/transform.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/wrap.js +0 -0
- /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
- /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
- /package/src/lib/{geojson-tiler → vector-tiler}/LICENSE +0 -0
- /package/src/lib/{geojson-tiler → vector-tiler}/simplify.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-tiler.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/geojson-tiler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,WAAW,EAAE,kBAAkB,EAAC,kBAAe;AAQ5D,kCAAkC;AAClC,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,qCAAqC,CAAC;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC,iCAAiC,CAAC;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC,sDAAsD,CAAC;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC,sDAAsD,CAAC;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC,kBAAkB,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC,+BAA+B,CAAC;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC,wCAAwC,CAAC;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC,8DAA8D,CAAC;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC,qEAAqE,CAAC;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC,gCAAgC,CAAC;CACjD,CAAC;AAgBF,qBAAa,YAAY;IACvB,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAGvC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAM;IACxC,UAAU,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,EAAE,CAAM;IAErD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACnC,KAAK,EAAE,MAAM,CAAK;gBAEN,IAAI,KAAA,EAAE,OAAO,CAAC,EAAE,mBAAmB;IA6C/C;;;;;;OAMG;IAEH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAkD5D;;;;;;;OAOG;IAEH,SAAS,CACP,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,EAAE,CAAC,EAAE,MAAM,EACX,EAAE,CAAC,EAAE,MAAM,EACX,EAAE,CAAC,EAAE,MAAM,GACV,IAAI;CAyGR"}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
import { convert } from "./convert.js"; // GeoJSON conversion and preprocessing
|
|
6
|
-
import { clip } from "./clip.js"; // stripe clipping algorithm
|
|
7
|
-
import { wrap } from "./wrap.js"; // date line processing
|
|
8
|
-
import { transformTile } from "./transform.js"; // coordinate transformation
|
|
9
|
-
import { createTile } from "./tile.js"; // final simplified tile generation
|
|
10
|
-
const DEFAULT_OPTIONS = {
|
|
11
|
-
maxZoom: 14, // max zoom to preserve detail on
|
|
12
|
-
indexMaxZoom: 5, // max zoom in the tile index
|
|
13
|
-
indexMaxPoints: 100000, // max number of points per tile in the tile index
|
|
14
|
-
tolerance: 3, // simplification tolerance (higher means simpler)
|
|
15
|
-
extent: 4096, // tile extent
|
|
16
|
-
buffer: 64, // tile buffer on each side
|
|
17
|
-
lineMetrics: false, // whether to calculate line metrics
|
|
18
|
-
// @ts-expect-error Ensures all these required params have defaults
|
|
19
|
-
promoteId: undefined, // name of a feature property to be promoted to feature.id
|
|
20
|
-
generateId: false, // whether to generate feature ids. Cannot be used with promoteId
|
|
21
|
-
debug: 0 // logging level (0, 1 or 2)
|
|
22
|
-
};
|
|
23
|
-
export class GeoJSONTiler {
|
|
24
|
-
options;
|
|
25
|
-
// tiles and tileCoords are part of the public API
|
|
26
|
-
tiles = {};
|
|
27
|
-
tileCoords = [];
|
|
28
|
-
stats = {};
|
|
29
|
-
total = 0;
|
|
30
|
-
constructor(data, options) {
|
|
31
|
-
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
32
|
-
options = this.options;
|
|
33
|
-
const debug = options.debug;
|
|
34
|
-
if (debug)
|
|
35
|
-
console.time('preprocess data');
|
|
36
|
-
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
37
|
-
throw new Error('maxZoom should be in the 0-24 range');
|
|
38
|
-
}
|
|
39
|
-
if (options.promoteId && this.options.generateId) {
|
|
40
|
-
throw new Error('promoteId and generateId cannot be used together.');
|
|
41
|
-
}
|
|
42
|
-
// projects and adds simplification info
|
|
43
|
-
let features = convert(data, options);
|
|
44
|
-
if (debug) {
|
|
45
|
-
console.timeEnd('preprocess data');
|
|
46
|
-
console.log('index: maxZoom: %d, maxPoints: %d', options.indexMaxZoom, options.indexMaxPoints);
|
|
47
|
-
console.time('generate tiles');
|
|
48
|
-
}
|
|
49
|
-
// wraps features (ie extreme west and extreme east)
|
|
50
|
-
features = wrap(features, this.options);
|
|
51
|
-
// start slicing from the top tile down
|
|
52
|
-
if (features.length) {
|
|
53
|
-
this.splitTile(features, 0, 0, 0);
|
|
54
|
-
}
|
|
55
|
-
if (debug) {
|
|
56
|
-
if (features.length) {
|
|
57
|
-
console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
58
|
-
}
|
|
59
|
-
console.timeEnd('generate tiles');
|
|
60
|
-
console.log('tiles generated:', this.total, JSON.stringify(this.stats));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get a tile at the specified index
|
|
65
|
-
* @param z
|
|
66
|
-
* @param x
|
|
67
|
-
* @param y
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line complexity, max-statements
|
|
71
|
-
getTile(z, x, y) {
|
|
72
|
-
// z = +z;
|
|
73
|
-
// x = +x;
|
|
74
|
-
// y = +y;
|
|
75
|
-
const { extent, debug } = this.options;
|
|
76
|
-
if (z < 0 || z > 24) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const z2 = 1 << z;
|
|
80
|
-
x = (x + z2) & (z2 - 1); // wrap tile x coordinate
|
|
81
|
-
const id = toID(z, x, y);
|
|
82
|
-
if (this.tiles[id]) {
|
|
83
|
-
return transformTile(this.tiles[id], extent);
|
|
84
|
-
}
|
|
85
|
-
if (debug > 1)
|
|
86
|
-
console.log('drilling down to z%d-%d-%d', z, x, y);
|
|
87
|
-
let z0 = z;
|
|
88
|
-
let x0 = x;
|
|
89
|
-
let y0 = y;
|
|
90
|
-
let parent;
|
|
91
|
-
while (!parent && z0 > 0) {
|
|
92
|
-
z0--;
|
|
93
|
-
x0 = x0 >> 1;
|
|
94
|
-
y0 = y0 >> 1;
|
|
95
|
-
parent = this.tiles[toID(z0, x0, y0)];
|
|
96
|
-
}
|
|
97
|
-
if (!parent || !parent.source) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
// if we found a parent tile containing the original geometry, we can drill down from it
|
|
101
|
-
if (debug > 1) {
|
|
102
|
-
console.log('found parent tile z%d-%d-%d', z0, x0, y0);
|
|
103
|
-
console.time('drilling down');
|
|
104
|
-
}
|
|
105
|
-
this.splitTile(parent.source, z0, x0, y0, z, x, y);
|
|
106
|
-
if (debug > 1) {
|
|
107
|
-
console.timeEnd('drilling down');
|
|
108
|
-
}
|
|
109
|
-
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* splits features from a parent tile to sub-tiles.
|
|
113
|
-
* @param z, x, and y are the coordinates of the parent tile
|
|
114
|
-
* @param cz, cx, and cy are the coordinates of the target tile
|
|
115
|
-
*
|
|
116
|
-
* If no target tile is specified, splitting stops when we reach the maximum
|
|
117
|
-
* zoom or the number of points is low as specified in the options.
|
|
118
|
-
*/
|
|
119
|
-
// eslint-disable-next-line max-params, max-statements, complexity
|
|
120
|
-
splitTile(features, z, x, y, cz, cx, cy) {
|
|
121
|
-
const stack = [features, z, x, y];
|
|
122
|
-
const options = this.options;
|
|
123
|
-
const debug = options.debug;
|
|
124
|
-
// avoid recursion by using a processing queue
|
|
125
|
-
while (stack.length) {
|
|
126
|
-
y = stack.pop();
|
|
127
|
-
x = stack.pop();
|
|
128
|
-
z = stack.pop();
|
|
129
|
-
features = stack.pop();
|
|
130
|
-
const z2 = 1 << z;
|
|
131
|
-
const id = toID(z, x, y);
|
|
132
|
-
let tile = this.tiles[id];
|
|
133
|
-
if (!tile) {
|
|
134
|
-
if (debug > 1) {
|
|
135
|
-
console.time('creation');
|
|
136
|
-
}
|
|
137
|
-
tile = this.tiles[id] = createTile(features, z, x, y, options);
|
|
138
|
-
this.tileCoords.push({ z, x, y });
|
|
139
|
-
if (debug) {
|
|
140
|
-
if (debug > 1) {
|
|
141
|
-
console.log('tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
142
|
-
console.timeEnd('creation');
|
|
143
|
-
}
|
|
144
|
-
const key = `z${z}`;
|
|
145
|
-
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
146
|
-
this.total++;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// save reference to original geometry in tile so that we can drill down later if we stop now
|
|
150
|
-
tile.source = features;
|
|
151
|
-
// if it's the first-pass tiling
|
|
152
|
-
if (cz === undefined) {
|
|
153
|
-
// stop tiling if we reached max zoom, or if the tile is too simple
|
|
154
|
-
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
155
|
-
continue;
|
|
156
|
-
// if a drilldown to a specific tile
|
|
157
|
-
}
|
|
158
|
-
else if (z === options.maxZoom || z === cz) {
|
|
159
|
-
// stop tiling if we reached base zoom or our target tile zoom
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
else if (cz !== undefined) {
|
|
163
|
-
// stop tiling if it's not an ancestor of the target tile
|
|
164
|
-
const zoomSteps = cz - z;
|
|
165
|
-
// @ts-expect-error TODO fix the types of cx cy
|
|
166
|
-
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
// if we slice further down, no need to keep source geometry
|
|
170
|
-
tile.source = null;
|
|
171
|
-
if (features.length === 0)
|
|
172
|
-
continue;
|
|
173
|
-
if (debug > 1)
|
|
174
|
-
console.time('clipping');
|
|
175
|
-
// values we'll use for clipping
|
|
176
|
-
const k1 = (0.5 * options.buffer) / options.extent;
|
|
177
|
-
const k2 = 0.5 - k1;
|
|
178
|
-
const k3 = 0.5 + k1;
|
|
179
|
-
const k4 = 1 + k1;
|
|
180
|
-
let tl = null;
|
|
181
|
-
let bl = null;
|
|
182
|
-
let tr = null;
|
|
183
|
-
let br = null;
|
|
184
|
-
let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
|
|
185
|
-
let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
|
|
186
|
-
// @ts-expect-error - unclear why this is needed?
|
|
187
|
-
features = null;
|
|
188
|
-
if (left) {
|
|
189
|
-
tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
190
|
-
bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
191
|
-
left = null;
|
|
192
|
-
}
|
|
193
|
-
if (right) {
|
|
194
|
-
tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
195
|
-
br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
196
|
-
right = null;
|
|
197
|
-
}
|
|
198
|
-
if (debug > 1)
|
|
199
|
-
console.timeEnd('clipping');
|
|
200
|
-
stack.push(tl || [], z + 1, x * 2, y * 2);
|
|
201
|
-
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
|
|
202
|
-
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
|
|
203
|
-
stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function toID(z, x, y) {
|
|
208
|
-
return ((1 << z) * y + x) * 32 + z;
|
|
209
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/simplify.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAkCjG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAqB9F"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { GeoJSONTile } from "./tile.js";
|
|
2
|
-
/**
|
|
3
|
-
* Transforms the coordinates of each feature in the given tile from
|
|
4
|
-
* mercator-projected space into (extent x extent) tile space.
|
|
5
|
-
*/
|
|
6
|
-
export declare function transformTile(tile: GeoJSONTile, extent: number): GeoJSONTile;
|
|
7
|
-
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,kBAAe;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Protobuf from 'pbf';
|
|
2
|
-
import { MVTMapboxCoordinates, MVTMapboxGeometry } from "../types.js";
|
|
3
|
-
export declare class VectorTileFeature {
|
|
4
|
-
properties: {
|
|
5
|
-
[x: string]: string | number | boolean | null;
|
|
6
|
-
};
|
|
7
|
-
extent: any;
|
|
8
|
-
type: number;
|
|
9
|
-
id: number | null;
|
|
10
|
-
_pbf: Protobuf;
|
|
11
|
-
_geometry: number;
|
|
12
|
-
_keys: string[];
|
|
13
|
-
_values: (string | number | boolean | null)[];
|
|
14
|
-
static get types(): string[];
|
|
15
|
-
constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[]);
|
|
16
|
-
loadGeometry(): MVTMapboxGeometry;
|
|
17
|
-
bbox(): number[];
|
|
18
|
-
_toGeoJSON(transform: any): MVTMapboxCoordinates;
|
|
19
|
-
toGeoJSON(options: {
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
z: number;
|
|
23
|
-
} | ((data: number[], feature: {
|
|
24
|
-
extent: any;
|
|
25
|
-
}) => void)): MVTMapboxCoordinates;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=vector-tile-feature.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAKA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,oBAAiB;AAGjE,qBAAa,iBAAiB;IAC5B,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,MAAM,KAAK,KAAK,aAEf;gBAGC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE;IAkB9C,YAAY,IAAI,iBAAiB;IA+CjC,IAAI;IAsCJ,UAAU,CAAC,SAAS,KAAA;IAuDpB,SAAS,CACP,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,oBAAoB;CAmBxB"}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
import { readFeature, classifyRings } from "../../helpers/mapbox-util-functions.js";
|
|
5
|
-
export class VectorTileFeature {
|
|
6
|
-
properties;
|
|
7
|
-
extent;
|
|
8
|
-
type;
|
|
9
|
-
id;
|
|
10
|
-
_pbf;
|
|
11
|
-
_geometry;
|
|
12
|
-
_keys;
|
|
13
|
-
_values;
|
|
14
|
-
static get types() {
|
|
15
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
16
|
-
}
|
|
17
|
-
constructor(pbf, end, extent, keys, values) {
|
|
18
|
-
// Public
|
|
19
|
-
this.properties = {};
|
|
20
|
-
this.extent = extent;
|
|
21
|
-
this.type = 0;
|
|
22
|
-
this.id = null;
|
|
23
|
-
// Private
|
|
24
|
-
this._pbf = pbf;
|
|
25
|
-
this._geometry = -1;
|
|
26
|
-
this._keys = keys;
|
|
27
|
-
this._values = values;
|
|
28
|
-
pbf.readFields(readFeature, this, end);
|
|
29
|
-
}
|
|
30
|
-
// eslint-disable-next-line complexity, max-statements
|
|
31
|
-
loadGeometry() {
|
|
32
|
-
const pbf = this._pbf;
|
|
33
|
-
pbf.pos = this._geometry;
|
|
34
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
35
|
-
let cmd = 1;
|
|
36
|
-
let length = 0;
|
|
37
|
-
let x = 0;
|
|
38
|
-
let y = 0;
|
|
39
|
-
const lines = [];
|
|
40
|
-
let line;
|
|
41
|
-
while (pbf.pos < end) {
|
|
42
|
-
if (length <= 0) {
|
|
43
|
-
const cmdLen = pbf.readVarint();
|
|
44
|
-
cmd = cmdLen & 0x7;
|
|
45
|
-
length = cmdLen >> 3;
|
|
46
|
-
}
|
|
47
|
-
length--;
|
|
48
|
-
if (cmd === 1 || cmd === 2) {
|
|
49
|
-
x += pbf.readSVarint();
|
|
50
|
-
y += pbf.readSVarint();
|
|
51
|
-
if (cmd === 1) {
|
|
52
|
-
// moveTo
|
|
53
|
-
if (line)
|
|
54
|
-
lines.push(line);
|
|
55
|
-
line = [];
|
|
56
|
-
}
|
|
57
|
-
if (line)
|
|
58
|
-
line.push([x, y]);
|
|
59
|
-
}
|
|
60
|
-
else if (cmd === 7) {
|
|
61
|
-
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
62
|
-
if (line) {
|
|
63
|
-
line.push(line[0].slice()); // closePolygon
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new Error(`unknown command ${cmd}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (line)
|
|
71
|
-
lines.push(line);
|
|
72
|
-
return lines;
|
|
73
|
-
}
|
|
74
|
-
// eslint-disable-next-line max-statements
|
|
75
|
-
bbox() {
|
|
76
|
-
const pbf = this._pbf;
|
|
77
|
-
pbf.pos = this._geometry;
|
|
78
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
79
|
-
let cmd = 1;
|
|
80
|
-
let length = 0;
|
|
81
|
-
let x = 0;
|
|
82
|
-
let y = 0;
|
|
83
|
-
let x1 = Infinity;
|
|
84
|
-
let x2 = -Infinity;
|
|
85
|
-
let y1 = Infinity;
|
|
86
|
-
let y2 = -Infinity;
|
|
87
|
-
while (pbf.pos < end) {
|
|
88
|
-
if (length <= 0) {
|
|
89
|
-
const cmdLen = pbf.readVarint();
|
|
90
|
-
cmd = cmdLen & 0x7;
|
|
91
|
-
length = cmdLen >> 3;
|
|
92
|
-
}
|
|
93
|
-
length--;
|
|
94
|
-
if (cmd === 1 || cmd === 2) {
|
|
95
|
-
x += pbf.readSVarint();
|
|
96
|
-
y += pbf.readSVarint();
|
|
97
|
-
if (x < x1)
|
|
98
|
-
x1 = x;
|
|
99
|
-
if (x > x2)
|
|
100
|
-
x2 = x;
|
|
101
|
-
if (y < y1)
|
|
102
|
-
y1 = y;
|
|
103
|
-
if (y > y2)
|
|
104
|
-
y2 = y;
|
|
105
|
-
}
|
|
106
|
-
else if (cmd !== 7) {
|
|
107
|
-
throw new Error(`unknown command ${cmd}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return [x1, y1, x2, y2];
|
|
111
|
-
}
|
|
112
|
-
_toGeoJSON(transform) {
|
|
113
|
-
let coords = this.loadGeometry();
|
|
114
|
-
let type = VectorTileFeature.types[this.type];
|
|
115
|
-
let i;
|
|
116
|
-
let j;
|
|
117
|
-
// eslint-disable-next-line default-case
|
|
118
|
-
switch (this.type) {
|
|
119
|
-
case 1:
|
|
120
|
-
const points = [];
|
|
121
|
-
for (i = 0; i < coords.length; i++) {
|
|
122
|
-
points[i] = coords[i][0];
|
|
123
|
-
}
|
|
124
|
-
coords = points;
|
|
125
|
-
transform(coords, this);
|
|
126
|
-
break;
|
|
127
|
-
case 2:
|
|
128
|
-
for (i = 0; i < coords.length; i++) {
|
|
129
|
-
transform(coords[i], this);
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
case 3:
|
|
133
|
-
coords = classifyRings(coords);
|
|
134
|
-
for (i = 0; i < coords.length; i++) {
|
|
135
|
-
for (j = 0; j < coords[i].length; j++) {
|
|
136
|
-
transform(coords[i][j], this);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
if (coords.length === 1) {
|
|
142
|
-
coords = coords[0];
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
type = `Multi${type}`;
|
|
146
|
-
}
|
|
147
|
-
const result = {
|
|
148
|
-
type: 'Feature',
|
|
149
|
-
geometry: {
|
|
150
|
-
type,
|
|
151
|
-
coordinates: coords
|
|
152
|
-
},
|
|
153
|
-
properties: this.properties
|
|
154
|
-
};
|
|
155
|
-
if (this.id !== null) {
|
|
156
|
-
result.id = this.id;
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
toGeoJSON(options) {
|
|
161
|
-
if (typeof options === 'function') {
|
|
162
|
-
return this._toGeoJSON(options);
|
|
163
|
-
}
|
|
164
|
-
const { x, y, z } = options;
|
|
165
|
-
const size = this.extent * Math.pow(2, z);
|
|
166
|
-
const x0 = this.extent * x;
|
|
167
|
-
const y0 = this.extent * y;
|
|
168
|
-
function project(line) {
|
|
169
|
-
for (let j = 0; j < line.length; j++) {
|
|
170
|
-
const p = line[j];
|
|
171
|
-
p[0] = ((p[0] + x0) * 360) / size - 180;
|
|
172
|
-
const y2 = 180 - ((p[1] + y0) * 360) / size;
|
|
173
|
-
p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return this._toGeoJSON(project);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AAExD,qBAAa,eAAe;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;OAIG;IAEH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB;CAUtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,qBAAa,UAAU;IACrB,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import Protobuf from 'pbf';
|
|
6
|
-
import {getPolygonSignedArea} from '@math.gl/polygon';
|
|
7
|
-
import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
|
|
8
|
-
import {BinaryVectorTileFeature} from '../lib/binary-vector-tile/vector-tile-feature';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Classifies an array of rings into polygons with outer rings and holes
|
|
12
|
-
* The function also detects holes which have zero area and
|
|
13
|
-
* removes them. In doing so it modifies the input
|
|
14
|
-
* `geom.data` array to remove the unneeded data
|
|
15
|
-
*
|
|
16
|
-
* @param geometry
|
|
17
|
-
* @returns object
|
|
18
|
-
*/
|
|
19
|
-
// eslint-disable-next-line max-statements
|
|
20
|
-
export function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {
|
|
21
|
-
const len = geom.indices.length;
|
|
22
|
-
const type = 'Polygon';
|
|
23
|
-
|
|
24
|
-
if (len <= 1) {
|
|
25
|
-
return {
|
|
26
|
-
type,
|
|
27
|
-
data: geom.data,
|
|
28
|
-
areas: [[getPolygonSignedArea(geom.data)]],
|
|
29
|
-
indices: [geom.indices]
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const areas: any[] = [];
|
|
34
|
-
const polygons: any[] = [];
|
|
35
|
-
let ringAreas: number[] = [];
|
|
36
|
-
let polygon: number[] = [];
|
|
37
|
-
let ccw: boolean | undefined;
|
|
38
|
-
let offset = 0;
|
|
39
|
-
|
|
40
|
-
for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {
|
|
41
|
-
startIndex = geom.indices[i] - offset;
|
|
42
|
-
|
|
43
|
-
endIndex = geom.indices[i + 1] - offset || geom.data.length;
|
|
44
|
-
const shape = geom.data.slice(startIndex, endIndex);
|
|
45
|
-
const area = getPolygonSignedArea(shape);
|
|
46
|
-
|
|
47
|
-
if (area === 0) {
|
|
48
|
-
// This polygon has no area, so remove it from the shape
|
|
49
|
-
// Remove the section from the data array
|
|
50
|
-
const before = geom.data.slice(0, startIndex);
|
|
51
|
-
const after = geom.data.slice(endIndex);
|
|
52
|
-
geom.data = before.concat(after);
|
|
53
|
-
|
|
54
|
-
// Need to offset any remaining indices as we have
|
|
55
|
-
// modified the data buffer
|
|
56
|
-
offset += endIndex - startIndex;
|
|
57
|
-
|
|
58
|
-
// Do not add this index to the output and process next shape
|
|
59
|
-
continue; // eslint-disable-line no-continue
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (ccw === undefined) ccw = area < 0;
|
|
63
|
-
|
|
64
|
-
if (ccw === area < 0) {
|
|
65
|
-
if (polygon.length) {
|
|
66
|
-
areas.push(ringAreas);
|
|
67
|
-
polygons.push(polygon);
|
|
68
|
-
}
|
|
69
|
-
polygon = [startIndex];
|
|
70
|
-
ringAreas = [area];
|
|
71
|
-
} else {
|
|
72
|
-
ringAreas.push(area);
|
|
73
|
-
polygon.push(startIndex);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (ringAreas) areas.push(ringAreas);
|
|
77
|
-
if (polygon.length) polygons.push(polygon);
|
|
78
|
-
|
|
79
|
-
return {type, areas, indices: polygons, data: geom.data};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param data
|
|
85
|
-
* @param x0
|
|
86
|
-
* @param y0
|
|
87
|
-
* @param size
|
|
88
|
-
*/
|
|
89
|
-
export function project(data: number[], x0: number, y0: number, size: number): void {
|
|
90
|
-
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
91
|
-
data[j] = ((data[j] + x0) * 360) / size - 180;
|
|
92
|
-
const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
|
|
93
|
-
data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* All code below is unchanged from the original Mapbox implemenation
|
|
99
|
-
*
|
|
100
|
-
* @param tag
|
|
101
|
-
* @param feature
|
|
102
|
-
* @param pbf
|
|
103
|
-
*/
|
|
104
|
-
export function readFeature(tag: number, feature?: BinaryVectorTileFeature, pbf?: Protobuf): void {
|
|
105
|
-
if (feature && pbf) {
|
|
106
|
-
if (tag === 1) feature.id = pbf.readVarint();
|
|
107
|
-
else if (tag === 2) readTag(pbf, feature);
|
|
108
|
-
else if (tag === 3) feature.type = pbf.readVarint();
|
|
109
|
-
else if (tag === 4) feature._geometry = pbf.pos;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param pbf
|
|
115
|
-
* @param feature
|
|
116
|
-
*/
|
|
117
|
-
export function readTag(pbf: Protobuf, feature: BinaryVectorTileFeature): void {
|
|
118
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
119
|
-
|
|
120
|
-
while (pbf.pos < end) {
|
|
121
|
-
const key = feature._keys[pbf.readVarint()];
|
|
122
|
-
const value = feature._values[pbf.readVarint()];
|
|
123
|
-
feature.properties[key] = value;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import Protobuf from 'pbf';
|
|
6
|
-
import {MVTMapboxGeometry} from '../lib/types';
|
|
7
|
-
import {VectorTileFeature} from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Classifies an array of rings into polygons with outer rings and holes
|
|
11
|
-
* @param rings
|
|
12
|
-
* @returns polygons
|
|
13
|
-
*/
|
|
14
|
-
export function classifyRings(rings: MVTMapboxGeometry) {
|
|
15
|
-
const len = rings.length;
|
|
16
|
-
|
|
17
|
-
if (len <= 1) return [rings];
|
|
18
|
-
|
|
19
|
-
const polygons: number[][][] = [];
|
|
20
|
-
let polygon: number[][] | undefined;
|
|
21
|
-
let ccw: boolean | undefined;
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < len; i++) {
|
|
24
|
-
const area = signedArea(rings[i]);
|
|
25
|
-
if (area === 0) continue; // eslint-disable-line no-continue
|
|
26
|
-
|
|
27
|
-
if (ccw === undefined) ccw = area < 0;
|
|
28
|
-
|
|
29
|
-
if (ccw === area < 0) {
|
|
30
|
-
if (polygon) polygons.push(polygon);
|
|
31
|
-
polygon = [rings[i]];
|
|
32
|
-
} else if (polygon) polygon.push(rings[i]);
|
|
33
|
-
}
|
|
34
|
-
if (polygon) polygons.push(polygon);
|
|
35
|
-
|
|
36
|
-
return polygons;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param ring
|
|
42
|
-
* @returns sum
|
|
43
|
-
*/
|
|
44
|
-
export function signedArea(ring: number[][]) {
|
|
45
|
-
let sum = 0;
|
|
46
|
-
for (let i = 0, j = ring.length - 1, p1: number[], p2: number[]; i < ring.length; j = i++) {
|
|
47
|
-
p1 = ring[i];
|
|
48
|
-
p2 = ring[j];
|
|
49
|
-
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
50
|
-
}
|
|
51
|
-
return sum;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param tag
|
|
57
|
-
* @param feature
|
|
58
|
-
* @param pbf
|
|
59
|
-
*/
|
|
60
|
-
export function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void {
|
|
61
|
-
if (feature && pbf) {
|
|
62
|
-
if (tag === 1) feature.id = pbf.readVarint();
|
|
63
|
-
else if (tag === 2) readTag(pbf, feature);
|
|
64
|
-
else if (tag === 3) feature.type = pbf.readVarint();
|
|
65
|
-
else if (tag === 4) feature._geometry = pbf.pos;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param pbf
|
|
72
|
-
* @param feature
|
|
73
|
-
*/
|
|
74
|
-
export function readTag(pbf: Protobuf, feature: VectorTileFeature): void {
|
|
75
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
76
|
-
|
|
77
|
-
while (pbf.pos < end) {
|
|
78
|
-
const key = feature._keys[pbf.readVarint()];
|
|
79
|
-
const value = feature._values[pbf.readVarint()];
|
|
80
|
-
feature.properties[key] = value;
|
|
81
|
-
}
|
|
82
|
-
}
|