@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.3
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 +1289 -807
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +923 -773
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.js +2 -30
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +38 -1
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.js +65 -6
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
- package/dist/lib/{geojsonvt/clip.d.ts → vector-tiler/features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/clip.js → vector-tiler/features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/features/convert-feature.d.ts +18 -0
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/{geojsonvt/simplify.d.ts → vector-tiler/features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/simplify.js → vector-tiler/features/simplify-path.js} +3 -3
- package/dist/lib/{geojsonvt/wrap.d.ts → vector-tiler/features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/wrap.js → vector-tiler/features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +35 -18
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +30 -10
- package/dist/mvt-worker.js +101 -56
- package/dist/table-tile-source.d.ts +148 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +420 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +14 -7
- package/src/lib/parse-mvt.ts +4 -33
- package/src/lib/parse-tilejson.ts +6 -6
- package/src/lib/utils/geometry-utils.ts +66 -1
- package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
- package/src/lib/{geojsonvt/clip.ts → vector-tiler/features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/features/convert-feature.ts +191 -0
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/{geojsonvt/simplify.ts → vector-tiler/features/simplify-path.ts} +8 -3
- package/src/lib/{geojsonvt/wrap.ts → vector-tiler/features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-source.ts +47 -24
- package/src/table-tile-source.ts +553 -0
- package/src/tilejson-loader.ts +2 -2
- package/dist/geojson-tile-source.d.ts +0 -79
- package/dist/geojson-tile-source.d.ts.map +0 -1
- package/dist/geojson-tile-source.js +0 -319
- package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.d.ts +0 -10
- package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.js +0 -132
- package/dist/lib/geojsonvt/feature.d.ts +0 -3
- package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
- package/dist/lib/geojsonvt/feature.js +0 -44
- package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.d.ts +0 -38
- package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.js +0 -123
- package/dist/lib/geojsonvt/transform.d.ts +0 -7
- package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
- package/dist/lib/geojsonvt/transform.js +0 -41
- package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
- package/src/geojson-tile-source.ts +0 -422
- package/src/lib/geojsonvt/convert.ts +0 -160
- package/src/lib/geojsonvt/feature.ts +0 -47
- package/src/lib/geojsonvt/tile.ts +0 -187
- package/src/lib/geojsonvt/transform.ts +0 -57
- /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
package/dist/index.cjs
CHANGED
|
@@ -35,14 +35,251 @@ var __publicField = (obj, key, value) => {
|
|
|
35
35
|
// dist/index.js
|
|
36
36
|
var dist_exports = {};
|
|
37
37
|
__export(dist_exports, {
|
|
38
|
-
GeoJSONTileSource: () => GeoJSONTileSource,
|
|
39
38
|
MVTLoader: () => MVTLoader,
|
|
40
39
|
MVTSource: () => MVTSource,
|
|
41
40
|
MVTWorkerLoader: () => MVTWorkerLoader,
|
|
41
|
+
TableTileSource: () => TableTileSource,
|
|
42
42
|
TileJSONLoader: () => TileJSONLoader
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(dist_exports);
|
|
45
45
|
|
|
46
|
+
// dist/lib/parse-tilejson.js
|
|
47
|
+
var isObject = (x) => x !== null && typeof x === "object";
|
|
48
|
+
function parseTileJSON(jsonMetadata, options) {
|
|
49
|
+
var _a;
|
|
50
|
+
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
let tileJSON = {
|
|
54
|
+
name: jsonMetadata.name || "",
|
|
55
|
+
description: jsonMetadata.description || ""
|
|
56
|
+
};
|
|
57
|
+
if (typeof jsonMetadata.generator === "string") {
|
|
58
|
+
tileJSON.generator = jsonMetadata.generator;
|
|
59
|
+
}
|
|
60
|
+
if (typeof jsonMetadata.generator_options === "string") {
|
|
61
|
+
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
62
|
+
}
|
|
63
|
+
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
64
|
+
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
65
|
+
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
66
|
+
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
67
|
+
if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
|
|
68
|
+
try {
|
|
69
|
+
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.warn("Failed to parse tilejson.json field", error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
|
|
75
|
+
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
76
|
+
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
77
|
+
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
78
|
+
tileJSON = {
|
|
79
|
+
...tileJSON,
|
|
80
|
+
layers
|
|
81
|
+
};
|
|
82
|
+
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
83
|
+
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
84
|
+
}
|
|
85
|
+
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
86
|
+
tileJSON.minZoom = layers[0].minZoom || null;
|
|
87
|
+
}
|
|
88
|
+
return tileJSON;
|
|
89
|
+
}
|
|
90
|
+
function parseTileJSONLayers(layers) {
|
|
91
|
+
if (!Array.isArray(layers)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
95
|
+
}
|
|
96
|
+
function parseTileJSONLayer(layer) {
|
|
97
|
+
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
98
|
+
name: key,
|
|
99
|
+
...attributeTypeToFieldType(String(datatype))
|
|
100
|
+
}));
|
|
101
|
+
const layer2 = { ...layer };
|
|
102
|
+
delete layer2.fields;
|
|
103
|
+
return {
|
|
104
|
+
name: layer.id || "",
|
|
105
|
+
...layer2,
|
|
106
|
+
fields
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function parseTilestatsLayers(tilestats, options) {
|
|
110
|
+
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
111
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
112
|
+
}
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
function parseTilestatsForLayer(layer, options) {
|
|
116
|
+
const fields = [];
|
|
117
|
+
const indexedAttributes = {};
|
|
118
|
+
const attributes = layer.attributes || [];
|
|
119
|
+
for (const attribute of attributes) {
|
|
120
|
+
const name = attribute.attribute;
|
|
121
|
+
if (typeof name === "string") {
|
|
122
|
+
if (name.split("|").length > 1) {
|
|
123
|
+
const fname = name.split("|")[0];
|
|
124
|
+
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
125
|
+
indexedAttributes[fname].push(attribute);
|
|
126
|
+
console.warn("ignoring tilestats indexed field", fname);
|
|
127
|
+
} else if (!fields[name]) {
|
|
128
|
+
fields.push(attributeToField(attribute, options));
|
|
129
|
+
} else {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
name: layer.layer || "",
|
|
135
|
+
dominantGeometry: layer.geometry,
|
|
136
|
+
fields
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function mergeLayers(layers, tilestatsLayers) {
|
|
140
|
+
return layers.map((layer) => {
|
|
141
|
+
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
142
|
+
const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || [];
|
|
143
|
+
const layer2 = { ...layer };
|
|
144
|
+
delete layer2.fields;
|
|
145
|
+
return {
|
|
146
|
+
...layer2,
|
|
147
|
+
...tilestatsLayer,
|
|
148
|
+
fields
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function parseBounds(bounds) {
|
|
153
|
+
const result = fromArrayOrString(bounds);
|
|
154
|
+
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
155
|
+
return [
|
|
156
|
+
[result[0], result[1]],
|
|
157
|
+
[result[2], result[3]]
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
return void 0;
|
|
161
|
+
}
|
|
162
|
+
function parseCenter(center) {
|
|
163
|
+
const result = fromArrayOrString(center);
|
|
164
|
+
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
function safeParseFloat(input) {
|
|
170
|
+
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
171
|
+
return result === null || isNaN(result) ? null : result;
|
|
172
|
+
}
|
|
173
|
+
function isLat(num) {
|
|
174
|
+
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
175
|
+
}
|
|
176
|
+
function isLng(num) {
|
|
177
|
+
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
178
|
+
}
|
|
179
|
+
function isZoom(num) {
|
|
180
|
+
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
181
|
+
}
|
|
182
|
+
function fromArrayOrString(data) {
|
|
183
|
+
if (typeof data === "string") {
|
|
184
|
+
return data.split(",").map(parseFloat);
|
|
185
|
+
} else if (Array.isArray(data)) {
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
var attrTypeMap = {
|
|
191
|
+
number: {
|
|
192
|
+
type: "float32"
|
|
193
|
+
},
|
|
194
|
+
numeric: {
|
|
195
|
+
type: "float32"
|
|
196
|
+
},
|
|
197
|
+
string: {
|
|
198
|
+
type: "utf8"
|
|
199
|
+
},
|
|
200
|
+
vachar: {
|
|
201
|
+
type: "utf8"
|
|
202
|
+
},
|
|
203
|
+
float: {
|
|
204
|
+
type: "float32"
|
|
205
|
+
},
|
|
206
|
+
int: {
|
|
207
|
+
type: "int32"
|
|
208
|
+
},
|
|
209
|
+
int4: {
|
|
210
|
+
type: "int32"
|
|
211
|
+
},
|
|
212
|
+
boolean: {
|
|
213
|
+
type: "boolean"
|
|
214
|
+
},
|
|
215
|
+
bool: {
|
|
216
|
+
type: "boolean"
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
function attributeToField(attribute = {}, options) {
|
|
220
|
+
var _a;
|
|
221
|
+
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
222
|
+
const field = {
|
|
223
|
+
name: attribute.attribute,
|
|
224
|
+
// what happens if attribute type is string...
|
|
225
|
+
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
226
|
+
...fieldTypes
|
|
227
|
+
};
|
|
228
|
+
if (typeof attribute.min === "number") {
|
|
229
|
+
field.min = attribute.min;
|
|
230
|
+
}
|
|
231
|
+
if (typeof attribute.max === "number") {
|
|
232
|
+
field.max = attribute.max;
|
|
233
|
+
}
|
|
234
|
+
if (typeof attribute.count === "number") {
|
|
235
|
+
field.uniqueValueCount = attribute.count;
|
|
236
|
+
}
|
|
237
|
+
if (attribute.values) {
|
|
238
|
+
field.values = attribute.values;
|
|
239
|
+
}
|
|
240
|
+
if (field.values && typeof options.maxValues === "number") {
|
|
241
|
+
field.values = (_a = field.values) == null ? void 0 : _a.slice(0, options.maxValues);
|
|
242
|
+
}
|
|
243
|
+
return field;
|
|
244
|
+
}
|
|
245
|
+
function attributeTypeToFieldType(aType) {
|
|
246
|
+
const type = aType.toLowerCase();
|
|
247
|
+
if (!type || !attrTypeMap[type]) {
|
|
248
|
+
}
|
|
249
|
+
return attrTypeMap[type] || { type: "string" };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// dist/tilejson-loader.js
|
|
253
|
+
var VERSION = true ? "4.3.0-alpha.2" : "latest";
|
|
254
|
+
var TileJSONLoader = {
|
|
255
|
+
dataType: null,
|
|
256
|
+
batchType: null,
|
|
257
|
+
name: "TileJSON",
|
|
258
|
+
id: "tilejson",
|
|
259
|
+
module: "pmtiles",
|
|
260
|
+
version: VERSION,
|
|
261
|
+
worker: true,
|
|
262
|
+
extensions: ["json"],
|
|
263
|
+
mimeTypes: ["application/json"],
|
|
264
|
+
text: true,
|
|
265
|
+
options: {
|
|
266
|
+
tilejson: {
|
|
267
|
+
maxValues: void 0
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
parse: async (arrayBuffer, options) => {
|
|
271
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
272
|
+
const json = JSON.parse(jsonString);
|
|
273
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
|
|
274
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
275
|
+
},
|
|
276
|
+
parseTextSync: (text, options) => {
|
|
277
|
+
const json = JSON.parse(text);
|
|
278
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
|
|
279
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
46
283
|
// dist/lib/parse-mvt.js
|
|
47
284
|
var import_gis = require("@loaders.gl/gis");
|
|
48
285
|
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
@@ -59,6 +296,39 @@ function signedArea(ring) {
|
|
|
59
296
|
}
|
|
60
297
|
return sum;
|
|
61
298
|
}
|
|
299
|
+
function convertToLocalCoordinates(coordinates, extent) {
|
|
300
|
+
if (Array.isArray(coordinates[0])) {
|
|
301
|
+
for (const subcoords of coordinates) {
|
|
302
|
+
convertToLocalCoordinates(subcoords, extent);
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const p = coordinates;
|
|
307
|
+
p[0] /= extent;
|
|
308
|
+
p[1] /= extent;
|
|
309
|
+
}
|
|
310
|
+
function convertToLocalCoordinatesFlat(data, extent) {
|
|
311
|
+
for (let i = 0; i < data.length; ++i) {
|
|
312
|
+
data[i] /= extent;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function projectToLngLat(line, tileIndex, extent) {
|
|
316
|
+
if (typeof line[0][0] !== "number") {
|
|
317
|
+
for (const point of line) {
|
|
318
|
+
projectToLngLat(point, tileIndex, extent);
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const size = extent * Math.pow(2, tileIndex.z);
|
|
323
|
+
const x0 = extent * tileIndex.x;
|
|
324
|
+
const y0 = extent * tileIndex.y;
|
|
325
|
+
for (let j = 0; j < line.length; j++) {
|
|
326
|
+
const p = line[j];
|
|
327
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
328
|
+
const y2 = 180 - (p[1] + y0) * 360 / size;
|
|
329
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
62
332
|
function projectToLngLatFlat(data, tileIndex, extent) {
|
|
63
333
|
const { x, y, z } = tileIndex;
|
|
64
334
|
const size = extent * Math.pow(2, z);
|
|
@@ -168,37 +438,30 @@ var VectorTileFeature = class {
|
|
|
168
438
|
this._geometryInfo = geometryInfo;
|
|
169
439
|
pbf.readFields(readFeature, this, end);
|
|
170
440
|
}
|
|
171
|
-
|
|
441
|
+
toGeoJSONFeature(coordinates, tileIndex) {
|
|
172
442
|
const coords = this.loadGeometry();
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const x0 = this.extent * x;
|
|
179
|
-
const y0 = this.extent * y;
|
|
180
|
-
function project(line) {
|
|
181
|
-
for (let j = 0; j < line.length; j++) {
|
|
182
|
-
const p = line[j];
|
|
183
|
-
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
184
|
-
const y2 = 180 - (p[1] + y0) * 360 / size;
|
|
185
|
-
p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
186
|
-
}
|
|
443
|
+
switch (coordinates) {
|
|
444
|
+
case "wgs84":
|
|
445
|
+
return _toGeoJSONFeature(this, coords, (line) => projectToLngLat(line, tileIndex, this.extent));
|
|
446
|
+
default:
|
|
447
|
+
return _toGeoJSONFeature(this, coords, convertToLocalCoordinates);
|
|
187
448
|
}
|
|
188
|
-
return _toGeoJSON(this, coords, project);
|
|
189
449
|
}
|
|
190
450
|
/**
|
|
191
451
|
*
|
|
192
452
|
* @param options
|
|
193
453
|
* @returns
|
|
194
454
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
455
|
+
toBinaryFeature(coordinates, tileIndex) {
|
|
456
|
+
const geom = this.loadFlatGeometry();
|
|
457
|
+
switch (coordinates) {
|
|
458
|
+
case "wgs84":
|
|
459
|
+
return this._toBinaryCoordinates(geom, (coords) => projectToLngLatFlat(coords, tileIndex, this.extent));
|
|
460
|
+
default:
|
|
461
|
+
return this._toBinaryCoordinates(geom, convertToLocalCoordinatesFlat);
|
|
198
462
|
}
|
|
199
|
-
const tileIndex = options;
|
|
200
|
-
return this._toBinaryCoordinates((data) => projectToLngLatFlat(data, tileIndex, this.extent));
|
|
201
463
|
}
|
|
464
|
+
/** Read a bounding box from the feature */
|
|
202
465
|
// eslint-disable-next-line max-statements
|
|
203
466
|
bbox() {
|
|
204
467
|
const pbf = this._pbf;
|
|
@@ -242,10 +505,9 @@ var VectorTileFeature = class {
|
|
|
242
505
|
* @param transform
|
|
243
506
|
* @returns result
|
|
244
507
|
*/
|
|
245
|
-
_toBinaryCoordinates(transform) {
|
|
246
|
-
const geom = this.loadFlatGeometry();
|
|
508
|
+
_toBinaryCoordinates(geom, transform) {
|
|
247
509
|
let geometry;
|
|
248
|
-
transform(geom.data, this);
|
|
510
|
+
transform(geom.data, this.extent);
|
|
249
511
|
const coordLength = 2;
|
|
250
512
|
switch (this.type) {
|
|
251
513
|
case 1:
|
|
@@ -322,6 +584,28 @@ var VectorTileFeature = class {
|
|
|
322
584
|
lines.push(line);
|
|
323
585
|
return lines;
|
|
324
586
|
}
|
|
587
|
+
/**
|
|
588
|
+
* Expands the protobuf data to an intermediate Flat GeoJSON
|
|
589
|
+
* data format, which maps closely to the binary data buffers.
|
|
590
|
+
* It is similar to GeoJSON, but rather than storing the coordinates
|
|
591
|
+
* in multidimensional arrays, we have a 1D `data` with all the
|
|
592
|
+
* coordinates, and then index into this using the `indices`
|
|
593
|
+
* parameter, e.g.
|
|
594
|
+
*
|
|
595
|
+
* geometry: {
|
|
596
|
+
* type: 'Point', data: [1,2], indices: [0]
|
|
597
|
+
* }
|
|
598
|
+
* geometry: {
|
|
599
|
+
* type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
600
|
+
* }
|
|
601
|
+
* geometry: {
|
|
602
|
+
* type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
603
|
+
* }
|
|
604
|
+
* Thus the indices member lets us look up the relevant range
|
|
605
|
+
* from the data array.
|
|
606
|
+
* The Multi* versions of the above types share the same data
|
|
607
|
+
* structure, just with multiple elements in the indices array
|
|
608
|
+
*/
|
|
325
609
|
// eslint-disable-next-line complexity, max-statements
|
|
326
610
|
loadFlatGeometry() {
|
|
327
611
|
const pbf = this._pbf;
|
|
@@ -364,7 +648,7 @@ var VectorTileFeature = class {
|
|
|
364
648
|
}
|
|
365
649
|
};
|
|
366
650
|
__publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
|
|
367
|
-
function
|
|
651
|
+
function _toGeoJSONFeature(vtFeature, coords, transform) {
|
|
368
652
|
let type = VectorTileFeature.types[vtFeature.type];
|
|
369
653
|
let i;
|
|
370
654
|
let j;
|
|
@@ -376,19 +660,19 @@ function _toGeoJSON(vtFeature, coords, transform) {
|
|
|
376
660
|
points[i] = coords[i][0];
|
|
377
661
|
}
|
|
378
662
|
coordinates = points;
|
|
379
|
-
transform(coordinates, vtFeature);
|
|
663
|
+
transform(coordinates, vtFeature.extent);
|
|
380
664
|
break;
|
|
381
665
|
case 2:
|
|
382
666
|
coordinates = coords;
|
|
383
667
|
for (i = 0; i < coordinates.length; i++) {
|
|
384
|
-
transform(coordinates[i], vtFeature);
|
|
668
|
+
transform(coordinates[i], vtFeature.extent);
|
|
385
669
|
}
|
|
386
670
|
break;
|
|
387
671
|
case 3:
|
|
388
672
|
coordinates = classifyRings(coords);
|
|
389
673
|
for (i = 0; i < coordinates.length; i++) {
|
|
390
674
|
for (j = 0; j < coordinates[i].length; j++) {
|
|
391
|
-
transform(coordinates[i][j], vtFeature);
|
|
675
|
+
transform(coordinates[i][j], vtFeature.extent);
|
|
392
676
|
}
|
|
393
677
|
}
|
|
394
678
|
break;
|
|
@@ -409,7 +693,8 @@ function _toGeoJSON(vtFeature, coords, transform) {
|
|
|
409
693
|
properties: vtFeature.properties
|
|
410
694
|
};
|
|
411
695
|
if (vtFeature.id !== null) {
|
|
412
|
-
result.
|
|
696
|
+
result.properties ||= {};
|
|
697
|
+
result.properties.id = vtFeature.id;
|
|
413
698
|
}
|
|
414
699
|
return result;
|
|
415
700
|
}
|
|
@@ -562,7 +847,7 @@ function parseToBinary(arrayBuffer, options) {
|
|
|
562
847
|
return binaryData;
|
|
563
848
|
}
|
|
564
849
|
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
565
|
-
const
|
|
850
|
+
const features2 = [];
|
|
566
851
|
const geometryInfo = {
|
|
567
852
|
coordLength: 2,
|
|
568
853
|
pointPositionsCount: 0,
|
|
@@ -576,7 +861,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
|
|
|
576
861
|
polygonFeaturesCount: 0
|
|
577
862
|
};
|
|
578
863
|
if (arrayBuffer.byteLength <= 0) {
|
|
579
|
-
return [
|
|
864
|
+
return [features2, geometryInfo];
|
|
580
865
|
}
|
|
581
866
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
582
867
|
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
@@ -588,16 +873,16 @@ function parseToFlatGeoJson(arrayBuffer, options) {
|
|
|
588
873
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
589
874
|
const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
|
|
590
875
|
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
591
|
-
|
|
876
|
+
features2.push(decodedFeature);
|
|
592
877
|
}
|
|
593
878
|
});
|
|
594
|
-
return [
|
|
879
|
+
return [features2, geometryInfo];
|
|
595
880
|
}
|
|
596
881
|
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
597
882
|
if (arrayBuffer.byteLength <= 0) {
|
|
598
883
|
return [];
|
|
599
884
|
}
|
|
600
|
-
const
|
|
885
|
+
const features2 = [];
|
|
601
886
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
602
887
|
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
603
888
|
selectedLayers.forEach((layerName) => {
|
|
@@ -608,10 +893,10 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
|
608
893
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
609
894
|
const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
|
|
610
895
|
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
611
|
-
|
|
896
|
+
features2.push(decodedFeature);
|
|
612
897
|
}
|
|
613
898
|
});
|
|
614
|
-
return
|
|
899
|
+
return features2;
|
|
615
900
|
}
|
|
616
901
|
function checkOptions(options) {
|
|
617
902
|
var _a;
|
|
@@ -627,10 +912,7 @@ function checkOptions(options) {
|
|
|
627
912
|
return options.mvt;
|
|
628
913
|
}
|
|
629
914
|
function getDecodedFeature(feature, options, layerName) {
|
|
630
|
-
const decodedFeature = feature.
|
|
631
|
-
// @ts-expect-error What is going on here?
|
|
632
|
-
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
|
|
633
|
-
);
|
|
915
|
+
const decodedFeature = feature.toGeoJSONFeature(options.coordinates || "local", options.tileIndex);
|
|
634
916
|
if (options.layerProperty) {
|
|
635
917
|
decodedFeature.properties ||= {};
|
|
636
918
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
@@ -638,39 +920,22 @@ function getDecodedFeature(feature, options, layerName) {
|
|
|
638
920
|
return decodedFeature;
|
|
639
921
|
}
|
|
640
922
|
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
641
|
-
const decodedFeature = feature.
|
|
642
|
-
// @ts-expect-error
|
|
643
|
-
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
644
|
-
);
|
|
923
|
+
const decodedFeature = feature.toBinaryFeature(options.coordinates || "local", options.tileIndex);
|
|
645
924
|
if (options.layerProperty && decodedFeature.properties) {
|
|
646
925
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
647
926
|
}
|
|
648
927
|
return decodedFeature;
|
|
649
928
|
}
|
|
650
|
-
function transformToLocalCoordinates(line, feature) {
|
|
651
|
-
const { extent } = feature;
|
|
652
|
-
for (let i = 0; i < line.length; i++) {
|
|
653
|
-
const p = line[i];
|
|
654
|
-
p[0] /= extent;
|
|
655
|
-
p[1] /= extent;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function transformToLocalCoordinatesBinary(data, feature) {
|
|
659
|
-
const { extent } = feature;
|
|
660
|
-
for (let i = 0, il = data.length; i < il; ++i) {
|
|
661
|
-
data[i] /= extent;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
929
|
|
|
665
930
|
// dist/mvt-loader.js
|
|
666
|
-
var
|
|
931
|
+
var VERSION2 = true ? "4.3.0-alpha.2" : "latest";
|
|
667
932
|
var MVTWorkerLoader = {
|
|
668
933
|
dataType: null,
|
|
669
934
|
batchType: null,
|
|
670
935
|
name: "Mapbox Vector Tile",
|
|
671
936
|
id: "mvt",
|
|
672
937
|
module: "mvt",
|
|
673
|
-
version:
|
|
938
|
+
version: VERSION2,
|
|
674
939
|
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
675
940
|
extensions: ["mvt", "pbf"],
|
|
676
941
|
mimeTypes: [
|
|
@@ -698,248 +963,31 @@ var MVTLoader = {
|
|
|
698
963
|
binary: true
|
|
699
964
|
};
|
|
700
965
|
|
|
701
|
-
// dist/
|
|
702
|
-
var
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
if (typeof jsonMetadata.generator === "string") {
|
|
713
|
-
tileJSON.generator = jsonMetadata.generator;
|
|
714
|
-
}
|
|
715
|
-
if (typeof jsonMetadata.generator_options === "string") {
|
|
716
|
-
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
717
|
-
}
|
|
718
|
-
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
719
|
-
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
720
|
-
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
721
|
-
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
722
|
-
if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
|
|
723
|
-
try {
|
|
724
|
-
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
725
|
-
} catch (error) {
|
|
726
|
-
console.warn("Failed to parse tilejson.json field", error);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
|
|
730
|
-
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
731
|
-
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
732
|
-
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
733
|
-
tileJSON = {
|
|
734
|
-
...tileJSON,
|
|
735
|
-
layers
|
|
736
|
-
};
|
|
737
|
-
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
738
|
-
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
739
|
-
}
|
|
740
|
-
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
741
|
-
tileJSON.minZoom = layers[0].minZoom || null;
|
|
742
|
-
}
|
|
743
|
-
return tileJSON;
|
|
744
|
-
}
|
|
745
|
-
function parseTileJSONLayers(layers) {
|
|
746
|
-
if (!Array.isArray(layers)) {
|
|
747
|
-
return [];
|
|
748
|
-
}
|
|
749
|
-
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
750
|
-
}
|
|
751
|
-
function parseTileJSONLayer(layer) {
|
|
752
|
-
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
753
|
-
name: key,
|
|
754
|
-
...attributeTypeToFieldType(String(datatype))
|
|
755
|
-
}));
|
|
756
|
-
const layer2 = { ...layer };
|
|
757
|
-
delete layer2.fields;
|
|
758
|
-
return {
|
|
759
|
-
name: layer.id || "",
|
|
760
|
-
...layer2,
|
|
761
|
-
fields
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
function parseTilestatsLayers(tilestats, options) {
|
|
765
|
-
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
766
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
767
|
-
}
|
|
768
|
-
return [];
|
|
769
|
-
}
|
|
770
|
-
function parseTilestatsForLayer(layer, options) {
|
|
771
|
-
const fields = [];
|
|
772
|
-
const indexedAttributes = {};
|
|
773
|
-
const attributes = layer.attributes || [];
|
|
774
|
-
for (const attribute of attributes) {
|
|
775
|
-
const name = attribute.attribute;
|
|
776
|
-
if (typeof name === "string") {
|
|
777
|
-
if (name.split("|").length > 1) {
|
|
778
|
-
const fname = name.split("|")[0];
|
|
779
|
-
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
780
|
-
indexedAttributes[fname].push(attribute);
|
|
781
|
-
console.warn("ignoring tilestats indexed field", fname);
|
|
782
|
-
} else if (!fields[name]) {
|
|
783
|
-
fields.push(attributeToField(attribute, options));
|
|
784
|
-
} else {
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
return {
|
|
789
|
-
name: layer.layer || "",
|
|
790
|
-
dominantGeometry: layer.geometry,
|
|
791
|
-
fields
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function mergeLayers(layers, tilestatsLayers) {
|
|
795
|
-
return layers.map((layer) => {
|
|
796
|
-
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
797
|
-
const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || [];
|
|
798
|
-
const layer2 = { ...layer };
|
|
799
|
-
delete layer2.fields;
|
|
800
|
-
return {
|
|
801
|
-
...layer2,
|
|
802
|
-
...tilestatsLayer,
|
|
803
|
-
fields
|
|
804
|
-
};
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
function parseBounds(bounds) {
|
|
808
|
-
const result = fromArrayOrString(bounds);
|
|
809
|
-
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
810
|
-
return [
|
|
811
|
-
[result[0], result[1]],
|
|
812
|
-
[result[2], result[3]]
|
|
813
|
-
];
|
|
814
|
-
}
|
|
815
|
-
return void 0;
|
|
816
|
-
}
|
|
817
|
-
function parseCenter(center) {
|
|
818
|
-
const result = fromArrayOrString(center);
|
|
819
|
-
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
820
|
-
return result;
|
|
821
|
-
}
|
|
822
|
-
return null;
|
|
823
|
-
}
|
|
824
|
-
function safeParseFloat(input) {
|
|
825
|
-
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
826
|
-
return result === null || isNaN(result) ? null : result;
|
|
827
|
-
}
|
|
828
|
-
function isLat(num) {
|
|
829
|
-
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
830
|
-
}
|
|
831
|
-
function isLng(num) {
|
|
832
|
-
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
833
|
-
}
|
|
834
|
-
function isZoom(num) {
|
|
835
|
-
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
836
|
-
}
|
|
837
|
-
function fromArrayOrString(data) {
|
|
838
|
-
if (typeof data === "string") {
|
|
839
|
-
return data.split(",").map(parseFloat);
|
|
840
|
-
} else if (Array.isArray(data)) {
|
|
841
|
-
return data;
|
|
842
|
-
}
|
|
843
|
-
return null;
|
|
844
|
-
}
|
|
845
|
-
var attrTypeMap = {
|
|
846
|
-
number: {
|
|
847
|
-
type: "float32"
|
|
848
|
-
},
|
|
849
|
-
numeric: {
|
|
850
|
-
type: "float32"
|
|
851
|
-
},
|
|
852
|
-
string: {
|
|
853
|
-
type: "utf8"
|
|
854
|
-
},
|
|
855
|
-
vachar: {
|
|
856
|
-
type: "utf8"
|
|
857
|
-
},
|
|
858
|
-
float: {
|
|
859
|
-
type: "float32"
|
|
860
|
-
},
|
|
861
|
-
int: {
|
|
862
|
-
type: "int32"
|
|
863
|
-
},
|
|
864
|
-
int4: {
|
|
865
|
-
type: "int32"
|
|
866
|
-
},
|
|
867
|
-
boolean: {
|
|
868
|
-
type: "boolean"
|
|
869
|
-
},
|
|
870
|
-
bool: {
|
|
871
|
-
type: "boolean"
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
function attributeToField(attribute = {}, options) {
|
|
875
|
-
var _a;
|
|
876
|
-
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
877
|
-
const field = {
|
|
878
|
-
name: attribute.attribute,
|
|
879
|
-
// what happens if attribute type is string...
|
|
880
|
-
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
881
|
-
...fieldTypes
|
|
882
|
-
};
|
|
883
|
-
if (typeof attribute.min === "number") {
|
|
884
|
-
field.min = attribute.min;
|
|
885
|
-
}
|
|
886
|
-
if (typeof attribute.max === "number") {
|
|
887
|
-
field.max = attribute.max;
|
|
888
|
-
}
|
|
889
|
-
if (typeof attribute.count === "number") {
|
|
890
|
-
field.uniqueValueCount = attribute.count;
|
|
891
|
-
}
|
|
892
|
-
if (attribute.values) {
|
|
893
|
-
field.values = attribute.values;
|
|
894
|
-
}
|
|
895
|
-
if (field.values && typeof options.maxValues === "number") {
|
|
896
|
-
field.values = (_a = field.values) == null ? void 0 : _a.slice(0, options.maxValues);
|
|
897
|
-
}
|
|
898
|
-
return field;
|
|
899
|
-
}
|
|
900
|
-
function attributeTypeToFieldType(aType) {
|
|
901
|
-
const type = aType.toLowerCase();
|
|
902
|
-
if (!type || !attrTypeMap[type]) {
|
|
903
|
-
}
|
|
904
|
-
return attrTypeMap[type] || { type: "string" };
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
// dist/tilejson-loader.js
|
|
908
|
-
var VERSION2 = true ? "4.2.0" : "latest";
|
|
909
|
-
var TileJSONLoader = {
|
|
910
|
-
dataType: null,
|
|
911
|
-
batchType: null,
|
|
912
|
-
name: "TileJSON",
|
|
913
|
-
id: "tilejson",
|
|
914
|
-
module: "pmtiles",
|
|
915
|
-
version: VERSION2,
|
|
916
|
-
worker: true,
|
|
917
|
-
extensions: ["json"],
|
|
918
|
-
mimeTypes: ["application/json"],
|
|
919
|
-
text: true,
|
|
966
|
+
// dist/mvt-source.js
|
|
967
|
+
var import_loader_utils2 = require("@loaders.gl/loader-utils");
|
|
968
|
+
var import_images = require("@loaders.gl/images");
|
|
969
|
+
var import_mvt = require("@loaders.gl/mvt");
|
|
970
|
+
var MVTSource = {
|
|
971
|
+
name: "MVT",
|
|
972
|
+
id: "mvt",
|
|
973
|
+
module: "mvt",
|
|
974
|
+
version: "0.0.0",
|
|
975
|
+
extensions: ["mvt"],
|
|
976
|
+
mimeTypes: ["application/octet-stream"],
|
|
920
977
|
options: {
|
|
921
|
-
|
|
922
|
-
|
|
978
|
+
mvt: {
|
|
979
|
+
// TODO - add options here
|
|
923
980
|
}
|
|
924
981
|
},
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
parseTextSync: (text, options) => {
|
|
932
|
-
const json = JSON.parse(text);
|
|
933
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
|
|
934
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
982
|
+
type: "mvt",
|
|
983
|
+
fromUrl: true,
|
|
984
|
+
fromBlob: false,
|
|
985
|
+
testURL: (url) => true,
|
|
986
|
+
createDataSource(url, props) {
|
|
987
|
+
return new MVTTileSource(url, props);
|
|
935
988
|
}
|
|
936
989
|
};
|
|
937
|
-
|
|
938
|
-
// dist/mvt-source.js
|
|
939
|
-
var import_loader_utils2 = require("@loaders.gl/loader-utils");
|
|
940
|
-
var import_images = require("@loaders.gl/images");
|
|
941
|
-
var import_mvt = require("@loaders.gl/mvt");
|
|
942
|
-
var MVTSource = class extends import_loader_utils2.DataSource {
|
|
990
|
+
var MVTTileSource = class extends import_loader_utils2.DataSource {
|
|
943
991
|
props;
|
|
944
992
|
url;
|
|
945
993
|
metadataUrl = null;
|
|
@@ -948,12 +996,13 @@ var MVTSource = class extends import_loader_utils2.DataSource {
|
|
|
948
996
|
metadata;
|
|
949
997
|
extension;
|
|
950
998
|
mimeType = null;
|
|
951
|
-
constructor(props) {
|
|
999
|
+
constructor(url, props) {
|
|
1000
|
+
var _a, _b;
|
|
952
1001
|
super(props);
|
|
953
1002
|
this.props = props;
|
|
954
|
-
this.url = (0, import_loader_utils2.resolvePath)(
|
|
955
|
-
this.metadataUrl = props.
|
|
956
|
-
this.extension = props.extension || ".png";
|
|
1003
|
+
this.url = (0, import_loader_utils2.resolvePath)(url);
|
|
1004
|
+
this.metadataUrl = ((_a = props.mvt) == null ? void 0 : _a.metadataUrl) || `${this.url}/tilejson.json`;
|
|
1005
|
+
this.extension = ((_b = props.mvt) == null ? void 0 : _b.extension) || ".png";
|
|
957
1006
|
this.data = this.url;
|
|
958
1007
|
this.getTileData = this.getTileData.bind(this);
|
|
959
1008
|
this.metadata = this.getMetadata();
|
|
@@ -985,8 +1034,8 @@ var MVTSource = class extends import_loader_utils2.DataSource {
|
|
|
985
1034
|
getTileMIMEType() {
|
|
986
1035
|
return this.mimeType;
|
|
987
1036
|
}
|
|
988
|
-
async getTile(
|
|
989
|
-
const { x, y, z } =
|
|
1037
|
+
async getTile(parameters) {
|
|
1038
|
+
const { x, y, z } = parameters;
|
|
990
1039
|
const tileUrl = this.getTileURL(x, y, z);
|
|
991
1040
|
const response = await this.fetch(tileUrl);
|
|
992
1041
|
if (!response.ok) {
|
|
@@ -997,8 +1046,8 @@ var MVTSource = class extends import_loader_utils2.DataSource {
|
|
|
997
1046
|
}
|
|
998
1047
|
// Tile Source interface implementation: deck.gl compatible API
|
|
999
1048
|
// TODO - currently only handles image tiles, not vector tiles
|
|
1000
|
-
async getTileData(
|
|
1001
|
-
const { x, y, z } =
|
|
1049
|
+
async getTileData(parameters) {
|
|
1050
|
+
const { x, y, z } = parameters.index;
|
|
1002
1051
|
const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
|
|
1003
1052
|
if (arrayBuffer === null) {
|
|
1004
1053
|
return null;
|
|
@@ -1053,33 +1102,317 @@ var MVTSource = class extends import_loader_utils2.DataSource {
|
|
|
1053
1102
|
throw new Error(this.schema);
|
|
1054
1103
|
}
|
|
1055
1104
|
}
|
|
1056
|
-
};
|
|
1057
|
-
function isURLTemplate(s) {
|
|
1058
|
-
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
1105
|
+
};
|
|
1106
|
+
function isURLTemplate(s) {
|
|
1107
|
+
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
1108
|
+
}
|
|
1109
|
+
var xRegex = new RegExp("{x}", "g");
|
|
1110
|
+
var yRegex = new RegExp("{y}", "g");
|
|
1111
|
+
var zRegex = new RegExp("{z}", "g");
|
|
1112
|
+
function getURLFromTemplate(template, x, y, z, id = "0") {
|
|
1113
|
+
if (Array.isArray(template)) {
|
|
1114
|
+
const i = stringHash(id) % template.length;
|
|
1115
|
+
template = template[i];
|
|
1116
|
+
}
|
|
1117
|
+
let url = template;
|
|
1118
|
+
url = url.replace(xRegex, String(x));
|
|
1119
|
+
url = url.replace(yRegex, String(y));
|
|
1120
|
+
url = url.replace(zRegex, String(z));
|
|
1121
|
+
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
1122
|
+
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
1123
|
+
}
|
|
1124
|
+
return url;
|
|
1125
|
+
}
|
|
1126
|
+
function stringHash(s) {
|
|
1127
|
+
return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// dist/table-tile-source.js
|
|
1131
|
+
var import_loader_utils3 = require("@loaders.gl/loader-utils");
|
|
1132
|
+
var import_schema = require("@loaders.gl/schema");
|
|
1133
|
+
var import_stats = require("@probe.gl/stats");
|
|
1134
|
+
|
|
1135
|
+
// dist/lib/vector-tiler/proto-tile.js
|
|
1136
|
+
function createProtoTile(features2, z, tx, ty, options) {
|
|
1137
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
1138
|
+
const tile = {
|
|
1139
|
+
protoFeatures: [],
|
|
1140
|
+
sourceFeatures: null,
|
|
1141
|
+
numPoints: 0,
|
|
1142
|
+
numSimplified: 0,
|
|
1143
|
+
numFeatures: features2.length,
|
|
1144
|
+
x: tx,
|
|
1145
|
+
y: ty,
|
|
1146
|
+
z,
|
|
1147
|
+
transformed: false,
|
|
1148
|
+
minX: 2,
|
|
1149
|
+
minY: 1,
|
|
1150
|
+
maxX: -1,
|
|
1151
|
+
maxY: 0
|
|
1152
|
+
};
|
|
1153
|
+
for (const feature of features2) {
|
|
1154
|
+
addProtoFeature(tile, feature, tolerance, options);
|
|
1155
|
+
}
|
|
1156
|
+
return tile;
|
|
1157
|
+
}
|
|
1158
|
+
function addProtoFeature(tile, feature, tolerance, options) {
|
|
1159
|
+
const geometry = feature.geometry;
|
|
1160
|
+
const type = feature.type;
|
|
1161
|
+
const simplifiedGeometry = [];
|
|
1162
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
1163
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
1164
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
1165
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
1166
|
+
let simplifiedType;
|
|
1167
|
+
switch (type) {
|
|
1168
|
+
case "Point":
|
|
1169
|
+
case "MultiPoint":
|
|
1170
|
+
simplifiedType = 1;
|
|
1171
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
1172
|
+
simplifiedGeometry.push(geometry[i], geometry[i + 1]);
|
|
1173
|
+
tile.numPoints++;
|
|
1174
|
+
tile.numSimplified++;
|
|
1175
|
+
}
|
|
1176
|
+
break;
|
|
1177
|
+
case "LineString":
|
|
1178
|
+
simplifiedType = 2;
|
|
1179
|
+
addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
|
|
1180
|
+
break;
|
|
1181
|
+
case "MultiLineString":
|
|
1182
|
+
simplifiedType = 2;
|
|
1183
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
1184
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
case "Polygon":
|
|
1188
|
+
simplifiedType = 3;
|
|
1189
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
1190
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
|
|
1191
|
+
}
|
|
1192
|
+
break;
|
|
1193
|
+
case "MultiPolygon":
|
|
1194
|
+
simplifiedType = 3;
|
|
1195
|
+
for (let k = 0; k < geometry.length; k++) {
|
|
1196
|
+
const polygon = geometry[k];
|
|
1197
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
1198
|
+
addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
break;
|
|
1202
|
+
default:
|
|
1203
|
+
throw new Error(`Unknown geometry type: ${type}`);
|
|
1204
|
+
}
|
|
1205
|
+
if (simplifiedGeometry.length) {
|
|
1206
|
+
let tags = feature.tags || null;
|
|
1207
|
+
if (type === "LineString" && options.lineMetrics) {
|
|
1208
|
+
tags = {};
|
|
1209
|
+
for (const key in feature.tags) {
|
|
1210
|
+
tags[key] = feature.tags[key];
|
|
1211
|
+
}
|
|
1212
|
+
tags.mapbox_clip_start = geometry.start / geometry.size;
|
|
1213
|
+
tags.mapbox_clip_end = geometry.end / geometry.size;
|
|
1214
|
+
}
|
|
1215
|
+
const tileFeature = {
|
|
1216
|
+
geometry: simplifiedGeometry,
|
|
1217
|
+
simplifiedType,
|
|
1218
|
+
// @ts-expect-error
|
|
1219
|
+
tags
|
|
1220
|
+
};
|
|
1221
|
+
if (feature.id !== null) {
|
|
1222
|
+
tileFeature.id = feature.id;
|
|
1223
|
+
}
|
|
1224
|
+
tile.protoFeatures.push(tileFeature);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
|
|
1228
|
+
const sqTolerance = tolerance * tolerance;
|
|
1229
|
+
if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
1230
|
+
tile.numPoints += geometry.length / 3;
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
const ring = [];
|
|
1234
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
1235
|
+
if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
|
|
1236
|
+
tile.numSimplified++;
|
|
1237
|
+
ring.push(geometry[i], geometry[i + 1]);
|
|
1238
|
+
}
|
|
1239
|
+
tile.numPoints++;
|
|
1240
|
+
}
|
|
1241
|
+
if (isPolygon)
|
|
1242
|
+
rewind(ring, isOuter);
|
|
1243
|
+
result.push(ring);
|
|
1244
|
+
}
|
|
1245
|
+
function rewind(ring, clockwise) {
|
|
1246
|
+
let area = 0;
|
|
1247
|
+
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
1248
|
+
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
1249
|
+
}
|
|
1250
|
+
if (area > 0 === clockwise) {
|
|
1251
|
+
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
1252
|
+
const x = ring[i];
|
|
1253
|
+
const y = ring[i + 1];
|
|
1254
|
+
ring[i] = ring[len - 2 - i];
|
|
1255
|
+
ring[i + 1] = ring[len - 1 - i];
|
|
1256
|
+
ring[len - 2 - i] = x;
|
|
1257
|
+
ring[len - 1 - i] = y;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// dist/lib/vector-tiler/transform-tile.js
|
|
1263
|
+
function transformTile(protoTile, extent) {
|
|
1264
|
+
if (protoTile.transformed) {
|
|
1265
|
+
return protoTile;
|
|
1266
|
+
}
|
|
1267
|
+
const z2 = 1 << protoTile.z;
|
|
1268
|
+
const tx = protoTile.x;
|
|
1269
|
+
const ty = protoTile.y;
|
|
1270
|
+
for (const protoFeature of protoTile.protoFeatures) {
|
|
1271
|
+
const geom = protoFeature.geometry;
|
|
1272
|
+
const simplifiedType = protoFeature.simplifiedType;
|
|
1273
|
+
protoFeature.geometry = [];
|
|
1274
|
+
if (simplifiedType === 1) {
|
|
1275
|
+
for (let j = 0; j < geom.length; j += 2) {
|
|
1276
|
+
protoFeature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
1277
|
+
}
|
|
1278
|
+
} else {
|
|
1279
|
+
for (let j = 0; j < geom.length; j++) {
|
|
1280
|
+
const ring = [];
|
|
1281
|
+
for (let k = 0; k < geom[j].length; k += 2) {
|
|
1282
|
+
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
1283
|
+
}
|
|
1284
|
+
protoFeature.geometry.push(ring);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
protoTile.transformed = true;
|
|
1289
|
+
return protoTile;
|
|
1290
|
+
}
|
|
1291
|
+
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
1292
|
+
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// dist/lib/vector-tiler/tile-to-geojson.js
|
|
1296
|
+
function convertTileToGeoJSON(protoTile, props) {
|
|
1297
|
+
const features2 = [];
|
|
1298
|
+
for (const rawFeature of protoTile.protoFeatures) {
|
|
1299
|
+
if (!rawFeature || !rawFeature.geometry) {
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
let type;
|
|
1303
|
+
let coordinates;
|
|
1304
|
+
switch (rawFeature.simplifiedType) {
|
|
1305
|
+
case 1:
|
|
1306
|
+
if (rawFeature.geometry.length === 1) {
|
|
1307
|
+
type = "Point";
|
|
1308
|
+
coordinates = rawFeature.geometry[0];
|
|
1309
|
+
} else {
|
|
1310
|
+
type = "MultiPoint";
|
|
1311
|
+
coordinates = rawFeature.geometry;
|
|
1312
|
+
}
|
|
1313
|
+
break;
|
|
1314
|
+
case 2:
|
|
1315
|
+
if (rawFeature.geometry.length === 1) {
|
|
1316
|
+
type = "LineString";
|
|
1317
|
+
coordinates = rawFeature.geometry[0];
|
|
1318
|
+
} else {
|
|
1319
|
+
type = "MultiLineString";
|
|
1320
|
+
coordinates = rawFeature.geometry;
|
|
1321
|
+
}
|
|
1322
|
+
break;
|
|
1323
|
+
case 3:
|
|
1324
|
+
if (rawFeature.geometry.length > 1) {
|
|
1325
|
+
type = "MultiPolygon";
|
|
1326
|
+
coordinates = [rawFeature.geometry];
|
|
1327
|
+
} else {
|
|
1328
|
+
type = "Polygon";
|
|
1329
|
+
coordinates = rawFeature.geometry;
|
|
1330
|
+
}
|
|
1331
|
+
break;
|
|
1332
|
+
default:
|
|
1333
|
+
throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
|
|
1334
|
+
}
|
|
1335
|
+
switch (props.coordinates) {
|
|
1336
|
+
case "EPSG:4326":
|
|
1337
|
+
case "wgs84":
|
|
1338
|
+
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
1339
|
+
break;
|
|
1340
|
+
default:
|
|
1341
|
+
convertToLocalCoordinates(coordinates, props.extent);
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
const feature = {
|
|
1345
|
+
type: "Feature",
|
|
1346
|
+
geometry: {
|
|
1347
|
+
type,
|
|
1348
|
+
coordinates
|
|
1349
|
+
},
|
|
1350
|
+
properties: rawFeature.tags || {},
|
|
1351
|
+
id: rawFeature.id
|
|
1352
|
+
};
|
|
1353
|
+
features2.push(feature);
|
|
1354
|
+
}
|
|
1355
|
+
if (features2.length === 0) {
|
|
1356
|
+
return null;
|
|
1357
|
+
}
|
|
1358
|
+
const table = {
|
|
1359
|
+
shape: "geojson-table",
|
|
1360
|
+
type: "FeatureCollection",
|
|
1361
|
+
features: features2
|
|
1362
|
+
};
|
|
1363
|
+
return table;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// dist/lib/vector-tiler/features/proto-feature.js
|
|
1367
|
+
function createProtoFeature(id, type, geometry, tags) {
|
|
1368
|
+
const feature = {
|
|
1369
|
+
// eslint-disable-next-line
|
|
1370
|
+
id: id == null ? null : id,
|
|
1371
|
+
type,
|
|
1372
|
+
simplifiedType: void 0,
|
|
1373
|
+
// TODO
|
|
1374
|
+
geometry,
|
|
1375
|
+
tags,
|
|
1376
|
+
minX: Infinity,
|
|
1377
|
+
minY: Infinity,
|
|
1378
|
+
maxX: -Infinity,
|
|
1379
|
+
maxY: -Infinity
|
|
1380
|
+
};
|
|
1381
|
+
switch (type) {
|
|
1382
|
+
case "Point":
|
|
1383
|
+
case "MultiPoint":
|
|
1384
|
+
case "LineString":
|
|
1385
|
+
calcLineBBox(feature, geometry);
|
|
1386
|
+
break;
|
|
1387
|
+
case "MultiLineString":
|
|
1388
|
+
for (const line of geometry) {
|
|
1389
|
+
calcLineBBox(feature, line);
|
|
1390
|
+
}
|
|
1391
|
+
break;
|
|
1392
|
+
case "Polygon":
|
|
1393
|
+
calcLineBBox(feature, geometry[0]);
|
|
1394
|
+
break;
|
|
1395
|
+
case "MultiPolygon":
|
|
1396
|
+
for (const polygon of geometry) {
|
|
1397
|
+
calcLineBBox(feature, polygon[0]);
|
|
1398
|
+
}
|
|
1399
|
+
break;
|
|
1400
|
+
default:
|
|
1401
|
+
throw new Error(String(type));
|
|
1402
|
+
}
|
|
1403
|
+
return feature;
|
|
1059
1404
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
template = template[i];
|
|
1067
|
-
}
|
|
1068
|
-
let url = template;
|
|
1069
|
-
url = url.replace(xRegex, String(x));
|
|
1070
|
-
url = url.replace(yRegex, String(y));
|
|
1071
|
-
url = url.replace(zRegex, String(z));
|
|
1072
|
-
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
1073
|
-
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
1405
|
+
function calcLineBBox(feature, geometry) {
|
|
1406
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
1407
|
+
feature.minX = Math.min(feature.minX, geometry[i]);
|
|
1408
|
+
feature.minY = Math.min(feature.minY, geometry[i + 1]);
|
|
1409
|
+
feature.maxX = Math.max(feature.maxX, geometry[i]);
|
|
1410
|
+
feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
|
|
1074
1411
|
}
|
|
1075
|
-
return url;
|
|
1076
|
-
}
|
|
1077
|
-
function stringHash(s) {
|
|
1078
|
-
return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
|
|
1079
1412
|
}
|
|
1080
1413
|
|
|
1081
|
-
// dist/lib/
|
|
1082
|
-
function
|
|
1414
|
+
// dist/lib/vector-tiler/features/simplify-path.js
|
|
1415
|
+
function simplifyPath(coords, first, last, sqTolerance) {
|
|
1083
1416
|
let maxSqDist = sqTolerance;
|
|
1084
1417
|
const mid = last - first >> 1;
|
|
1085
1418
|
let minPosToMid = last - first;
|
|
@@ -1103,10 +1436,10 @@ function simplify(coords, first, last, sqTolerance) {
|
|
|
1103
1436
|
}
|
|
1104
1437
|
if (maxSqDist > sqTolerance) {
|
|
1105
1438
|
if (index - first > 3)
|
|
1106
|
-
|
|
1439
|
+
simplifyPath(coords, first, index, sqTolerance);
|
|
1107
1440
|
coords[index + 2] = maxSqDist;
|
|
1108
1441
|
if (last - index > 3)
|
|
1109
|
-
|
|
1442
|
+
simplifyPath(coords, index, last, sqTolerance);
|
|
1110
1443
|
}
|
|
1111
1444
|
}
|
|
1112
1445
|
function getSqSegDist(px, py, x, y, bx, by) {
|
|
@@ -1127,58 +1460,25 @@ function getSqSegDist(px, py, x, y, bx, by) {
|
|
|
1127
1460
|
return dx * dx + dy * dy;
|
|
1128
1461
|
}
|
|
1129
1462
|
|
|
1130
|
-
// dist/lib/
|
|
1131
|
-
function
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
} else if (type === "Polygon") {
|
|
1146
|
-
calcLineBBox(feature, geom[0]);
|
|
1147
|
-
} else if (type === "MultiLineString") {
|
|
1148
|
-
for (const line of geom) {
|
|
1149
|
-
calcLineBBox(feature, line);
|
|
1150
|
-
}
|
|
1151
|
-
} else if (type === "MultiPolygon") {
|
|
1152
|
-
for (const polygon of geom) {
|
|
1153
|
-
calcLineBBox(feature, polygon[0]);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
return feature;
|
|
1157
|
-
}
|
|
1158
|
-
function calcLineBBox(feature, geom) {
|
|
1159
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
1160
|
-
feature.minX = Math.min(feature.minX, geom[i]);
|
|
1161
|
-
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
1162
|
-
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
1163
|
-
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
// dist/lib/geojsonvt/convert.js
|
|
1168
|
-
function convert(data, options) {
|
|
1169
|
-
const features = [];
|
|
1170
|
-
if (data.type === "FeatureCollection") {
|
|
1171
|
-
for (let i = 0; i < data.features.length; i++) {
|
|
1172
|
-
convertFeature(features, data.features[i], options, i);
|
|
1173
|
-
}
|
|
1174
|
-
} else if (data.type === "Feature") {
|
|
1175
|
-
convertFeature(features, data, options);
|
|
1176
|
-
} else {
|
|
1177
|
-
convertFeature(features, { geometry: data }, options);
|
|
1463
|
+
// dist/lib/vector-tiler/features/convert-feature.js
|
|
1464
|
+
function convertFeaturesToProtoFeature(data, options) {
|
|
1465
|
+
const protoFeatures = [];
|
|
1466
|
+
switch (data.type) {
|
|
1467
|
+
case "FeatureCollection":
|
|
1468
|
+
let i = 0;
|
|
1469
|
+
for (const feature of data.features) {
|
|
1470
|
+
protoFeatures.push(convertFeature(feature, options, i++));
|
|
1471
|
+
}
|
|
1472
|
+
break;
|
|
1473
|
+
case "Feature":
|
|
1474
|
+
protoFeatures.push(convertFeature(data, options));
|
|
1475
|
+
break;
|
|
1476
|
+
default:
|
|
1477
|
+
protoFeatures.push(convertFeature({ geometry: data }, options));
|
|
1178
1478
|
}
|
|
1179
|
-
return
|
|
1479
|
+
return protoFeatures;
|
|
1180
1480
|
}
|
|
1181
|
-
function convertFeature(
|
|
1481
|
+
function convertFeature(geojson, options, index) {
|
|
1182
1482
|
if (!geojson.geometry) {
|
|
1183
1483
|
return;
|
|
1184
1484
|
}
|
|
@@ -1192,46 +1492,52 @@ function convertFeature(features, geojson, options, index) {
|
|
|
1192
1492
|
} else if (options.generateId) {
|
|
1193
1493
|
id = index || 0;
|
|
1194
1494
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
convertLine(coords, geometry, tolerance, false);
|
|
1203
|
-
} else if (type === "MultiLineString") {
|
|
1204
|
-
if (options.lineMetrics) {
|
|
1205
|
-
for (const line of coords) {
|
|
1206
|
-
geometry = [];
|
|
1207
|
-
convertLine(line, geometry, tolerance, false);
|
|
1208
|
-
features.push(createFeature(id, "LineString", geometry, geojson.properties));
|
|
1495
|
+
switch (type) {
|
|
1496
|
+
case "Point":
|
|
1497
|
+
convertPoint(coords, geometry);
|
|
1498
|
+
break;
|
|
1499
|
+
case "MultiPoint":
|
|
1500
|
+
for (const p of coords) {
|
|
1501
|
+
convertPoint(p, geometry);
|
|
1209
1502
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1503
|
+
break;
|
|
1504
|
+
case "LineString":
|
|
1505
|
+
convertLine(coords, geometry, tolerance, false);
|
|
1506
|
+
break;
|
|
1507
|
+
case "MultiLineString":
|
|
1508
|
+
if (options.lineMetrics) {
|
|
1509
|
+
for (const line of coords) {
|
|
1510
|
+
geometry = [];
|
|
1511
|
+
convertLine(line, geometry, tolerance, false);
|
|
1512
|
+
features.push(createProtoFeature(id, "LineString", geometry, geojson.properties));
|
|
1513
|
+
}
|
|
1514
|
+
return;
|
|
1515
|
+
convertLines(coords, geometry, tolerance, false);
|
|
1516
|
+
}
|
|
1517
|
+
break;
|
|
1518
|
+
case "Polygon":
|
|
1519
|
+
convertLines(coords, geometry, tolerance, true);
|
|
1520
|
+
break;
|
|
1521
|
+
case "MultiPolygon":
|
|
1522
|
+
for (const polygon of coords) {
|
|
1523
|
+
const newPolygon = [];
|
|
1524
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
1525
|
+
geometry.push(newPolygon);
|
|
1526
|
+
}
|
|
1527
|
+
break;
|
|
1528
|
+
case "GeometryCollection":
|
|
1529
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
1530
|
+
convertFeature(features, {
|
|
1531
|
+
id,
|
|
1532
|
+
geometry: singleGeometry,
|
|
1533
|
+
properties: geojson.properties
|
|
1534
|
+
}, options, index);
|
|
1535
|
+
}
|
|
1536
|
+
break;
|
|
1537
|
+
default:
|
|
1538
|
+
throw new Error("Input data is not a valid GeoJSON object.");
|
|
1233
1539
|
}
|
|
1234
|
-
|
|
1540
|
+
return createProtoFeature(id, type, geometry, geojson.properties);
|
|
1235
1541
|
}
|
|
1236
1542
|
function convertPoint(coords, out) {
|
|
1237
1543
|
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
@@ -1255,7 +1561,7 @@ function convertLine(ring, out, tolerance, isPolygon) {
|
|
|
1255
1561
|
}
|
|
1256
1562
|
const last = out.length - 3;
|
|
1257
1563
|
out[2] = 1;
|
|
1258
|
-
|
|
1564
|
+
simplifyPath(out, 0, last, tolerance);
|
|
1259
1565
|
out[last + 2] = 1;
|
|
1260
1566
|
out.size = Math.abs(size);
|
|
1261
1567
|
out.start = 0;
|
|
@@ -1277,17 +1583,17 @@ function projectY(y) {
|
|
|
1277
1583
|
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
1278
1584
|
}
|
|
1279
1585
|
|
|
1280
|
-
// dist/lib/
|
|
1281
|
-
function
|
|
1586
|
+
// dist/lib/vector-tiler/features/clip-features.js
|
|
1587
|
+
function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
1282
1588
|
k1 /= scale;
|
|
1283
1589
|
k2 /= scale;
|
|
1284
1590
|
if (minAll >= k1 && maxAll < k2) {
|
|
1285
|
-
return
|
|
1591
|
+
return features2;
|
|
1286
1592
|
} else if (maxAll < k1 || minAll >= k2) {
|
|
1287
1593
|
return null;
|
|
1288
1594
|
}
|
|
1289
1595
|
const clipped = [];
|
|
1290
|
-
for (const feature of
|
|
1596
|
+
for (const feature of features2) {
|
|
1291
1597
|
const geometry = feature.geometry;
|
|
1292
1598
|
let type = feature.type;
|
|
1293
1599
|
const min = axis === 0 ? feature.minX : feature.minY;
|
|
@@ -1319,7 +1625,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
1319
1625
|
if (newGeometry.length) {
|
|
1320
1626
|
if (options.lineMetrics && type === "LineString") {
|
|
1321
1627
|
for (const line of newGeometry) {
|
|
1322
|
-
clipped.push(
|
|
1628
|
+
clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
|
|
1323
1629
|
}
|
|
1324
1630
|
continue;
|
|
1325
1631
|
}
|
|
@@ -1334,7 +1640,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
1334
1640
|
if (type === "Point" || type === "MultiPoint") {
|
|
1335
1641
|
type = newGeometry.length === 3 ? "Point" : "MultiPoint";
|
|
1336
1642
|
}
|
|
1337
|
-
clipped.push(
|
|
1643
|
+
clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
1338
1644
|
}
|
|
1339
1645
|
}
|
|
1340
1646
|
return clipped.length ? clipped : null;
|
|
@@ -1442,14 +1748,14 @@ function intersectY(out, ax, ay, bx, by, y) {
|
|
|
1442
1748
|
return t;
|
|
1443
1749
|
}
|
|
1444
1750
|
|
|
1445
|
-
// dist/lib/
|
|
1446
|
-
function
|
|
1751
|
+
// dist/lib/vector-tiler/features/wrap-features.js
|
|
1752
|
+
function wrapFeatures(features2, options) {
|
|
1447
1753
|
const buffer = options.buffer / options.extent;
|
|
1448
|
-
let merged =
|
|
1449
|
-
const left =
|
|
1450
|
-
const right =
|
|
1754
|
+
let merged = features2;
|
|
1755
|
+
const left = clipFeatures(features2, 1, -1 - buffer, buffer, 0, -1, 2, options);
|
|
1756
|
+
const right = clipFeatures(features2, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
|
|
1451
1757
|
if (left || right) {
|
|
1452
|
-
merged =
|
|
1758
|
+
merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
|
|
1453
1759
|
if (left) {
|
|
1454
1760
|
merged = shiftFeatureCoords(left, 1).concat(merged);
|
|
1455
1761
|
}
|
|
@@ -1459,30 +1765,39 @@ function wrap(features, options) {
|
|
|
1459
1765
|
}
|
|
1460
1766
|
return merged;
|
|
1461
1767
|
}
|
|
1462
|
-
function shiftFeatureCoords(
|
|
1768
|
+
function shiftFeatureCoords(features2, offset) {
|
|
1463
1769
|
const newFeatures = [];
|
|
1464
|
-
for (let i = 0; i <
|
|
1465
|
-
const feature =
|
|
1770
|
+
for (let i = 0; i < features2.length; i++) {
|
|
1771
|
+
const feature = features2[i];
|
|
1466
1772
|
const type = feature.type;
|
|
1467
1773
|
let newGeometry;
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
for (const line of polygon) {
|
|
1480
|
-
newPolygon.push(shiftCoords(line, offset));
|
|
1774
|
+
switch (type) {
|
|
1775
|
+
case "Point":
|
|
1776
|
+
case "MultiPoint":
|
|
1777
|
+
case "LineString":
|
|
1778
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
1779
|
+
break;
|
|
1780
|
+
case "MultiLineString":
|
|
1781
|
+
case "Polygon":
|
|
1782
|
+
newGeometry = [];
|
|
1783
|
+
for (const line of feature.geometry) {
|
|
1784
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
1481
1785
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1786
|
+
break;
|
|
1787
|
+
case "MultiPolygon":
|
|
1788
|
+
newGeometry = [];
|
|
1789
|
+
for (const polygon of feature.geometry) {
|
|
1790
|
+
const newPolygon = [];
|
|
1791
|
+
for (const line of polygon) {
|
|
1792
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
1793
|
+
}
|
|
1794
|
+
newGeometry.push(newPolygon);
|
|
1795
|
+
}
|
|
1796
|
+
break;
|
|
1797
|
+
default:
|
|
1798
|
+
throw new Error(String(type));
|
|
1484
1799
|
}
|
|
1485
|
-
newFeatures.push(
|
|
1800
|
+
newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
1486
1801
|
}
|
|
1487
1802
|
return newFeatures;
|
|
1488
1803
|
}
|
|
@@ -1499,196 +1814,86 @@ function shiftCoords(points, offset) {
|
|
|
1499
1814
|
return newPoints;
|
|
1500
1815
|
}
|
|
1501
1816
|
|
|
1502
|
-
// dist/
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
const ring = [];
|
|
1521
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
1522
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
1523
|
-
}
|
|
1524
|
-
feature.geometry.push(ring);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
tile.transformed = true;
|
|
1529
|
-
return tile;
|
|
1530
|
-
}
|
|
1531
|
-
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
1532
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
// dist/lib/geojsonvt/tile.js
|
|
1536
|
-
function createTile(features, z, tx, ty, options) {
|
|
1537
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
1538
|
-
const tile = {
|
|
1539
|
-
features: [],
|
|
1540
|
-
numPoints: 0,
|
|
1541
|
-
numSimplified: 0,
|
|
1542
|
-
numFeatures: features.length,
|
|
1543
|
-
source: null,
|
|
1544
|
-
x: tx,
|
|
1545
|
-
y: ty,
|
|
1546
|
-
z,
|
|
1547
|
-
transformed: false,
|
|
1548
|
-
minX: 2,
|
|
1549
|
-
minY: 1,
|
|
1550
|
-
maxX: -1,
|
|
1551
|
-
maxY: 0
|
|
1552
|
-
};
|
|
1553
|
-
for (const feature of features) {
|
|
1554
|
-
addFeature(tile, feature, tolerance, options);
|
|
1555
|
-
}
|
|
1556
|
-
return tile;
|
|
1557
|
-
}
|
|
1558
|
-
function addFeature(tile, feature, tolerance, options) {
|
|
1559
|
-
const geom = feature.geometry;
|
|
1560
|
-
const type = feature.type;
|
|
1561
|
-
const simplified = [];
|
|
1562
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
1563
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
1564
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
1565
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
1566
|
-
if (type === "Point" || type === "MultiPoint") {
|
|
1567
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
1568
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
1569
|
-
tile.numPoints++;
|
|
1570
|
-
tile.numSimplified++;
|
|
1571
|
-
}
|
|
1572
|
-
} else if (type === "LineString") {
|
|
1573
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
1574
|
-
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
1575
|
-
for (let i = 0; i < geom.length; i++) {
|
|
1576
|
-
addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
|
|
1577
|
-
}
|
|
1578
|
-
} else if (type === "MultiPolygon") {
|
|
1579
|
-
for (let k = 0; k < geom.length; k++) {
|
|
1580
|
-
const polygon = geom[k];
|
|
1581
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
1582
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
if (simplified.length) {
|
|
1587
|
-
let tags = feature.tags || null;
|
|
1588
|
-
if (type === "LineString" && options.lineMetrics) {
|
|
1589
|
-
tags = {};
|
|
1590
|
-
for (const key in feature.tags)
|
|
1591
|
-
tags[key] = feature.tags[key];
|
|
1592
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
1593
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
1594
|
-
}
|
|
1595
|
-
const tileFeature = {
|
|
1596
|
-
geometry: simplified,
|
|
1597
|
-
type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
|
|
1598
|
-
tags
|
|
1599
|
-
};
|
|
1600
|
-
if (feature.id !== null) {
|
|
1601
|
-
tileFeature.id = feature.id;
|
|
1602
|
-
}
|
|
1603
|
-
tile.features.push(tileFeature);
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
1607
|
-
const sqTolerance = tolerance * tolerance;
|
|
1608
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
1609
|
-
tile.numPoints += geom.length / 3;
|
|
1610
|
-
return;
|
|
1611
|
-
}
|
|
1612
|
-
const ring = [];
|
|
1613
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
1614
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
1615
|
-
tile.numSimplified++;
|
|
1616
|
-
ring.push(geom[i], geom[i + 1]);
|
|
1617
|
-
}
|
|
1618
|
-
tile.numPoints++;
|
|
1619
|
-
}
|
|
1620
|
-
if (isPolygon)
|
|
1621
|
-
rewind(ring, isOuter);
|
|
1622
|
-
result.push(ring);
|
|
1623
|
-
}
|
|
1624
|
-
function rewind(ring, clockwise) {
|
|
1625
|
-
let area = 0;
|
|
1626
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
1627
|
-
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
1628
|
-
}
|
|
1629
|
-
if (area > 0 === clockwise) {
|
|
1630
|
-
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
1631
|
-
const x = ring[i];
|
|
1632
|
-
const y = ring[i + 1];
|
|
1633
|
-
ring[i] = ring[len - 2 - i];
|
|
1634
|
-
ring[i + 1] = ring[len - 1 - i];
|
|
1635
|
-
ring[len - 2 - i] = x;
|
|
1636
|
-
ring[len - 1 - i] = y;
|
|
1817
|
+
// dist/table-tile-source.js
|
|
1818
|
+
var TableTileSource = {
|
|
1819
|
+
name: "TableTiler",
|
|
1820
|
+
id: "table-tiler",
|
|
1821
|
+
version: "0.0.0",
|
|
1822
|
+
extensions: ["mvt"],
|
|
1823
|
+
mimeTypes: ["application/octet-stream"],
|
|
1824
|
+
options: {
|
|
1825
|
+
table: {
|
|
1826
|
+
coordinates: "local",
|
|
1827
|
+
promoteId: void 0,
|
|
1828
|
+
maxZoom: 14,
|
|
1829
|
+
indexMaxZoom: 5,
|
|
1830
|
+
maxPointsPerTile: 1e4,
|
|
1831
|
+
tolerance: 3,
|
|
1832
|
+
extent: 4096,
|
|
1833
|
+
buffer: 64,
|
|
1834
|
+
generateId: void 0
|
|
1637
1835
|
}
|
|
1836
|
+
},
|
|
1837
|
+
type: "table",
|
|
1838
|
+
testURL: (url) => url.endsWith(".geojson"),
|
|
1839
|
+
createDataSource(url, options) {
|
|
1840
|
+
var _a, _b;
|
|
1841
|
+
const needsLoading = typeof url === "string" || url instanceof Blob;
|
|
1842
|
+
const loader = (_b = (_a = options == null ? void 0 : options.table) == null ? void 0 : _a.loaders) == null ? void 0 : _b[0];
|
|
1843
|
+
const tablePromise = needsLoading ? loadTable(url, loader) : url;
|
|
1844
|
+
return new DynamicVectorTileSource(tablePromise, options);
|
|
1638
1845
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1846
|
+
// @ts-expect-error
|
|
1847
|
+
};
|
|
1848
|
+
async function loadTable(url, loader) {
|
|
1849
|
+
if (typeof url === "string") {
|
|
1850
|
+
const response = await fetch(url);
|
|
1851
|
+
const data2 = await response.arrayBuffer();
|
|
1852
|
+
return await loader.parse(data2);
|
|
1853
|
+
}
|
|
1854
|
+
const data = await url.arrayBuffer();
|
|
1855
|
+
return await loader.parse(data);
|
|
1856
|
+
}
|
|
1857
|
+
var _DynamicVectorTileSource = class {
|
|
1858
|
+
/** Stats for this DynamicVectorTileSource */
|
|
1859
|
+
stats = new import_stats.Stats({
|
|
1860
|
+
id: "table-tile-source",
|
|
1861
|
+
stats: [new import_stats.Stat("tiles", "count"), new import_stats.Stat("features", "count")]
|
|
1862
|
+
});
|
|
1863
|
+
/** MIME type of the tiles emitted by this tile source */
|
|
1643
1864
|
mimeType = "application/vnd.mapbox-vector-tile";
|
|
1644
|
-
|
|
1645
|
-
|
|
1865
|
+
localCoordinates = true;
|
|
1866
|
+
/** The props that this tile source was created with */
|
|
1867
|
+
// @ts-expect-error
|
|
1868
|
+
props;
|
|
1869
|
+
/* Schema of the data */
|
|
1870
|
+
schema = null;
|
|
1871
|
+
/** Map of generated tiles, indexed by stringified tile coordinates */
|
|
1646
1872
|
tiles = {};
|
|
1873
|
+
/** Array of tile coordinates */
|
|
1647
1874
|
tileCoords = [];
|
|
1648
|
-
|
|
1649
|
-
total = 0;
|
|
1650
|
-
/** Sync methods can be called: the input data promise has been resolved and initial top-level tiling is done */
|
|
1875
|
+
/** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
|
|
1651
1876
|
ready;
|
|
1652
|
-
|
|
1653
|
-
|
|
1877
|
+
/** Metadata for the tile source (generated TileJSON/tilestats */
|
|
1878
|
+
metadata;
|
|
1879
|
+
constructor(table, props) {
|
|
1880
|
+
this.props = { ...TableTileSource.options.table, ...props == null ? void 0 : props.table };
|
|
1654
1881
|
this.getTileData = this.getTileData.bind(this);
|
|
1655
|
-
this.ready = this.initializeTilesAsync(
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
const options = this.options;
|
|
1663
|
-
const debug = options.debug;
|
|
1664
|
-
if (debug)
|
|
1665
|
-
console.time("preprocess data");
|
|
1666
|
-
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
1667
|
-
throw new Error("maxZoom should be in the 0-24 range");
|
|
1668
|
-
}
|
|
1669
|
-
if (options.promoteId && this.options.generateId) {
|
|
1670
|
-
throw new Error("promoteId and generateId cannot be used together.");
|
|
1671
|
-
}
|
|
1672
|
-
let features = convert(data, options);
|
|
1673
|
-
if (debug) {
|
|
1674
|
-
console.timeEnd("preprocess data");
|
|
1675
|
-
console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
|
|
1676
|
-
console.time("generate tiles");
|
|
1677
|
-
}
|
|
1678
|
-
features = wrap(features, this.options);
|
|
1679
|
-
if (features.length) {
|
|
1680
|
-
this.splitTile(features, 0, 0, 0);
|
|
1681
|
-
}
|
|
1682
|
-
if (debug) {
|
|
1683
|
-
if (features.length) {
|
|
1684
|
-
console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
1685
|
-
}
|
|
1686
|
-
console.timeEnd("generate tiles");
|
|
1687
|
-
console.log("tiles generated:", this.total, JSON.stringify(this.stats));
|
|
1688
|
-
}
|
|
1882
|
+
this.ready = this.initializeTilesAsync(table);
|
|
1883
|
+
this.metadata = this.getMetadata();
|
|
1884
|
+
}
|
|
1885
|
+
async initializeTilesAsync(tablePromise) {
|
|
1886
|
+
const table = await tablePromise;
|
|
1887
|
+
this.schema = (0, import_schema.deduceTableSchema)(table);
|
|
1888
|
+
this.createRootTiles(table);
|
|
1689
1889
|
}
|
|
1690
1890
|
async getMetadata() {
|
|
1691
|
-
|
|
1891
|
+
await this.ready;
|
|
1892
|
+
return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
|
|
1893
|
+
}
|
|
1894
|
+
async getSchema() {
|
|
1895
|
+
await this.ready;
|
|
1896
|
+
return this.schema;
|
|
1692
1897
|
}
|
|
1693
1898
|
/**
|
|
1694
1899
|
* Get a tile at the specified index
|
|
@@ -1698,6 +1903,7 @@ var _GeoJSONTileSource = class {
|
|
|
1698
1903
|
async getVectorTile(tileIndex) {
|
|
1699
1904
|
await this.ready;
|
|
1700
1905
|
const table = this.getTileSync(tileIndex);
|
|
1906
|
+
import_loader_utils3.log.info(2, "getVectorTile", tileIndex, table)();
|
|
1701
1907
|
return table;
|
|
1702
1908
|
}
|
|
1703
1909
|
async getTile(tileIndex) {
|
|
@@ -1706,7 +1912,8 @@ var _GeoJSONTileSource = class {
|
|
|
1706
1912
|
}
|
|
1707
1913
|
async getTileData(tileParams) {
|
|
1708
1914
|
const { x, y, z } = tileParams.index;
|
|
1709
|
-
|
|
1915
|
+
const tile = await this.getVectorTile({ x, y, z });
|
|
1916
|
+
return (tile == null ? void 0 : tile.features) || [];
|
|
1710
1917
|
}
|
|
1711
1918
|
// Implementation
|
|
1712
1919
|
/**
|
|
@@ -1714,21 +1921,52 @@ var _GeoJSONTileSource = class {
|
|
|
1714
1921
|
* @note Application must await `source.ready` before calling sync methods.
|
|
1715
1922
|
*/
|
|
1716
1923
|
getTileSync(tileIndex) {
|
|
1717
|
-
const
|
|
1718
|
-
if (!
|
|
1924
|
+
const protoTile = this.getProtoTile(tileIndex);
|
|
1925
|
+
if (!protoTile) {
|
|
1719
1926
|
return null;
|
|
1720
1927
|
}
|
|
1721
|
-
return
|
|
1928
|
+
return convertTileToGeoJSON(protoTile, {
|
|
1929
|
+
coordinates: this.props.coordinates,
|
|
1930
|
+
tileIndex,
|
|
1931
|
+
extent: this.props.extent
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Create the initial tiles
|
|
1936
|
+
* @note the tiles stores all the features together with additional data
|
|
1937
|
+
*/
|
|
1938
|
+
createRootTiles(table) {
|
|
1939
|
+
if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
|
|
1940
|
+
throw new Error("maxZoom should be in the 0-24 range");
|
|
1941
|
+
}
|
|
1942
|
+
if (this.props.promoteId && this.props.generateId) {
|
|
1943
|
+
throw new Error("promoteId and generateId cannot be used together.");
|
|
1944
|
+
}
|
|
1945
|
+
import_loader_utils3.log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
|
|
1946
|
+
import_loader_utils3.log.time(1, "preprocess table")();
|
|
1947
|
+
let features2 = convertFeaturesToProtoFeature(table, this.props);
|
|
1948
|
+
import_loader_utils3.log.timeEnd(1, "preprocess table")();
|
|
1949
|
+
import_loader_utils3.log.time(1, "generate tiles")();
|
|
1950
|
+
features2 = wrapFeatures(features2, this.props);
|
|
1951
|
+
if (features2.length === 0) {
|
|
1952
|
+
import_loader_utils3.log.log(1, "DynamicVectorTileSource: no features generated")();
|
|
1953
|
+
return;
|
|
1954
|
+
}
|
|
1955
|
+
this.splitTile(features2, 0, 0, 0);
|
|
1956
|
+
const rootTile = this.tiles[0];
|
|
1957
|
+
import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
|
|
1958
|
+
import_loader_utils3.log.timeEnd(1, "generate tiles")();
|
|
1959
|
+
import_loader_utils3.log.log(1, `DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
|
|
1722
1960
|
}
|
|
1723
1961
|
/**
|
|
1724
1962
|
* Return geojsonvt-style "half formed" vector tile
|
|
1725
1963
|
* @note Application must await `source.ready` before calling sync methods.
|
|
1726
1964
|
*/
|
|
1727
1965
|
// eslint-disable-next-line complexity, max-statements
|
|
1728
|
-
|
|
1966
|
+
getProtoTile(tileIndex) {
|
|
1729
1967
|
const { z, y } = tileIndex;
|
|
1730
1968
|
let { x } = tileIndex;
|
|
1731
|
-
const { extent
|
|
1969
|
+
const { extent } = this.props;
|
|
1732
1970
|
if (z < 0 || z > 24) {
|
|
1733
1971
|
return null;
|
|
1734
1972
|
}
|
|
@@ -1738,8 +1976,7 @@ var _GeoJSONTileSource = class {
|
|
|
1738
1976
|
if (this.tiles[id]) {
|
|
1739
1977
|
return transformTile(this.tiles[id], extent);
|
|
1740
1978
|
}
|
|
1741
|
-
|
|
1742
|
-
console.log("drilling down to z%d-%d-%d", z, x, y);
|
|
1979
|
+
import_loader_utils3.log.log(import_loader_utils3.log, "drilling down to z%d-%d-%d", z, x, y)();
|
|
1743
1980
|
let z0 = z;
|
|
1744
1981
|
let x0 = x;
|
|
1745
1982
|
let y0 = y;
|
|
@@ -1750,17 +1987,13 @@ var _GeoJSONTileSource = class {
|
|
|
1750
1987
|
y0 = y0 >> 1;
|
|
1751
1988
|
parent = this.tiles[toID(z0, x0, y0)];
|
|
1752
1989
|
}
|
|
1753
|
-
if (!parent || !parent.
|
|
1990
|
+
if (!parent || !parent.sourceFeatures) {
|
|
1754
1991
|
return null;
|
|
1755
1992
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
this.splitTile(parent.source, z0, x0, y0, z, x, y);
|
|
1761
|
-
if (debug > 1) {
|
|
1762
|
-
console.timeEnd("drilling down");
|
|
1763
|
-
}
|
|
1993
|
+
import_loader_utils3.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
|
|
1994
|
+
import_loader_utils3.log.time(1, "drilling down")();
|
|
1995
|
+
this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
|
|
1996
|
+
import_loader_utils3.log.timeEnd(1, "drilling down")();
|
|
1764
1997
|
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
1765
1998
|
}
|
|
1766
1999
|
/**
|
|
@@ -1769,54 +2002,53 @@ var _GeoJSONTileSource = class {
|
|
|
1769
2002
|
* @param cz, cx, and cy are the coordinates of the target tile
|
|
1770
2003
|
*
|
|
1771
2004
|
* If no target tile is specified, splitting stops when we reach the maximum
|
|
1772
|
-
* zoom or the number of points is low as specified in the
|
|
2005
|
+
* zoom or the number of points is low as specified in the props.
|
|
1773
2006
|
*/
|
|
1774
2007
|
// eslint-disable-next-line max-params, max-statements, complexity
|
|
1775
|
-
splitTile(
|
|
1776
|
-
const stack = [
|
|
1777
|
-
const options = this.options;
|
|
1778
|
-
const debug = options.debug;
|
|
2008
|
+
splitTile(features2, z, x, y, cz, cx, cy) {
|
|
2009
|
+
const stack = [features2, z, x, y];
|
|
1779
2010
|
while (stack.length) {
|
|
1780
2011
|
y = stack.pop();
|
|
1781
2012
|
x = stack.pop();
|
|
1782
2013
|
z = stack.pop();
|
|
1783
|
-
|
|
2014
|
+
features2 = stack.pop();
|
|
1784
2015
|
const z2 = 1 << z;
|
|
1785
2016
|
const id = toID(z, x, y);
|
|
1786
2017
|
let tile = this.tiles[id];
|
|
1787
2018
|
if (!tile) {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
}
|
|
1791
|
-
tile = this.tiles[id] = createTile(features, z, x, y, options);
|
|
2019
|
+
import_loader_utils3.log.time(2, "tile creation")();
|
|
2020
|
+
tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
|
|
1792
2021
|
this.tileCoords.push({ z, x, y });
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
2022
|
+
const key = `z${z}`;
|
|
2023
|
+
let stat = this.stats.get(key, "count");
|
|
2024
|
+
stat.incrementCount();
|
|
2025
|
+
stat = this.stats.get("total");
|
|
2026
|
+
stat.incrementCount();
|
|
2027
|
+
stat = _DynamicVectorTileSource.stats.get(key, "count");
|
|
2028
|
+
stat.incrementCount();
|
|
2029
|
+
stat = _DynamicVectorTileSource.stats.get("total");
|
|
2030
|
+
stat.incrementCount();
|
|
2031
|
+
import_loader_utils3.log.log(2, "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
|
|
2032
|
+
import_loader_utils3.log.timeEnd(2, "tile creation")();
|
|
1802
2033
|
}
|
|
1803
|
-
tile.
|
|
2034
|
+
tile.sourceFeatures = features2;
|
|
1804
2035
|
if (cz === void 0) {
|
|
1805
|
-
if (z ===
|
|
2036
|
+
if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
|
|
1806
2037
|
continue;
|
|
1807
|
-
|
|
2038
|
+
}
|
|
2039
|
+
} else if (z === this.props.maxZoom || z === cz) {
|
|
1808
2040
|
continue;
|
|
1809
2041
|
} else if (cz !== void 0) {
|
|
1810
2042
|
const zoomSteps = cz - z;
|
|
1811
|
-
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
|
|
2043
|
+
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
|
|
1812
2044
|
continue;
|
|
2045
|
+
}
|
|
1813
2046
|
}
|
|
1814
|
-
tile.
|
|
1815
|
-
if (
|
|
2047
|
+
tile.sourceFeatures = null;
|
|
2048
|
+
if (features2.length === 0)
|
|
1816
2049
|
continue;
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
const k1 = 0.5 * options.buffer / options.extent;
|
|
2050
|
+
import_loader_utils3.log.time(2, "clipping tile")();
|
|
2051
|
+
const k1 = 0.5 * this.props.buffer / this.props.extent;
|
|
1820
2052
|
const k2 = 0.5 - k1;
|
|
1821
2053
|
const k3 = 0.5 + k1;
|
|
1822
2054
|
const k4 = 1 + k1;
|
|
@@ -1824,21 +2056,20 @@ var _GeoJSONTileSource = class {
|
|
|
1824
2056
|
let bl = null;
|
|
1825
2057
|
let tr = null;
|
|
1826
2058
|
let br = null;
|
|
1827
|
-
let left =
|
|
1828
|
-
let right =
|
|
1829
|
-
|
|
2059
|
+
let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
|
|
2060
|
+
let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
|
|
2061
|
+
features2 = null;
|
|
1830
2062
|
if (left) {
|
|
1831
|
-
tl =
|
|
1832
|
-
bl =
|
|
2063
|
+
tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
2064
|
+
bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
1833
2065
|
left = null;
|
|
1834
2066
|
}
|
|
1835
2067
|
if (right) {
|
|
1836
|
-
tr =
|
|
1837
|
-
br =
|
|
2068
|
+
tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
2069
|
+
br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
1838
2070
|
right = null;
|
|
1839
2071
|
}
|
|
1840
|
-
|
|
1841
|
-
console.timeEnd("clipping");
|
|
2072
|
+
import_loader_utils3.log.timeEnd(2, "clipping tile")();
|
|
1842
2073
|
stack.push(tl || [], z + 1, x * 2, y * 2);
|
|
1843
2074
|
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
|
|
1844
2075
|
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
|
|
@@ -1846,94 +2077,13 @@ var _GeoJSONTileSource = class {
|
|
|
1846
2077
|
}
|
|
1847
2078
|
}
|
|
1848
2079
|
};
|
|
1849
|
-
var
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
indexMaxPoints: 1e5,
|
|
1856
|
-
// max number of points per tile in the tile index
|
|
1857
|
-
tolerance: 3,
|
|
1858
|
-
// simplification tolerance (higher means simpler)
|
|
1859
|
-
extent: 4096,
|
|
1860
|
-
// tile extent
|
|
1861
|
-
buffer: 64,
|
|
1862
|
-
// tile buffer on each side
|
|
1863
|
-
lineMetrics: false,
|
|
1864
|
-
// whether to calculate line metrics
|
|
1865
|
-
// @ts-expect-error
|
|
1866
|
-
promoteId: void 0,
|
|
1867
|
-
// name of a feature property to be promoted to feature.id
|
|
1868
|
-
generateId: false,
|
|
1869
|
-
// whether to generate feature ids. Cannot be used with promoteId
|
|
1870
|
-
debug: 0
|
|
1871
|
-
// logging level (0, 1 or 2)
|
|
1872
|
-
});
|
|
2080
|
+
var DynamicVectorTileSource = _DynamicVectorTileSource;
|
|
2081
|
+
/** Global stats for all DynamicVectorTileSources */
|
|
2082
|
+
__publicField(DynamicVectorTileSource, "stats", new import_stats.Stats({
|
|
2083
|
+
id: "table-tile-source-all",
|
|
2084
|
+
stats: [new import_stats.Stat("count", "tiles"), new import_stats.Stat("count", "features")]
|
|
2085
|
+
}));
|
|
1873
2086
|
function toID(z, x, y) {
|
|
1874
2087
|
return ((1 << z) * y + x) * 32 + z;
|
|
1875
2088
|
}
|
|
1876
|
-
function convertToGeoJSONTable(vtTile, extent) {
|
|
1877
|
-
const features = [];
|
|
1878
|
-
for (const rawFeature of vtTile.features) {
|
|
1879
|
-
if (!rawFeature || !rawFeature.geometry) {
|
|
1880
|
-
continue;
|
|
1881
|
-
}
|
|
1882
|
-
let type;
|
|
1883
|
-
let coordinates;
|
|
1884
|
-
switch (rawFeature.type) {
|
|
1885
|
-
case 1:
|
|
1886
|
-
if (rawFeature.geometry.length === 1) {
|
|
1887
|
-
type = "Point";
|
|
1888
|
-
coordinates = rawFeature.geometry[0];
|
|
1889
|
-
} else {
|
|
1890
|
-
type = "MultiPoint";
|
|
1891
|
-
coordinates = rawFeature.geometry;
|
|
1892
|
-
}
|
|
1893
|
-
break;
|
|
1894
|
-
case 2:
|
|
1895
|
-
if (rawFeature.geometry.length === 1) {
|
|
1896
|
-
type = "LineString";
|
|
1897
|
-
coordinates = rawFeature.geometry[0];
|
|
1898
|
-
} else {
|
|
1899
|
-
type = "MultiLineString";
|
|
1900
|
-
coordinates = rawFeature.geometry;
|
|
1901
|
-
}
|
|
1902
|
-
break;
|
|
1903
|
-
case 3:
|
|
1904
|
-
if (rawFeature.geometry.length > 1) {
|
|
1905
|
-
type = "MultiPolygon";
|
|
1906
|
-
coordinates = [rawFeature.geometry];
|
|
1907
|
-
} else {
|
|
1908
|
-
type = "Polygon";
|
|
1909
|
-
coordinates = rawFeature.geometry;
|
|
1910
|
-
}
|
|
1911
|
-
break;
|
|
1912
|
-
default:
|
|
1913
|
-
continue;
|
|
1914
|
-
}
|
|
1915
|
-
coordinates = toLngLat(coordinates, extent);
|
|
1916
|
-
const feature = {
|
|
1917
|
-
type: "Feature",
|
|
1918
|
-
geometry: {
|
|
1919
|
-
type,
|
|
1920
|
-
coordinates
|
|
1921
|
-
},
|
|
1922
|
-
properties: rawFeature.tags || {}
|
|
1923
|
-
};
|
|
1924
|
-
features.push(feature);
|
|
1925
|
-
}
|
|
1926
|
-
const table = {
|
|
1927
|
-
shape: "geojson-table",
|
|
1928
|
-
type: "FeatureCollection",
|
|
1929
|
-
features
|
|
1930
|
-
};
|
|
1931
|
-
return table;
|
|
1932
|
-
}
|
|
1933
|
-
function toLngLat(coords, extent) {
|
|
1934
|
-
if (Array.isArray(coords[0])) {
|
|
1935
|
-
return coords.map((c) => toLngLat(c, extent));
|
|
1936
|
-
}
|
|
1937
|
-
return [coords[0] / extent, coords[1] / extent];
|
|
1938
|
-
}
|
|
1939
2089
|
//# sourceMappingURL=index.cjs.map
|