@loaders.gl/mvt 4.0.0-alpha.8 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +228 -24
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +8 -7
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/lib/parse-tilejson.js +186 -0
- package/dist/es5/lib/parse-tilejson.js.map +1 -0
- package/dist/es5/lib/types.js.map +1 -1
- package/dist/es5/mvt-loader.js +10 -11
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/es5/tilejson-loader.js +50 -0
- package/dist/es5/tilejson-loader.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +8 -7
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/lib/parse-tilejson.js +157 -0
- package/dist/esm/lib/parse-tilejson.js.map +1 -0
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/mvt-loader.js +10 -11
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/esm/tilejson-loader.js +25 -0
- package/dist/esm/tilejson-loader.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/parse-mvt.d.ts +3 -3
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.d.ts +46 -0
- package/dist/lib/parse-tilejson.d.ts.map +1 -0
- package/dist/lib/types.d.ts +4 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-loader.d.ts +5 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-worker.js +40 -26
- package/dist/tilejson-loader.d.ts +10 -0
- package/dist/tilejson-loader.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +5 -0
- package/src/lib/parse-mvt.ts +15 -11
- package/src/lib/parse-tilejson.ts +314 -0
- package/src/lib/types.ts +4 -4
- package/src/mvt-loader.ts +27 -13
- package/src/tilejson-loader.ts +39 -0
- package/dist/bundle.js +0 -5
- package/dist/helpers/binary-util-functions.js +0 -118
- package/dist/helpers/mapbox-util-functions.js +0 -82
- package/dist/index.js +0 -9
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -156
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -91
- package/dist/lib/binary-vector-tile/vector-tile.js +0 -29
- package/dist/lib/geojson-tiler/clip.js +0 -209
- package/dist/lib/geojson-tiler/convert.js +0 -134
- package/dist/lib/geojson-tiler/feature.js +0 -46
- package/dist/lib/geojson-tiler/geojson-tiler.js +0 -210
- package/dist/lib/geojson-tiler/simplify.js +0 -68
- package/dist/lib/geojson-tiler/tile.js +0 -125
- package/dist/lib/geojson-tiler/transform.js +0 -43
- package/dist/lib/geojson-tiler/wrap.js +0 -86
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -170
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +0 -89
- package/dist/lib/mapbox-vector-tile/vector-tile.js +0 -29
- package/dist/lib/parse-mvt.js +0 -167
- package/dist/lib/types.js +0 -2
- package/dist/mvt-loader.js +0 -47
- package/dist/workers/mvt-worker.js +0 -5
package/dist/dist.min.js
CHANGED
|
@@ -612,7 +612,8 @@
|
|
|
612
612
|
...geometryInfo
|
|
613
613
|
}, {
|
|
614
614
|
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
615
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
615
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
616
|
+
triangulate: options ? options.triangulate : true
|
|
616
617
|
});
|
|
617
618
|
}
|
|
618
619
|
function extractNumericPropTypes(features) {
|
|
@@ -641,7 +642,7 @@
|
|
|
641
642
|
propArrayTypes,
|
|
642
643
|
coordLength
|
|
643
644
|
} = geometryInfo;
|
|
644
|
-
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
645
|
+
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
645
646
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
646
647
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
647
648
|
const points = {
|
|
@@ -668,13 +669,15 @@
|
|
|
668
669
|
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
669
670
|
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
670
671
|
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
671
|
-
triangles: [],
|
|
672
672
|
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
673
673
|
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
674
674
|
numericProps: {},
|
|
675
675
|
properties: [],
|
|
676
676
|
fields: []
|
|
677
677
|
};
|
|
678
|
+
if (triangulate) {
|
|
679
|
+
polygons.triangles = [];
|
|
680
|
+
}
|
|
678
681
|
for (const object of [points, lines, polygons]) {
|
|
679
682
|
for (const propName of numericPropKeys) {
|
|
680
683
|
const T = propArrayTypes[propName];
|
|
@@ -779,6 +782,9 @@
|
|
|
779
782
|
endPosition,
|
|
780
783
|
coordLength
|
|
781
784
|
}) {
|
|
785
|
+
if (!polygons.triangles) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
782
788
|
const start = startPosition * coordLength;
|
|
783
789
|
const end = endPosition * coordLength;
|
|
784
790
|
const polygonPositions = polygons.positions.subarray(start, end);
|
|
@@ -797,7 +803,7 @@
|
|
|
797
803
|
return returnObj;
|
|
798
804
|
}
|
|
799
805
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
800
|
-
|
|
806
|
+
const binaryFeatures = {
|
|
801
807
|
points: {
|
|
802
808
|
...points,
|
|
803
809
|
positions: { value: points.positions, size: coordLength },
|
|
@@ -818,12 +824,15 @@
|
|
|
818
824
|
positions: { value: polygons.positions, size: coordLength },
|
|
819
825
|
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
820
826
|
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
821
|
-
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
822
827
|
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
823
828
|
featureIds: { value: polygons.featureIds, size: 1 },
|
|
824
829
|
numericProps: wrapProps(polygons.numericProps, 1)
|
|
825
830
|
}
|
|
826
831
|
};
|
|
832
|
+
if (binaryFeatures.polygons && polygons.triangles) {
|
|
833
|
+
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
834
|
+
}
|
|
835
|
+
return binaryFeatures;
|
|
827
836
|
}
|
|
828
837
|
function fillNumericProperties(object, properties, index, length2) {
|
|
829
838
|
for (const numericPropName in object.numericProps) {
|
|
@@ -2166,25 +2175,26 @@
|
|
|
2166
2175
|
// src/lib/parse-mvt.ts
|
|
2167
2176
|
function parseMVT(arrayBuffer, options) {
|
|
2168
2177
|
const mvtOptions = normalizeOptions(options);
|
|
2169
|
-
const shape = options?.gis?.format || options?.mvt?.shape;
|
|
2178
|
+
const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
|
|
2170
2179
|
switch (shape) {
|
|
2171
2180
|
case "columnar-table":
|
|
2172
2181
|
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2173
|
-
case "geojson-
|
|
2182
|
+
case "geojson-table": {
|
|
2174
2183
|
const table = {
|
|
2175
|
-
shape: "geojson-
|
|
2176
|
-
|
|
2184
|
+
shape: "geojson-table",
|
|
2185
|
+
type: "FeatureCollection",
|
|
2186
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
2177
2187
|
};
|
|
2178
2188
|
return table;
|
|
2179
2189
|
}
|
|
2180
2190
|
case "geojson":
|
|
2181
|
-
return
|
|
2191
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
2182
2192
|
case "binary-geometry":
|
|
2183
2193
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2184
2194
|
case "binary":
|
|
2185
2195
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2186
2196
|
default:
|
|
2187
|
-
throw new Error(shape);
|
|
2197
|
+
throw new Error(shape || "undefined shape");
|
|
2188
2198
|
}
|
|
2189
2199
|
}
|
|
2190
2200
|
function parseToBinary(arrayBuffer, options) {
|
|
@@ -2225,7 +2235,7 @@
|
|
|
2225
2235
|
});
|
|
2226
2236
|
return [features, geometryInfo];
|
|
2227
2237
|
}
|
|
2228
|
-
function
|
|
2238
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
2229
2239
|
if (arrayBuffer.byteLength <= 0) {
|
|
2230
2240
|
return [];
|
|
2231
2241
|
}
|
|
@@ -2296,20 +2306,11 @@
|
|
|
2296
2306
|
});
|
|
2297
2307
|
|
|
2298
2308
|
// src/mvt-loader.ts
|
|
2299
|
-
var VERSION,
|
|
2309
|
+
var VERSION, MVTWorkerLoader, MVTLoader;
|
|
2300
2310
|
var init_mvt_loader = __esm({
|
|
2301
2311
|
"src/mvt-loader.ts"() {
|
|
2302
2312
|
init_parse_mvt();
|
|
2303
2313
|
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2304
|
-
DEFAULT_MVT_LOADER_OPTIONS = {
|
|
2305
|
-
mvt: {
|
|
2306
|
-
shape: "geojson",
|
|
2307
|
-
coordinates: "local",
|
|
2308
|
-
layerProperty: "layerName",
|
|
2309
|
-
layers: void 0,
|
|
2310
|
-
tileIndex: null
|
|
2311
|
-
}
|
|
2312
|
-
};
|
|
2313
2314
|
MVTWorkerLoader = {
|
|
2314
2315
|
name: "Mapbox Vector Tile",
|
|
2315
2316
|
id: "mvt",
|
|
@@ -2322,7 +2323,15 @@
|
|
|
2322
2323
|
],
|
|
2323
2324
|
worker: true,
|
|
2324
2325
|
category: "geometry",
|
|
2325
|
-
options:
|
|
2326
|
+
options: {
|
|
2327
|
+
mvt: {
|
|
2328
|
+
shape: "geojson",
|
|
2329
|
+
coordinates: "local",
|
|
2330
|
+
layerProperty: "layerName",
|
|
2331
|
+
layers: void 0,
|
|
2332
|
+
tileIndex: null
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2326
2335
|
};
|
|
2327
2336
|
MVTLoader = {
|
|
2328
2337
|
...MVTWorkerLoader,
|
|
@@ -2333,6 +2342,199 @@
|
|
|
2333
2342
|
}
|
|
2334
2343
|
});
|
|
2335
2344
|
|
|
2345
|
+
// src/lib/parse-tilejson.ts
|
|
2346
|
+
function parseTileJSON(jsonMetadata) {
|
|
2347
|
+
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
2348
|
+
return null;
|
|
2349
|
+
}
|
|
2350
|
+
const boundingBox = parseBounds(jsonMetadata.bounds);
|
|
2351
|
+
const center = parseCenter(jsonMetadata.center);
|
|
2352
|
+
const maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
2353
|
+
const minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
2354
|
+
let tileJSON = {
|
|
2355
|
+
name: jsonMetadata.name || "",
|
|
2356
|
+
description: jsonMetadata.description || "",
|
|
2357
|
+
boundingBox,
|
|
2358
|
+
center,
|
|
2359
|
+
maxZoom,
|
|
2360
|
+
minZoom,
|
|
2361
|
+
layers: []
|
|
2362
|
+
};
|
|
2363
|
+
if (typeof jsonMetadata?.json === "string") {
|
|
2364
|
+
try {
|
|
2365
|
+
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
2366
|
+
} catch (err) {
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
let layers = parseTilestatsLayers(tileJSON.metaJson?.tilestats);
|
|
2370
|
+
if (layers.length === 0) {
|
|
2371
|
+
layers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
2372
|
+
}
|
|
2373
|
+
tileJSON = {
|
|
2374
|
+
...tileJSON,
|
|
2375
|
+
layers
|
|
2376
|
+
};
|
|
2377
|
+
return tileJSON;
|
|
2378
|
+
}
|
|
2379
|
+
function parseTileJSONLayers(layers) {
|
|
2380
|
+
if (!Array.isArray(layers)) {
|
|
2381
|
+
return [];
|
|
2382
|
+
}
|
|
2383
|
+
return layers.map((layer) => ({
|
|
2384
|
+
name: layer.id || "",
|
|
2385
|
+
fields: Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
2386
|
+
name: key,
|
|
2387
|
+
...attributeTypeToFieldType(String(datatype))
|
|
2388
|
+
}))
|
|
2389
|
+
}));
|
|
2390
|
+
}
|
|
2391
|
+
function parseTilestatsLayers(tilestats) {
|
|
2392
|
+
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
2393
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer));
|
|
2394
|
+
}
|
|
2395
|
+
return [];
|
|
2396
|
+
}
|
|
2397
|
+
function parseTilestatsForLayer(layer) {
|
|
2398
|
+
const fields = [];
|
|
2399
|
+
const indexedAttributes = {};
|
|
2400
|
+
const attributes = layer.attributes || [];
|
|
2401
|
+
for (const attr of attributes) {
|
|
2402
|
+
const name = attr.attribute;
|
|
2403
|
+
if (typeof name === "string") {
|
|
2404
|
+
if (name.split("|").length > 1) {
|
|
2405
|
+
const fname = name.split("|")[0];
|
|
2406
|
+
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
2407
|
+
indexedAttributes[fname].push(attr);
|
|
2408
|
+
} else if (!fields[name]) {
|
|
2409
|
+
fields[name] = attributeToField(attr);
|
|
2410
|
+
} else {
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return {
|
|
2415
|
+
name: layer.layer || "",
|
|
2416
|
+
dominantGeometry: layer.geometry,
|
|
2417
|
+
fields
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
function parseBounds(bounds) {
|
|
2421
|
+
const result = fromArrayOrString(bounds);
|
|
2422
|
+
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
2423
|
+
return [
|
|
2424
|
+
[result[0], result[1]],
|
|
2425
|
+
[result[2], result[3]]
|
|
2426
|
+
];
|
|
2427
|
+
}
|
|
2428
|
+
return void 0;
|
|
2429
|
+
}
|
|
2430
|
+
function parseCenter(center) {
|
|
2431
|
+
const result = fromArrayOrString(center);
|
|
2432
|
+
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
2433
|
+
return result;
|
|
2434
|
+
}
|
|
2435
|
+
return null;
|
|
2436
|
+
}
|
|
2437
|
+
function safeParseFloat(input) {
|
|
2438
|
+
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
2439
|
+
return result === null || isNaN(result) ? null : result;
|
|
2440
|
+
}
|
|
2441
|
+
function isLat(num) {
|
|
2442
|
+
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
2443
|
+
}
|
|
2444
|
+
function isLng(num) {
|
|
2445
|
+
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
2446
|
+
}
|
|
2447
|
+
function isZoom(num) {
|
|
2448
|
+
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
2449
|
+
}
|
|
2450
|
+
function fromArrayOrString(data) {
|
|
2451
|
+
if (typeof data === "string") {
|
|
2452
|
+
return data.split(",").map(parseFloat);
|
|
2453
|
+
} else if (Array.isArray(data)) {
|
|
2454
|
+
return data;
|
|
2455
|
+
}
|
|
2456
|
+
return null;
|
|
2457
|
+
}
|
|
2458
|
+
function attributeToField(attribute = {}) {
|
|
2459
|
+
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
2460
|
+
return {
|
|
2461
|
+
name: attribute.attribute,
|
|
2462
|
+
...fieldTypes
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
function attributeTypeToFieldType(aType) {
|
|
2466
|
+
const type = aType.toLowerCase();
|
|
2467
|
+
if (!type || !attrTypeMap[type]) {
|
|
2468
|
+
}
|
|
2469
|
+
return attrTypeMap[type] || { type: "string" };
|
|
2470
|
+
}
|
|
2471
|
+
var isObject, attrTypeMap;
|
|
2472
|
+
var init_parse_tilejson = __esm({
|
|
2473
|
+
"src/lib/parse-tilejson.ts"() {
|
|
2474
|
+
isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
2475
|
+
attrTypeMap = {
|
|
2476
|
+
number: {
|
|
2477
|
+
type: "float32"
|
|
2478
|
+
},
|
|
2479
|
+
numeric: {
|
|
2480
|
+
type: "float32"
|
|
2481
|
+
},
|
|
2482
|
+
string: {
|
|
2483
|
+
type: "utf8"
|
|
2484
|
+
},
|
|
2485
|
+
vachar: {
|
|
2486
|
+
type: "utf8"
|
|
2487
|
+
},
|
|
2488
|
+
float: {
|
|
2489
|
+
type: "float32"
|
|
2490
|
+
},
|
|
2491
|
+
int: {
|
|
2492
|
+
type: "int32"
|
|
2493
|
+
},
|
|
2494
|
+
int4: {
|
|
2495
|
+
type: "int32"
|
|
2496
|
+
},
|
|
2497
|
+
boolean: {
|
|
2498
|
+
type: "boolean"
|
|
2499
|
+
},
|
|
2500
|
+
bool: {
|
|
2501
|
+
type: "boolean"
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
|
|
2507
|
+
// src/tilejson-loader.ts
|
|
2508
|
+
var VERSION2, TileJSONLoader;
|
|
2509
|
+
var init_tilejson_loader = __esm({
|
|
2510
|
+
"src/tilejson-loader.ts"() {
|
|
2511
|
+
init_parse_tilejson();
|
|
2512
|
+
VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2513
|
+
TileJSONLoader = {
|
|
2514
|
+
name: "TileJSON",
|
|
2515
|
+
id: "tilejson",
|
|
2516
|
+
module: "pmtiles",
|
|
2517
|
+
version: VERSION2,
|
|
2518
|
+
worker: true,
|
|
2519
|
+
extensions: ["json"],
|
|
2520
|
+
mimeTypes: ["application/json"],
|
|
2521
|
+
text: true,
|
|
2522
|
+
options: {
|
|
2523
|
+
tilejson: {}
|
|
2524
|
+
},
|
|
2525
|
+
parse: async (arrayBuffer, options) => {
|
|
2526
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
2527
|
+
const json = JSON.parse(jsonString);
|
|
2528
|
+
return parseTileJSON(json);
|
|
2529
|
+
},
|
|
2530
|
+
parseTextSync: (text, options) => {
|
|
2531
|
+
const json = JSON.parse(text);
|
|
2532
|
+
return parseTileJSON(json);
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
|
|
2336
2538
|
// src/lib/geojson-tiler/simplify.ts
|
|
2337
2539
|
function simplify(coords, first, last, sqTolerance) {
|
|
2338
2540
|
let maxSqDist = sqTolerance;
|
|
@@ -3102,11 +3304,13 @@
|
|
|
3102
3304
|
__export(src_exports, {
|
|
3103
3305
|
GeoJSONTiler: () => GeoJSONTiler,
|
|
3104
3306
|
MVTLoader: () => MVTLoader,
|
|
3105
|
-
MVTWorkerLoader: () => MVTWorkerLoader
|
|
3307
|
+
MVTWorkerLoader: () => MVTWorkerLoader,
|
|
3308
|
+
TileJSONLoader: () => TileJSONLoader
|
|
3106
3309
|
});
|
|
3107
3310
|
var init_src2 = __esm({
|
|
3108
3311
|
"src/index.ts"() {
|
|
3109
3312
|
init_mvt_loader();
|
|
3313
|
+
init_tilejson_loader();
|
|
3110
3314
|
init_geojson_tiler();
|
|
3111
3315
|
}
|
|
3112
3316
|
});
|
package/dist/es5/index.js
CHANGED
|
@@ -21,6 +21,13 @@ Object.defineProperty(exports, "MVTWorkerLoader", {
|
|
|
21
21
|
return _mvtLoader.MVTWorkerLoader;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "TileJSONLoader", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _tilejsonLoader.TileJSONLoader;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
var _mvtLoader = require("./mvt-loader");
|
|
31
|
+
var _tilejsonLoader = require("./tilejson-loader");
|
|
25
32
|
var _geojsonTiler = require("./lib/geojson-tiler/geojson-tiler");
|
|
26
33
|
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mvtLoader","require","_geojsonTiler"],"sources":["../../src/index.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nexport {MVTLoader, MVTWorkerLoader} from './mvt-loader';\n\n// GeoJSONTiler\n\nexport type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';\nexport {GeoJSONTiler} from './lib/geojson-tiler/geojson-tiler';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mvtLoader","require","_tilejsonLoader","_geojsonTiler"],"sources":["../../src/index.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nexport type {MVTLoaderOptions} from './lib/types';\nexport {MVTLoader, MVTWorkerLoader} from './mvt-loader';\n\nexport type {TileJSON} from './lib/parse-tilejson';\nexport type {TileJSONLoaderOptions} from './tilejson-loader';\nexport {TileJSONLoader} from './tilejson-loader';\n\n// GeoJSONTiler\n\nexport type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';\nexport {GeoJSONTiler} from './lib/geojson-tiler/geojson-tiler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,UAAA,GAAAC,OAAA;AAIA,IAAAC,eAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAF,OAAA"}
|
|
@@ -13,29 +13,30 @@ var _vectorTile2 = _interopRequireDefault(require("./binary-vector-tile/vector-t
|
|
|
13
13
|
function parseMVT(arrayBuffer, options) {
|
|
14
14
|
var _options$gis, _options$mvt;
|
|
15
15
|
var mvtOptions = normalizeOptions(options);
|
|
16
|
-
var shape = (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) || (options === null || options === void 0 ? void 0 : (_options$mvt = options.mvt) === null || _options$mvt === void 0 ? void 0 : _options$mvt.shape);
|
|
16
|
+
var shape = (options === null || options === void 0 ? void 0 : (_options$gis = options.gis) === null || _options$gis === void 0 ? void 0 : _options$gis.format) || (options === null || options === void 0 ? void 0 : (_options$mvt = options.mvt) === null || _options$mvt === void 0 ? void 0 : _options$mvt.shape) || (options === null || options === void 0 ? void 0 : options.shape);
|
|
17
17
|
switch (shape) {
|
|
18
18
|
case 'columnar-table':
|
|
19
19
|
return {
|
|
20
20
|
shape: 'columnar-table',
|
|
21
21
|
data: parseToBinary(arrayBuffer, mvtOptions)
|
|
22
22
|
};
|
|
23
|
-
case 'geojson-
|
|
23
|
+
case 'geojson-table':
|
|
24
24
|
{
|
|
25
25
|
var table = {
|
|
26
|
-
shape: 'geojson-
|
|
27
|
-
|
|
26
|
+
shape: 'geojson-table',
|
|
27
|
+
type: 'FeatureCollection',
|
|
28
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
28
29
|
};
|
|
29
30
|
return table;
|
|
30
31
|
}
|
|
31
32
|
case 'geojson':
|
|
32
|
-
return
|
|
33
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
33
34
|
case 'binary-geometry':
|
|
34
35
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
35
36
|
case 'binary':
|
|
36
37
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
37
38
|
default:
|
|
38
|
-
throw new Error(shape);
|
|
39
|
+
throw new Error(shape || 'undefined shape');
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
function parseToBinary(arrayBuffer, options) {
|
|
@@ -79,7 +80,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
|
|
|
79
80
|
});
|
|
80
81
|
return [features, geometryInfo];
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
83
84
|
if (arrayBuffer.byteLength <= 0) {
|
|
84
85
|
return [];
|
|
85
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.js","names":["_gis","require","_pbf","_interopRequireDefault","_vectorTile","_vectorTile2","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","parseToGeojson","Error","_parseToFlatGeoJson","parseToFlatGeoJson","_parseToFlatGeoJson2","_slicedToArray2","default","flatGeoJsonFeatures","geometryInfo","binaryData","flatGeojsonToBinary","byteLength","features","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","BinaryVectorTile","Protobuf","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","VectorTile","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatures,\n GeoJSONRowTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\n\n/**\n * Parse MVT arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A MVT arrayBuffer\n * @param options\n * @returns A GeoJSON geometry object or a binary representation\n */\nexport default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape = options?.gis?.format || options?.mvt?.shape;\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-row-table': {\n const table: GeoJSONRowTable = {\n shape: 'geojson-row-table',\n data: parseToGeojson(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojson(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatures {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);\n // Add the original byteLength (as a reasonable approximation of the size of the binary data)\n // TODO decide where to store extra fields like byteLength (header etc) and document\n // @ts-ignore\n binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\n coordLength: 2,\n pointPositionsCount: 0,\n pointFeaturesCount: 0,\n linePositionsCount: 0,\n linePathsCount: 0,\n lineFeaturesCount: 0,\n polygonPositionsCount: 0,\n polygonObjectsCount: 0,\n polygonRingsCount: 0,\n polygonFeaturesCount: 0\n };\n\n if (arrayBuffer.byteLength <= 0) {\n return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojson(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\n const hasTileIndex =\n tileIndex &&\n Number.isFinite(tileIndex.x) &&\n Number.isFinite(tileIndex.y) &&\n Number.isFinite(tileIndex.z);\n\n if (wgs84Coordinates && !hasTileIndex) {\n throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded binary feature\n */\nfunction getDecodedFeatureBinary(\n feature: VectorTileFeatureBinary,\n options: MVTOptions,\n layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty && decodedFeature.properties) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param line\n * @param feature\n */\nfunction transformToLocalCoordinates(line: number[], feature: {extent: any}): void {\n // This function transforms local coordinates in a\n // [0 - bufferSize, this.extent + bufferSize] range to a\n // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.\n // The resulting extent would be 1.\n const {extent} = feature;\n for (let i = 0; i < line.length; i++) {\n const p = line[i];\n p[0] /= extent;\n p[1] /= extent;\n }\n}\n\nfunction transformToLocalCoordinatesBinary(data: number[], feature: {extent: any}) {\n // For the binary code path, the feature data is just\n // one big flat array, so we just divide each value\n const {extent} = feature;\n for (let i = 0, il = data.length; i < il; ++i) {\n data[i] /= extent;\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAIA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAF,sBAAA,CAAAF,OAAA;AAWe,SAASK,QAAQA,CAACC,WAAwB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,YAAA,EAAAC,YAAA;EACrF,IAAMC,UAAU,GAA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M,cAAc;AACvB;AAMA,SAASgB,2BAA2BA,CAACK,IAAc,EAAEtB,OAAsB,EAAQ;EAKjF,IAAOuB,MAAM,GAAIvB,OAAO,CAAjBuB,MAAM;EACb,KAAK,IAAI1B,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGyB,IAAI,CAACxB,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,IAAM2B,CAAC,GAAGF,IAAI,CAACzB,CAAC,CAAC;IACjB2B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAAC9D,IAAc,EAAEyC,OAAsB,EAAE;EAGjF,IAAOuB,MAAM,GAAIvB,OAAO,CAAjBuB,MAAM;EACb,KAAK,IAAI1B,CAAC,GAAG,CAAC,EAAE4B,EAAE,GAAGlE,IAAI,CAACuC,MAAM,EAAED,CAAC,GAAG4B,EAAE,EAAE,EAAE5B,CAAC,EAAE;IAC7CtC,IAAI,CAACsC,CAAC,CAAC,IAAI0B,MAAM;EACnB;AACF"}
|
|
1
|
+
{"version":3,"file":"parse-mvt.js","names":["_gis","require","_pbf","_interopRequireDefault","_vectorTile","_vectorTile2","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","type","features","parseToGeojsonFeatures","Error","_parseToFlatGeoJson","parseToFlatGeoJson","_parseToFlatGeoJson2","_slicedToArray2","default","flatGeoJsonFeatures","geometryInfo","binaryData","flatGeojsonToBinary","byteLength","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","BinaryVectorTile","Protobuf","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","VectorTile","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\n\n/**\n * Parse MVT arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A MVT arrayBuffer\n * @param options\n * @returns A GeoJSON geometry object or a binary representation\n */\nexport default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape: string | undefined =\n options?.gis?.format || options?.mvt?.shape || (options?.shape as string);\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-table': {\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojsonFeatures(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape || 'undefined shape');\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);\n // Add the original byteLength (as a reasonable approximation of the size of the binary data)\n // TODO decide where to store extra fields like byteLength (header etc) and document\n // @ts-ignore\n binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\n coordLength: 2,\n pointPositionsCount: 0,\n pointFeaturesCount: 0,\n linePositionsCount: 0,\n linePathsCount: 0,\n lineFeaturesCount: 0,\n polygonPositionsCount: 0,\n polygonObjectsCount: 0,\n polygonRingsCount: 0,\n polygonFeaturesCount: 0\n };\n\n if (arrayBuffer.byteLength <= 0) {\n return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojsonFeatures(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\n const hasTileIndex =\n tileIndex &&\n Number.isFinite(tileIndex.x) &&\n Number.isFinite(tileIndex.y) &&\n Number.isFinite(tileIndex.z);\n\n if (wgs84Coordinates && !hasTileIndex) {\n throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded binary feature\n */\nfunction getDecodedFeatureBinary(\n feature: VectorTileFeatureBinary,\n options: MVTOptions,\n layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty && decodedFeature.properties) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param line\n * @param feature\n */\nfunction transformToLocalCoordinates(line: number[], feature: {extent: any}): void {\n // This function transforms local coordinates in a\n // [0 - bufferSize, this.extent + bufferSize] range to a\n // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.\n // The resulting extent would be 1.\n const {extent} = feature;\n for (let i = 0; i < line.length; i++) {\n const p = line[i];\n p[0] /= extent;\n p[1] /= extent;\n }\n}\n\nfunction transformToLocalCoordinatesBinary(data: number[], feature: {extent: any}) {\n // For the binary code path, the feature data is just\n // one big flat array, so we just divide each value\n const {extent} = feature;\n for (let i = 0, il = data.length; i < il; ++i) {\n data[i] /= extent;\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAIA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAF,sBAAA,CAAAF,OAAA;AAWe,SAASK,QAAQA,CAACC,WAAwB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,YAAA,EAAAC,YAAA;EACrF,IAAMC,UAAU,GAAGC,gBAAgB,CAACJ,OAAO,CAAC;EAE5C,IAAMK,KAAyB,GAC7B,CAAAL,OAAO,aAAPA,OAAO,wBAAAC,YAAA,GAAPD,OAAO,CAAEM,GAAG,cAAAL,YAAA,uBAAZA,YAAA,CAAcM,MAAM,MAAIP,OAAO,aAAPA,OAAO,wBAAAE,YAAA,GAAPF,OAAO,CAAEQ,GAAG,cAAAN,YAAA,uBAAZA,YAAA,CAAcG,KAAK,MAAKL,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,KAAK,CAAW;EAC3E,QAAQA,KAAK;IACX,KAAK,gBAAgB;MACnB,OAAO;QAACA,KAAK,EAAE,gBAAgB;QAAEI,IAAI,EAAEC,aAAa,CAACX,WAAW,EAAEI,UAAU;MAAC,CAAC;IAChF,KAAK,eAAe;MAAE;QACpB,IAAMQ,KAAmB,GAAG;UAC1BN,KAAK,EAAE,eAAe;UACtBO,IAAI,EAAE,mBAAmB;UACzBC,QAAQ,EAAEC,sBAAsB,CAACf,WAAW,EAAEI,UAAU;QAC1D,CAAC;QACD,OAAOQ,KAAK;MACd;IACA,KA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