@loaders.gl/mvt 4.0.0-beta.8 → 4.0.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.dev.js +129 -49
- package/dist/index.cjs +115 -44
- package/dist/lib/parse-tilejson.d.ts +20 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +82 -33
- package/dist/lib/parse-tilejson.js.map +1 -1
- package/dist/mvt-source.d.ts +7 -0
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +42 -16
- package/dist/mvt-source.js.map +1 -1
- package/dist/mvt-worker.js +2 -2
- package/dist/tilejson-loader.d.ts +3 -1
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +13 -3
- package/dist/tilejson-loader.js.map +1 -1
- package/package.json +6 -6
- package/src/lib/parse-tilejson.ts +137 -42
- package/src/mvt-source.ts +51 -11
- package/src/tilejson-loader.ts +11 -5
package/dist/dist.dev.js
CHANGED
|
@@ -1346,7 +1346,7 @@ var __exports__ = (() => {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
};
|
|
1348
1348
|
|
|
1349
|
-
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1349
|
+
// ../gis/src/lib/binary-features/flat-geojson-to-binary.ts
|
|
1350
1350
|
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1351
1351
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
1352
1352
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
@@ -2378,70 +2378,88 @@ var __exports__ = (() => {
|
|
|
2378
2378
|
|
|
2379
2379
|
// src/lib/parse-tilejson.ts
|
|
2380
2380
|
var isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
2381
|
-
function parseTileJSON(jsonMetadata) {
|
|
2381
|
+
function parseTileJSON(jsonMetadata, options) {
|
|
2382
2382
|
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
2383
2383
|
return null;
|
|
2384
2384
|
}
|
|
2385
|
-
const boundingBox = parseBounds(jsonMetadata.bounds);
|
|
2386
|
-
const center = parseCenter(jsonMetadata.center);
|
|
2387
|
-
const maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
2388
|
-
const minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
2389
2385
|
let tileJSON = {
|
|
2390
2386
|
name: jsonMetadata.name || "",
|
|
2391
|
-
description: jsonMetadata.description || ""
|
|
2392
|
-
boundingBox,
|
|
2393
|
-
center,
|
|
2394
|
-
maxZoom,
|
|
2395
|
-
minZoom,
|
|
2396
|
-
layers: []
|
|
2387
|
+
description: jsonMetadata.description || ""
|
|
2397
2388
|
};
|
|
2389
|
+
if (typeof jsonMetadata.generator === "string") {
|
|
2390
|
+
tileJSON.generator = jsonMetadata.generator;
|
|
2391
|
+
}
|
|
2392
|
+
if (typeof jsonMetadata.generator_options === "string") {
|
|
2393
|
+
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
2394
|
+
}
|
|
2395
|
+
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
2396
|
+
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
2397
|
+
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
2398
|
+
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
2398
2399
|
if (typeof jsonMetadata?.json === "string") {
|
|
2399
2400
|
try {
|
|
2400
2401
|
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
2401
|
-
} catch (
|
|
2402
|
+
} catch (error) {
|
|
2403
|
+
console.warn("Failed to parse tilejson.json field", error);
|
|
2402
2404
|
}
|
|
2403
2405
|
}
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2406
|
+
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
2407
|
+
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
2408
|
+
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
2409
|
+
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
2408
2410
|
tileJSON = {
|
|
2409
2411
|
...tileJSON,
|
|
2410
2412
|
layers
|
|
2411
2413
|
};
|
|
2414
|
+
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
2415
|
+
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
2416
|
+
}
|
|
2417
|
+
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
2418
|
+
tileJSON.minZoom = layers[0].minZoom || null;
|
|
2419
|
+
}
|
|
2412
2420
|
return tileJSON;
|
|
2413
2421
|
}
|
|
2414
2422
|
function parseTileJSONLayers(layers) {
|
|
2415
2423
|
if (!Array.isArray(layers)) {
|
|
2416
2424
|
return [];
|
|
2417
2425
|
}
|
|
2418
|
-
return layers.map((layer) => (
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2426
|
+
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
2427
|
+
}
|
|
2428
|
+
function parseTileJSONLayer(layer) {
|
|
2429
|
+
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
2430
|
+
name: key,
|
|
2431
|
+
...attributeTypeToFieldType(String(datatype))
|
|
2424
2432
|
}));
|
|
2433
|
+
const layer2 = {
|
|
2434
|
+
...layer
|
|
2435
|
+
};
|
|
2436
|
+
delete layer2.fields;
|
|
2437
|
+
return {
|
|
2438
|
+
name: layer.id || "",
|
|
2439
|
+
...layer2,
|
|
2440
|
+
fields
|
|
2441
|
+
};
|
|
2425
2442
|
}
|
|
2426
|
-
function parseTilestatsLayers(tilestats) {
|
|
2443
|
+
function parseTilestatsLayers(tilestats, options) {
|
|
2427
2444
|
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
2428
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer));
|
|
2445
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
2429
2446
|
}
|
|
2430
2447
|
return [];
|
|
2431
2448
|
}
|
|
2432
|
-
function parseTilestatsForLayer(layer) {
|
|
2449
|
+
function parseTilestatsForLayer(layer, options) {
|
|
2433
2450
|
const fields = [];
|
|
2434
2451
|
const indexedAttributes = {};
|
|
2435
2452
|
const attributes = layer.attributes || [];
|
|
2436
|
-
for (const
|
|
2437
|
-
const name =
|
|
2453
|
+
for (const attribute of attributes) {
|
|
2454
|
+
const name = attribute.attribute;
|
|
2438
2455
|
if (typeof name === "string") {
|
|
2439
2456
|
if (name.split("|").length > 1) {
|
|
2440
2457
|
const fname = name.split("|")[0];
|
|
2441
2458
|
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
2442
|
-
indexedAttributes[fname].push(
|
|
2459
|
+
indexedAttributes[fname].push(attribute);
|
|
2460
|
+
console.warn("ignoring tilestats indexed field", fname);
|
|
2443
2461
|
} else if (!fields[name]) {
|
|
2444
|
-
fields
|
|
2462
|
+
fields.push(attributeToField(attribute, options));
|
|
2445
2463
|
} else {
|
|
2446
2464
|
}
|
|
2447
2465
|
}
|
|
@@ -2452,6 +2470,21 @@ var __exports__ = (() => {
|
|
|
2452
2470
|
fields
|
|
2453
2471
|
};
|
|
2454
2472
|
}
|
|
2473
|
+
function mergeLayers(layers, tilestatsLayers) {
|
|
2474
|
+
return layers.map((layer) => {
|
|
2475
|
+
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
2476
|
+
const fields = tilestatsLayer?.fields || [];
|
|
2477
|
+
const layer2 = {
|
|
2478
|
+
...layer
|
|
2479
|
+
};
|
|
2480
|
+
delete layer2.fields;
|
|
2481
|
+
return {
|
|
2482
|
+
...layer2,
|
|
2483
|
+
...tilestatsLayer,
|
|
2484
|
+
fields
|
|
2485
|
+
};
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2455
2488
|
function parseBounds(bounds) {
|
|
2456
2489
|
const result = fromArrayOrString(bounds);
|
|
2457
2490
|
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
@@ -2516,12 +2549,25 @@ var __exports__ = (() => {
|
|
|
2516
2549
|
type: "boolean"
|
|
2517
2550
|
}
|
|
2518
2551
|
};
|
|
2519
|
-
function attributeToField(attribute = {}) {
|
|
2552
|
+
function attributeToField(attribute = {}, options) {
|
|
2520
2553
|
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
2521
|
-
|
|
2554
|
+
const field = {
|
|
2522
2555
|
name: attribute.attribute,
|
|
2523
2556
|
...fieldTypes
|
|
2524
2557
|
};
|
|
2558
|
+
if (typeof attribute.min === "number") {
|
|
2559
|
+
field.min = attribute.min;
|
|
2560
|
+
}
|
|
2561
|
+
if (typeof attribute.max === "number") {
|
|
2562
|
+
field.max = attribute.max;
|
|
2563
|
+
}
|
|
2564
|
+
if (typeof attribute.count === "number") {
|
|
2565
|
+
field.uniqueValueCount = attribute.count;
|
|
2566
|
+
}
|
|
2567
|
+
if (options.maxValues !== false && attribute.values) {
|
|
2568
|
+
field.values = attribute.values?.slice(0, options.maxValues);
|
|
2569
|
+
}
|
|
2570
|
+
return field;
|
|
2525
2571
|
}
|
|
2526
2572
|
function attributeTypeToFieldType(aType) {
|
|
2527
2573
|
const type = aType.toLowerCase();
|
|
@@ -2544,16 +2590,26 @@ var __exports__ = (() => {
|
|
|
2544
2590
|
mimeTypes: ["application/json"],
|
|
2545
2591
|
text: true,
|
|
2546
2592
|
options: {
|
|
2547
|
-
tilejson: {
|
|
2593
|
+
tilejson: {
|
|
2594
|
+
maxValues: 10
|
|
2595
|
+
}
|
|
2548
2596
|
},
|
|
2549
2597
|
parse: async (arrayBuffer, options) => {
|
|
2550
2598
|
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
2551
2599
|
const json = JSON.parse(jsonString);
|
|
2552
|
-
|
|
2600
|
+
const tilejsonOptions = {
|
|
2601
|
+
...TileJSONLoader.options.tilejson,
|
|
2602
|
+
...options?.tilejson
|
|
2603
|
+
};
|
|
2604
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
2553
2605
|
},
|
|
2554
2606
|
parseTextSync: (text, options) => {
|
|
2555
2607
|
const json = JSON.parse(text);
|
|
2556
|
-
|
|
2608
|
+
const tilejsonOptions = {
|
|
2609
|
+
...TileJSONLoader.options.tilejson,
|
|
2610
|
+
...options?.tilejson
|
|
2611
|
+
};
|
|
2612
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
2557
2613
|
}
|
|
2558
2614
|
};
|
|
2559
2615
|
|
|
@@ -3023,23 +3079,36 @@ var __exports__ = (() => {
|
|
|
3023
3079
|
// src/mvt-source.ts
|
|
3024
3080
|
var MVTSource = class extends DataSource {
|
|
3025
3081
|
schema = "tms";
|
|
3082
|
+
extension = ".png";
|
|
3083
|
+
mimeType = null;
|
|
3026
3084
|
constructor(props) {
|
|
3027
3085
|
super(props);
|
|
3028
3086
|
this.props = props;
|
|
3029
3087
|
this.url = resolvePath(props.url);
|
|
3088
|
+
this.data = this.url;
|
|
3030
3089
|
this.getTileData = this.getTileData.bind(this);
|
|
3031
3090
|
this.metadata = this.getMetadata();
|
|
3032
3091
|
}
|
|
3033
3092
|
async getMetadata() {
|
|
3034
3093
|
const metadataUrl = this.getMetadataUrl();
|
|
3035
|
-
|
|
3094
|
+
let response;
|
|
3095
|
+
try {
|
|
3096
|
+
response = await this.fetch(metadataUrl);
|
|
3097
|
+
} catch (error) {
|
|
3098
|
+
console.error(error.message);
|
|
3099
|
+
return null;
|
|
3100
|
+
}
|
|
3036
3101
|
if (!response.ok) {
|
|
3102
|
+
console.error(response.statusText);
|
|
3037
3103
|
return null;
|
|
3038
3104
|
}
|
|
3039
3105
|
const tileJSON = await response.text();
|
|
3040
3106
|
const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;
|
|
3041
3107
|
return metadata;
|
|
3042
3108
|
}
|
|
3109
|
+
getTileMIMEType() {
|
|
3110
|
+
return this.mimeType;
|
|
3111
|
+
}
|
|
3043
3112
|
async getTile(tileParams) {
|
|
3044
3113
|
const {
|
|
3045
3114
|
x: x2,
|
|
@@ -3060,30 +3129,41 @@ var __exports__ = (() => {
|
|
|
3060
3129
|
y: y2,
|
|
3061
3130
|
z
|
|
3062
3131
|
} = tileParams.index;
|
|
3063
|
-
const
|
|
3064
|
-
|
|
3132
|
+
const arrayBuffer = await this.getTile({
|
|
3133
|
+
x: x2,
|
|
3134
|
+
y: y2,
|
|
3135
|
+
zoom: z,
|
|
3136
|
+
layers: []
|
|
3137
|
+
});
|
|
3138
|
+
if (arrayBuffer === null) {
|
|
3139
|
+
return null;
|
|
3140
|
+
}
|
|
3141
|
+
const imageMetadata = getBinaryImageMetadata(arrayBuffer);
|
|
3142
|
+
this.mimeType = this.mimeType || imageMetadata?.mimeType || "application/vnd.mapbox-vector-tile";
|
|
3143
|
+
switch (this.mimeType) {
|
|
3065
3144
|
case "application/vnd.mapbox-vector-tile":
|
|
3066
|
-
return await this.
|
|
3145
|
+
return await this.parseVectorTile(arrayBuffer, {
|
|
3067
3146
|
x: x2,
|
|
3068
3147
|
y: y2,
|
|
3069
3148
|
zoom: z,
|
|
3070
3149
|
layers: []
|
|
3071
3150
|
});
|
|
3072
3151
|
default:
|
|
3073
|
-
return await this.
|
|
3074
|
-
x: x2,
|
|
3075
|
-
y: y2,
|
|
3076
|
-
zoom: z,
|
|
3077
|
-
layers: []
|
|
3078
|
-
});
|
|
3152
|
+
return await this.parseImageTile(arrayBuffer);
|
|
3079
3153
|
}
|
|
3080
3154
|
}
|
|
3081
3155
|
async getImageTile(tileParams) {
|
|
3082
3156
|
const arrayBuffer = await this.getTile(tileParams);
|
|
3083
|
-
return arrayBuffer ?
|
|
3157
|
+
return arrayBuffer ? this.parseImageTile(arrayBuffer) : null;
|
|
3158
|
+
}
|
|
3159
|
+
async parseImageTile(arrayBuffer) {
|
|
3160
|
+
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
3084
3161
|
}
|
|
3085
3162
|
async getVectorTile(tileParams) {
|
|
3086
3163
|
const arrayBuffer = await this.getTile(tileParams);
|
|
3164
|
+
return arrayBuffer ? this.parseVectorTile(arrayBuffer, tileParams) : null;
|
|
3165
|
+
}
|
|
3166
|
+
async parseVectorTile(arrayBuffer, tileParams) {
|
|
3087
3167
|
const loadOptions = {
|
|
3088
3168
|
shape: "geojson-table",
|
|
3089
3169
|
mvt: {
|
|
@@ -3097,7 +3177,7 @@ var __exports__ = (() => {
|
|
|
3097
3177
|
},
|
|
3098
3178
|
...this.loadOptions
|
|
3099
3179
|
};
|
|
3100
|
-
return
|
|
3180
|
+
return await MVTLoader.parse(arrayBuffer, loadOptions);
|
|
3101
3181
|
}
|
|
3102
3182
|
getMetadataUrl() {
|
|
3103
3183
|
return `${this.url}/tilejson.json`;
|
|
@@ -3105,10 +3185,10 @@ var __exports__ = (() => {
|
|
|
3105
3185
|
getTileURL(x2, y2, z) {
|
|
3106
3186
|
switch (this.schema) {
|
|
3107
3187
|
case "xyz":
|
|
3108
|
-
return `${this.url}/${x2}/${y2}/${z}`;
|
|
3188
|
+
return `${this.url}/${x2}/${y2}/${z}${this.extension}`;
|
|
3109
3189
|
case "tms":
|
|
3110
3190
|
default:
|
|
3111
|
-
return `${this.url}/${z}/${x2}/${y2}`;
|
|
3191
|
+
return `${this.url}/${z}/${x2}/${y2}${this.extension}`;
|
|
3112
3192
|
}
|
|
3113
3193
|
}
|
|
3114
3194
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -767,71 +767,87 @@ var MVTLoader = {
|
|
|
767
767
|
|
|
768
768
|
// src/lib/parse-tilejson.ts
|
|
769
769
|
var isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
770
|
-
function parseTileJSON(jsonMetadata) {
|
|
770
|
+
function parseTileJSON(jsonMetadata, options) {
|
|
771
771
|
var _a;
|
|
772
772
|
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
773
773
|
return null;
|
|
774
774
|
}
|
|
775
|
-
const boundingBox = parseBounds(jsonMetadata.bounds);
|
|
776
|
-
const center = parseCenter(jsonMetadata.center);
|
|
777
|
-
const maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
778
|
-
const minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
779
775
|
let tileJSON = {
|
|
780
776
|
name: jsonMetadata.name || "",
|
|
781
|
-
description: jsonMetadata.description || ""
|
|
782
|
-
boundingBox,
|
|
783
|
-
center,
|
|
784
|
-
maxZoom,
|
|
785
|
-
minZoom,
|
|
786
|
-
layers: []
|
|
777
|
+
description: jsonMetadata.description || ""
|
|
787
778
|
};
|
|
779
|
+
if (typeof jsonMetadata.generator === "string") {
|
|
780
|
+
tileJSON.generator = jsonMetadata.generator;
|
|
781
|
+
}
|
|
782
|
+
if (typeof jsonMetadata.generator_options === "string") {
|
|
783
|
+
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
784
|
+
}
|
|
785
|
+
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
786
|
+
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
787
|
+
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
788
|
+
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
788
789
|
if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
|
|
789
790
|
try {
|
|
790
791
|
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
791
|
-
} catch (
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.warn("Failed to parse tilejson.json field", error);
|
|
792
794
|
}
|
|
793
795
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
796
|
+
const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
|
|
797
|
+
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
798
|
+
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
799
|
+
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
798
800
|
tileJSON = {
|
|
799
801
|
...tileJSON,
|
|
800
802
|
layers
|
|
801
803
|
};
|
|
804
|
+
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
805
|
+
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
806
|
+
}
|
|
807
|
+
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
808
|
+
tileJSON.minZoom = layers[0].minZoom || null;
|
|
809
|
+
}
|
|
802
810
|
return tileJSON;
|
|
803
811
|
}
|
|
804
812
|
function parseTileJSONLayers(layers) {
|
|
805
813
|
if (!Array.isArray(layers)) {
|
|
806
814
|
return [];
|
|
807
815
|
}
|
|
808
|
-
return layers.map((layer) => (
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
816
|
+
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
817
|
+
}
|
|
818
|
+
function parseTileJSONLayer(layer) {
|
|
819
|
+
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
820
|
+
name: key,
|
|
821
|
+
...attributeTypeToFieldType(String(datatype))
|
|
814
822
|
}));
|
|
823
|
+
const layer2 = { ...layer };
|
|
824
|
+
delete layer2.fields;
|
|
825
|
+
return {
|
|
826
|
+
name: layer.id || "",
|
|
827
|
+
...layer2,
|
|
828
|
+
fields
|
|
829
|
+
};
|
|
815
830
|
}
|
|
816
|
-
function parseTilestatsLayers(tilestats) {
|
|
831
|
+
function parseTilestatsLayers(tilestats, options) {
|
|
817
832
|
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
818
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer));
|
|
833
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
819
834
|
}
|
|
820
835
|
return [];
|
|
821
836
|
}
|
|
822
|
-
function parseTilestatsForLayer(layer) {
|
|
837
|
+
function parseTilestatsForLayer(layer, options) {
|
|
823
838
|
const fields = [];
|
|
824
839
|
const indexedAttributes = {};
|
|
825
840
|
const attributes = layer.attributes || [];
|
|
826
|
-
for (const
|
|
827
|
-
const name =
|
|
841
|
+
for (const attribute of attributes) {
|
|
842
|
+
const name = attribute.attribute;
|
|
828
843
|
if (typeof name === "string") {
|
|
829
844
|
if (name.split("|").length > 1) {
|
|
830
845
|
const fname = name.split("|")[0];
|
|
831
846
|
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
832
|
-
indexedAttributes[fname].push(
|
|
847
|
+
indexedAttributes[fname].push(attribute);
|
|
848
|
+
console.warn("ignoring tilestats indexed field", fname);
|
|
833
849
|
} else if (!fields[name]) {
|
|
834
|
-
fields
|
|
850
|
+
fields.push(attributeToField(attribute, options));
|
|
835
851
|
} else {
|
|
836
852
|
}
|
|
837
853
|
}
|
|
@@ -842,6 +858,19 @@ function parseTilestatsForLayer(layer) {
|
|
|
842
858
|
fields
|
|
843
859
|
};
|
|
844
860
|
}
|
|
861
|
+
function mergeLayers(layers, tilestatsLayers) {
|
|
862
|
+
return layers.map((layer) => {
|
|
863
|
+
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
864
|
+
const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || [];
|
|
865
|
+
const layer2 = { ...layer };
|
|
866
|
+
delete layer2.fields;
|
|
867
|
+
return {
|
|
868
|
+
...layer2,
|
|
869
|
+
...tilestatsLayer,
|
|
870
|
+
fields
|
|
871
|
+
};
|
|
872
|
+
});
|
|
873
|
+
}
|
|
845
874
|
function parseBounds(bounds) {
|
|
846
875
|
const result = fromArrayOrString(bounds);
|
|
847
876
|
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
@@ -909,14 +938,28 @@ var attrTypeMap = {
|
|
|
909
938
|
type: "boolean"
|
|
910
939
|
}
|
|
911
940
|
};
|
|
912
|
-
function attributeToField(attribute = {}) {
|
|
941
|
+
function attributeToField(attribute = {}, options) {
|
|
942
|
+
var _a;
|
|
913
943
|
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
914
|
-
|
|
944
|
+
const field = {
|
|
915
945
|
name: attribute.attribute,
|
|
916
946
|
// what happens if attribute type is string...
|
|
917
947
|
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
918
948
|
...fieldTypes
|
|
919
949
|
};
|
|
950
|
+
if (typeof attribute.min === "number") {
|
|
951
|
+
field.min = attribute.min;
|
|
952
|
+
}
|
|
953
|
+
if (typeof attribute.max === "number") {
|
|
954
|
+
field.max = attribute.max;
|
|
955
|
+
}
|
|
956
|
+
if (typeof attribute.count === "number") {
|
|
957
|
+
field.uniqueValueCount = attribute.count;
|
|
958
|
+
}
|
|
959
|
+
if (options.maxValues !== false && attribute.values) {
|
|
960
|
+
field.values = (_a = attribute.values) == null ? void 0 : _a.slice(0, options.maxValues);
|
|
961
|
+
}
|
|
962
|
+
return field;
|
|
920
963
|
}
|
|
921
964
|
function attributeTypeToFieldType(aType) {
|
|
922
965
|
const type = aType.toLowerCase();
|
|
@@ -937,16 +980,20 @@ var TileJSONLoader = {
|
|
|
937
980
|
mimeTypes: ["application/json"],
|
|
938
981
|
text: true,
|
|
939
982
|
options: {
|
|
940
|
-
tilejson: {
|
|
983
|
+
tilejson: {
|
|
984
|
+
maxValues: 10
|
|
985
|
+
}
|
|
941
986
|
},
|
|
942
987
|
parse: async (arrayBuffer, options) => {
|
|
943
988
|
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
944
989
|
const json = JSON.parse(jsonString);
|
|
945
|
-
|
|
990
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
|
|
991
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
946
992
|
},
|
|
947
993
|
parseTextSync: (text, options) => {
|
|
948
994
|
const json = JSON.parse(text);
|
|
949
|
-
|
|
995
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
|
|
996
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
950
997
|
}
|
|
951
998
|
};
|
|
952
999
|
|
|
@@ -958,8 +1005,11 @@ var MVTSource = class extends import_loader_utils.DataSource {
|
|
|
958
1005
|
constructor(props) {
|
|
959
1006
|
super(props);
|
|
960
1007
|
this.schema = "tms";
|
|
1008
|
+
this.extension = ".png";
|
|
1009
|
+
this.mimeType = null;
|
|
961
1010
|
this.props = props;
|
|
962
1011
|
this.url = (0, import_loader_utils.resolvePath)(props.url);
|
|
1012
|
+
this.data = this.url;
|
|
963
1013
|
this.getTileData = this.getTileData.bind(this);
|
|
964
1014
|
this.metadata = this.getMetadata();
|
|
965
1015
|
}
|
|
@@ -967,14 +1017,24 @@ var MVTSource = class extends import_loader_utils.DataSource {
|
|
|
967
1017
|
async getMetadata() {
|
|
968
1018
|
var _a, _b;
|
|
969
1019
|
const metadataUrl = this.getMetadataUrl();
|
|
970
|
-
|
|
1020
|
+
let response;
|
|
1021
|
+
try {
|
|
1022
|
+
response = await this.fetch(metadataUrl);
|
|
1023
|
+
} catch (error) {
|
|
1024
|
+
console.error(error.message);
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
971
1027
|
if (!response.ok) {
|
|
1028
|
+
console.error(response.statusText);
|
|
972
1029
|
return null;
|
|
973
1030
|
}
|
|
974
1031
|
const tileJSON = await response.text();
|
|
975
1032
|
const metadata = ((_b = (_a = import_mvt.TileJSONLoader).parseTextSync) == null ? void 0 : _b.call(_a, JSON.stringify(tileJSON))) || null;
|
|
976
1033
|
return metadata;
|
|
977
1034
|
}
|
|
1035
|
+
getTileMIMEType() {
|
|
1036
|
+
return this.mimeType;
|
|
1037
|
+
}
|
|
978
1038
|
async getTile(tileParams) {
|
|
979
1039
|
const { x: x2, y: y2, zoom: z } = tileParams;
|
|
980
1040
|
const tileUrl = this.getTileURL(x2, y2, z);
|
|
@@ -989,23 +1049,34 @@ var MVTSource = class extends import_loader_utils.DataSource {
|
|
|
989
1049
|
// TODO - currently only handles image tiles, not vector tiles
|
|
990
1050
|
async getTileData(tileParams) {
|
|
991
1051
|
const { x: x2, y: y2, z } = tileParams.index;
|
|
992
|
-
const
|
|
993
|
-
|
|
1052
|
+
const arrayBuffer = await this.getTile({ x: x2, y: y2, zoom: z, layers: [] });
|
|
1053
|
+
if (arrayBuffer === null) {
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
const imageMetadata = (0, import_images.getBinaryImageMetadata)(arrayBuffer);
|
|
1057
|
+
this.mimeType = this.mimeType || (imageMetadata == null ? void 0 : imageMetadata.mimeType) || "application/vnd.mapbox-vector-tile";
|
|
1058
|
+
switch (this.mimeType) {
|
|
994
1059
|
case "application/vnd.mapbox-vector-tile":
|
|
995
|
-
return await this.
|
|
1060
|
+
return await this.parseVectorTile(arrayBuffer, { x: x2, y: y2, zoom: z, layers: [] });
|
|
996
1061
|
default:
|
|
997
|
-
return await this.
|
|
1062
|
+
return await this.parseImageTile(arrayBuffer);
|
|
998
1063
|
}
|
|
999
1064
|
}
|
|
1000
1065
|
// ImageTileSource interface implementation
|
|
1001
1066
|
async getImageTile(tileParams) {
|
|
1002
1067
|
const arrayBuffer = await this.getTile(tileParams);
|
|
1003
|
-
return arrayBuffer ?
|
|
1068
|
+
return arrayBuffer ? this.parseImageTile(arrayBuffer) : null;
|
|
1069
|
+
}
|
|
1070
|
+
async parseImageTile(arrayBuffer) {
|
|
1071
|
+
return await import_images.ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
1004
1072
|
}
|
|
1005
1073
|
// VectorTileSource interface implementation
|
|
1006
1074
|
async getVectorTile(tileParams) {
|
|
1007
|
-
var _a;
|
|
1008
1075
|
const arrayBuffer = await this.getTile(tileParams);
|
|
1076
|
+
return arrayBuffer ? this.parseVectorTile(arrayBuffer, tileParams) : null;
|
|
1077
|
+
}
|
|
1078
|
+
async parseVectorTile(arrayBuffer, tileParams) {
|
|
1079
|
+
var _a;
|
|
1009
1080
|
const loadOptions = {
|
|
1010
1081
|
shape: "geojson-table",
|
|
1011
1082
|
mvt: {
|
|
@@ -1015,7 +1086,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
|
|
|
1015
1086
|
},
|
|
1016
1087
|
...this.loadOptions
|
|
1017
1088
|
};
|
|
1018
|
-
return
|
|
1089
|
+
return await import_mvt.MVTLoader.parse(arrayBuffer, loadOptions);
|
|
1019
1090
|
}
|
|
1020
1091
|
getMetadataUrl() {
|
|
1021
1092
|
return `${this.url}/tilejson.json`;
|
|
@@ -1023,10 +1094,10 @@ var MVTSource = class extends import_loader_utils.DataSource {
|
|
|
1023
1094
|
getTileURL(x2, y2, z) {
|
|
1024
1095
|
switch (this.schema) {
|
|
1025
1096
|
case "xyz":
|
|
1026
|
-
return `${this.url}/${x2}/${y2}/${z}`;
|
|
1097
|
+
return `${this.url}/${x2}/${y2}/${z}${this.extension}`;
|
|
1027
1098
|
case "tms":
|
|
1028
1099
|
default:
|
|
1029
|
-
return `${this.url}/${z}/${x2}/${y2}`;
|
|
1100
|
+
return `${this.url}/${z}/${x2}/${y2}${this.extension}`;
|
|
1030
1101
|
}
|
|
1031
1102
|
}
|
|
1032
1103
|
};
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
+
export type TileJSONOptions = {
|
|
2
|
+
maxValues?: number | false;
|
|
3
|
+
};
|
|
1
4
|
/** Parsed and typed TileJSON, merges Tilestats information if present */
|
|
2
5
|
export type TileJSON = {
|
|
3
6
|
name?: string;
|
|
4
7
|
description?: string;
|
|
5
8
|
version?: string;
|
|
9
|
+
tileFormat?: string;
|
|
10
|
+
tilesetType?: string;
|
|
11
|
+
/** Generating application. Tippecanoe adds this. */
|
|
12
|
+
generator?: string;
|
|
13
|
+
/** Generating application options. Tippecanoe adds this. */
|
|
14
|
+
generatorOptions?: string;
|
|
15
|
+
/** Tile indexing scheme */
|
|
6
16
|
scheme?: 'xyz' | 'tms';
|
|
17
|
+
/** Sharded URLs */
|
|
7
18
|
tiles?: string[];
|
|
8
19
|
/** `[[w, s], [e, n]]`, indicates the limits of the bounding box using the axis units and order of the specified CRS. */
|
|
9
20
|
boundingBox?: [min: [w: number, s: number], max: [e: number, n: number]];
|
|
10
|
-
|
|
11
|
-
maxZoom
|
|
12
|
-
minZoom
|
|
21
|
+
/** May be set to the maxZoom of the first layer */
|
|
22
|
+
maxZoom?: number | null;
|
|
23
|
+
/** May be set to the minZoom of the first layer */
|
|
24
|
+
minZoom?: number | null;
|
|
25
|
+
center?: number[] | null;
|
|
13
26
|
htmlAttribution?: string;
|
|
14
27
|
htmlLegend?: string;
|
|
15
28
|
layers?: TileJSONLayer[];
|
|
29
|
+
/** Any nested JSON metadata */
|
|
16
30
|
metaJson?: any | null;
|
|
17
31
|
};
|
|
18
32
|
export type TileJSONLayer = {
|
|
@@ -39,8 +53,10 @@ export type TileJSONField = {
|
|
|
39
53
|
min?: number;
|
|
40
54
|
/** max value (if there are *any* numbers in the values) */
|
|
41
55
|
max?: number;
|
|
56
|
+
/** Number of unique values across the tileset */
|
|
57
|
+
uniqueValueCount?: number;
|
|
42
58
|
/** An array of this attribute's first 100 unique values */
|
|
43
59
|
values?: unknown[];
|
|
44
60
|
};
|
|
45
|
-
export declare function parseTileJSON(jsonMetadata: any): TileJSON | null;
|
|
61
|
+
export declare function parseTileJSON(jsonMetadata: any, options: TileJSONOptions): TileJSON | null;
|
|
46
62
|
//# sourceMappingURL=parse-tilejson.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-tilejson.d.ts","sourceRoot":"","sources":["../../src/lib/parse-tilejson.ts"],"names":[],"mappings":"AAGA,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-tilejson.d.ts","sourceRoot":"","sources":["../../src/lib/parse-tilejson.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,2BAA2B;IAC3B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,wHAAwH;IACxH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACzE,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IAEzB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IAEb,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IAEvE,OAAO;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AA+CF,wBAAgB,aAAa,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,GAAG,IAAI,CAgE1F"}
|