@loaders.gl/pmtiles 4.3.0-alpha.2 → 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 CHANGED
@@ -793,7 +793,8 @@ var __exports__ = (() => {
793
793
  // bundle.ts
794
794
  var bundle_exports = {};
795
795
  __export(bundle_exports, {
796
- PMTilesSource: () => PMTilesSource
796
+ PMTilesSource: () => PMTilesSource,
797
+ PMTilesTileSource: () => PMTilesTileSource
797
798
  });
798
799
  __reExport(bundle_exports, __toESM(require_core(), 1));
799
800
 
@@ -1879,6 +1880,241 @@ var __exports__ = (() => {
1879
1880
  options: DEFAULT_IMAGE_LOADER_OPTIONS
1880
1881
  };
1881
1882
 
1883
+ // ../mvt/src/lib/parse-tilejson.ts
1884
+ var isObject = (x2) => x2 !== null && typeof x2 === "object";
1885
+ function parseTileJSON(jsonMetadata, options) {
1886
+ if (!jsonMetadata || !isObject(jsonMetadata)) {
1887
+ return null;
1888
+ }
1889
+ let tileJSON = {
1890
+ name: jsonMetadata.name || "",
1891
+ description: jsonMetadata.description || ""
1892
+ };
1893
+ if (typeof jsonMetadata.generator === "string") {
1894
+ tileJSON.generator = jsonMetadata.generator;
1895
+ }
1896
+ if (typeof jsonMetadata.generator_options === "string") {
1897
+ tileJSON.generatorOptions = jsonMetadata.generator_options;
1898
+ }
1899
+ tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
1900
+ tileJSON.center = parseCenter(jsonMetadata.center);
1901
+ tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
1902
+ tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
1903
+ if (typeof jsonMetadata?.json === "string") {
1904
+ try {
1905
+ tileJSON.metaJson = JSON.parse(jsonMetadata.json);
1906
+ } catch (error) {
1907
+ console.warn("Failed to parse tilejson.json field", error);
1908
+ }
1909
+ }
1910
+ const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
1911
+ const tileStatsLayers = parseTilestatsLayers(tilestats, options);
1912
+ const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
1913
+ const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
1914
+ tileJSON = {
1915
+ ...tileJSON,
1916
+ layers
1917
+ };
1918
+ if (tileJSON.maxZoom === null && layers.length > 0) {
1919
+ tileJSON.maxZoom = layers[0].maxZoom || null;
1920
+ }
1921
+ if (tileJSON.minZoom === null && layers.length > 0) {
1922
+ tileJSON.minZoom = layers[0].minZoom || null;
1923
+ }
1924
+ return tileJSON;
1925
+ }
1926
+ function parseTileJSONLayers(layers) {
1927
+ if (!Array.isArray(layers)) {
1928
+ return [];
1929
+ }
1930
+ return layers.map((layer) => parseTileJSONLayer(layer));
1931
+ }
1932
+ function parseTileJSONLayer(layer) {
1933
+ const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
1934
+ name: key,
1935
+ ...attributeTypeToFieldType(String(datatype))
1936
+ }));
1937
+ const layer2 = { ...layer };
1938
+ delete layer2.fields;
1939
+ return {
1940
+ name: layer.id || "",
1941
+ ...layer2,
1942
+ fields
1943
+ };
1944
+ }
1945
+ function parseTilestatsLayers(tilestats, options) {
1946
+ if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
1947
+ return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
1948
+ }
1949
+ return [];
1950
+ }
1951
+ function parseTilestatsForLayer(layer, options) {
1952
+ const fields = [];
1953
+ const indexedAttributes = {};
1954
+ const attributes = layer.attributes || [];
1955
+ for (const attribute of attributes) {
1956
+ const name = attribute.attribute;
1957
+ if (typeof name === "string") {
1958
+ if (name.split("|").length > 1) {
1959
+ const fname = name.split("|")[0];
1960
+ indexedAttributes[fname] = indexedAttributes[fname] || [];
1961
+ indexedAttributes[fname].push(attribute);
1962
+ console.warn("ignoring tilestats indexed field", fname);
1963
+ } else if (!fields[name]) {
1964
+ fields.push(attributeToField(attribute, options));
1965
+ } else {
1966
+ }
1967
+ }
1968
+ }
1969
+ return {
1970
+ name: layer.layer || "",
1971
+ dominantGeometry: layer.geometry,
1972
+ fields
1973
+ };
1974
+ }
1975
+ function mergeLayers(layers, tilestatsLayers) {
1976
+ return layers.map((layer) => {
1977
+ const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
1978
+ const fields = tilestatsLayer?.fields || [];
1979
+ const layer2 = { ...layer };
1980
+ delete layer2.fields;
1981
+ return {
1982
+ ...layer2,
1983
+ ...tilestatsLayer,
1984
+ fields
1985
+ };
1986
+ });
1987
+ }
1988
+ function parseBounds(bounds) {
1989
+ const result = fromArrayOrString(bounds);
1990
+ if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
1991
+ return [
1992
+ [result[0], result[1]],
1993
+ [result[2], result[3]]
1994
+ ];
1995
+ }
1996
+ return void 0;
1997
+ }
1998
+ function parseCenter(center) {
1999
+ const result = fromArrayOrString(center);
2000
+ if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
2001
+ return result;
2002
+ }
2003
+ return null;
2004
+ }
2005
+ function safeParseFloat(input) {
2006
+ const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
2007
+ return result === null || isNaN(result) ? null : result;
2008
+ }
2009
+ function isLat(num) {
2010
+ return Number.isFinite(num) && num <= 90 && num >= -90;
2011
+ }
2012
+ function isLng(num) {
2013
+ return Number.isFinite(num) && num <= 180 && num >= -180;
2014
+ }
2015
+ function isZoom(num) {
2016
+ return Number.isFinite(num) && num >= 0 && num <= 22;
2017
+ }
2018
+ function fromArrayOrString(data) {
2019
+ if (typeof data === "string") {
2020
+ return data.split(",").map(parseFloat);
2021
+ } else if (Array.isArray(data)) {
2022
+ return data;
2023
+ }
2024
+ return null;
2025
+ }
2026
+ var attrTypeMap = {
2027
+ number: {
2028
+ type: "float32"
2029
+ },
2030
+ numeric: {
2031
+ type: "float32"
2032
+ },
2033
+ string: {
2034
+ type: "utf8"
2035
+ },
2036
+ vachar: {
2037
+ type: "utf8"
2038
+ },
2039
+ float: {
2040
+ type: "float32"
2041
+ },
2042
+ int: {
2043
+ type: "int32"
2044
+ },
2045
+ int4: {
2046
+ type: "int32"
2047
+ },
2048
+ boolean: {
2049
+ type: "boolean"
2050
+ },
2051
+ bool: {
2052
+ type: "boolean"
2053
+ }
2054
+ };
2055
+ function attributeToField(attribute = {}, options) {
2056
+ const fieldTypes = attributeTypeToFieldType(attribute.type);
2057
+ const field = {
2058
+ name: attribute.attribute,
2059
+ // what happens if attribute type is string...
2060
+ // filterProps: getFilterProps(fieldTypes.type, attribute),
2061
+ ...fieldTypes
2062
+ };
2063
+ if (typeof attribute.min === "number") {
2064
+ field.min = attribute.min;
2065
+ }
2066
+ if (typeof attribute.max === "number") {
2067
+ field.max = attribute.max;
2068
+ }
2069
+ if (typeof attribute.count === "number") {
2070
+ field.uniqueValueCount = attribute.count;
2071
+ }
2072
+ if (attribute.values) {
2073
+ field.values = attribute.values;
2074
+ }
2075
+ if (field.values && typeof options.maxValues === "number") {
2076
+ field.values = field.values?.slice(0, options.maxValues);
2077
+ }
2078
+ return field;
2079
+ }
2080
+ function attributeTypeToFieldType(aType) {
2081
+ const type = aType.toLowerCase();
2082
+ if (!type || !attrTypeMap[type]) {
2083
+ }
2084
+ return attrTypeMap[type] || { type: "string" };
2085
+ }
2086
+
2087
+ // ../mvt/src/tilejson-loader.ts
2088
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2089
+ var TileJSONLoader = {
2090
+ dataType: null,
2091
+ batchType: null,
2092
+ name: "TileJSON",
2093
+ id: "tilejson",
2094
+ module: "pmtiles",
2095
+ version: VERSION4,
2096
+ worker: true,
2097
+ extensions: ["json"],
2098
+ mimeTypes: ["application/json"],
2099
+ text: true,
2100
+ options: {
2101
+ tilejson: {
2102
+ maxValues: void 0
2103
+ }
2104
+ },
2105
+ parse: async (arrayBuffer, options) => {
2106
+ const jsonString = new TextDecoder().decode(arrayBuffer);
2107
+ const json = JSON.parse(jsonString);
2108
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
2109
+ return parseTileJSON(json, tilejsonOptions);
2110
+ },
2111
+ parseTextSync: (text, options) => {
2112
+ const json = JSON.parse(text);
2113
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
2114
+ return parseTileJSON(json, tilejsonOptions);
2115
+ }
2116
+ };
2117
+
1882
2118
  // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
1883
2119
  var DimIndex = {
1884
2120
  x: 0,
@@ -2705,7 +2941,7 @@ var __exports__ = (() => {
2705
2941
  p[1] /= extent;
2706
2942
  }
2707
2943
  function convertToLocalCoordinatesFlat(data, extent) {
2708
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
2944
+ for (let i2 = 0; i2 < data.length; ++i2) {
2709
2945
  data[i2] /= extent;
2710
2946
  }
2711
2947
  }
@@ -3340,14 +3576,14 @@ var __exports__ = (() => {
3340
3576
  }
3341
3577
 
3342
3578
  // ../mvt/src/mvt-loader.ts
3343
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3579
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3344
3580
  var MVTWorkerLoader = {
3345
3581
  dataType: null,
3346
3582
  batchType: null,
3347
3583
  name: "Mapbox Vector Tile",
3348
3584
  id: "mvt",
3349
3585
  module: "mvt",
3350
- version: VERSION4,
3586
+ version: VERSION5,
3351
3587
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
3352
3588
  extensions: ["mvt", "pbf"],
3353
3589
  mimeTypes: [
@@ -3375,241 +3611,6 @@ var __exports__ = (() => {
3375
3611
  binary: true
3376
3612
  };
3377
3613
 
3378
- // ../mvt/src/lib/parse-tilejson.ts
3379
- var isObject = (x2) => x2 !== null && typeof x2 === "object";
3380
- function parseTileJSON(jsonMetadata, options) {
3381
- if (!jsonMetadata || !isObject(jsonMetadata)) {
3382
- return null;
3383
- }
3384
- let tileJSON = {
3385
- name: jsonMetadata.name || "",
3386
- description: jsonMetadata.description || ""
3387
- };
3388
- if (typeof jsonMetadata.generator === "string") {
3389
- tileJSON.generator = jsonMetadata.generator;
3390
- }
3391
- if (typeof jsonMetadata.generator_options === "string") {
3392
- tileJSON.generatorOptions = jsonMetadata.generator_options;
3393
- }
3394
- tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
3395
- tileJSON.center = parseCenter(jsonMetadata.center);
3396
- tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
3397
- tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
3398
- if (typeof jsonMetadata?.json === "string") {
3399
- try {
3400
- tileJSON.metaJson = JSON.parse(jsonMetadata.json);
3401
- } catch (error) {
3402
- console.warn("Failed to parse tilejson.json field", error);
3403
- }
3404
- }
3405
- const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
3406
- const tileStatsLayers = parseTilestatsLayers(tilestats, options);
3407
- const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
3408
- const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
3409
- tileJSON = {
3410
- ...tileJSON,
3411
- layers
3412
- };
3413
- if (tileJSON.maxZoom === null && layers.length > 0) {
3414
- tileJSON.maxZoom = layers[0].maxZoom || null;
3415
- }
3416
- if (tileJSON.minZoom === null && layers.length > 0) {
3417
- tileJSON.minZoom = layers[0].minZoom || null;
3418
- }
3419
- return tileJSON;
3420
- }
3421
- function parseTileJSONLayers(layers) {
3422
- if (!Array.isArray(layers)) {
3423
- return [];
3424
- }
3425
- return layers.map((layer) => parseTileJSONLayer(layer));
3426
- }
3427
- function parseTileJSONLayer(layer) {
3428
- const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
3429
- name: key,
3430
- ...attributeTypeToFieldType(String(datatype))
3431
- }));
3432
- const layer2 = { ...layer };
3433
- delete layer2.fields;
3434
- return {
3435
- name: layer.id || "",
3436
- ...layer2,
3437
- fields
3438
- };
3439
- }
3440
- function parseTilestatsLayers(tilestats, options) {
3441
- if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
3442
- return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
3443
- }
3444
- return [];
3445
- }
3446
- function parseTilestatsForLayer(layer, options) {
3447
- const fields = [];
3448
- const indexedAttributes = {};
3449
- const attributes = layer.attributes || [];
3450
- for (const attribute of attributes) {
3451
- const name = attribute.attribute;
3452
- if (typeof name === "string") {
3453
- if (name.split("|").length > 1) {
3454
- const fname = name.split("|")[0];
3455
- indexedAttributes[fname] = indexedAttributes[fname] || [];
3456
- indexedAttributes[fname].push(attribute);
3457
- console.warn("ignoring tilestats indexed field", fname);
3458
- } else if (!fields[name]) {
3459
- fields.push(attributeToField(attribute, options));
3460
- } else {
3461
- }
3462
- }
3463
- }
3464
- return {
3465
- name: layer.layer || "",
3466
- dominantGeometry: layer.geometry,
3467
- fields
3468
- };
3469
- }
3470
- function mergeLayers(layers, tilestatsLayers) {
3471
- return layers.map((layer) => {
3472
- const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
3473
- const fields = tilestatsLayer?.fields || [];
3474
- const layer2 = { ...layer };
3475
- delete layer2.fields;
3476
- return {
3477
- ...layer2,
3478
- ...tilestatsLayer,
3479
- fields
3480
- };
3481
- });
3482
- }
3483
- function parseBounds(bounds) {
3484
- const result = fromArrayOrString(bounds);
3485
- if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
3486
- return [
3487
- [result[0], result[1]],
3488
- [result[2], result[3]]
3489
- ];
3490
- }
3491
- return void 0;
3492
- }
3493
- function parseCenter(center) {
3494
- const result = fromArrayOrString(center);
3495
- if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
3496
- return result;
3497
- }
3498
- return null;
3499
- }
3500
- function safeParseFloat(input) {
3501
- const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
3502
- return result === null || isNaN(result) ? null : result;
3503
- }
3504
- function isLat(num) {
3505
- return Number.isFinite(num) && num <= 90 && num >= -90;
3506
- }
3507
- function isLng(num) {
3508
- return Number.isFinite(num) && num <= 180 && num >= -180;
3509
- }
3510
- function isZoom(num) {
3511
- return Number.isFinite(num) && num >= 0 && num <= 22;
3512
- }
3513
- function fromArrayOrString(data) {
3514
- if (typeof data === "string") {
3515
- return data.split(",").map(parseFloat);
3516
- } else if (Array.isArray(data)) {
3517
- return data;
3518
- }
3519
- return null;
3520
- }
3521
- var attrTypeMap = {
3522
- number: {
3523
- type: "float32"
3524
- },
3525
- numeric: {
3526
- type: "float32"
3527
- },
3528
- string: {
3529
- type: "utf8"
3530
- },
3531
- vachar: {
3532
- type: "utf8"
3533
- },
3534
- float: {
3535
- type: "float32"
3536
- },
3537
- int: {
3538
- type: "int32"
3539
- },
3540
- int4: {
3541
- type: "int32"
3542
- },
3543
- boolean: {
3544
- type: "boolean"
3545
- },
3546
- bool: {
3547
- type: "boolean"
3548
- }
3549
- };
3550
- function attributeToField(attribute = {}, options) {
3551
- const fieldTypes = attributeTypeToFieldType(attribute.type);
3552
- const field = {
3553
- name: attribute.attribute,
3554
- // what happens if attribute type is string...
3555
- // filterProps: getFilterProps(fieldTypes.type, attribute),
3556
- ...fieldTypes
3557
- };
3558
- if (typeof attribute.min === "number") {
3559
- field.min = attribute.min;
3560
- }
3561
- if (typeof attribute.max === "number") {
3562
- field.max = attribute.max;
3563
- }
3564
- if (typeof attribute.count === "number") {
3565
- field.uniqueValueCount = attribute.count;
3566
- }
3567
- if (attribute.values) {
3568
- field.values = attribute.values;
3569
- }
3570
- if (field.values && typeof options.maxValues === "number") {
3571
- field.values = field.values?.slice(0, options.maxValues);
3572
- }
3573
- return field;
3574
- }
3575
- function attributeTypeToFieldType(aType) {
3576
- const type = aType.toLowerCase();
3577
- if (!type || !attrTypeMap[type]) {
3578
- }
3579
- return attrTypeMap[type] || { type: "string" };
3580
- }
3581
-
3582
- // ../mvt/src/tilejson-loader.ts
3583
- var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3584
- var TileJSONLoader = {
3585
- dataType: null,
3586
- batchType: null,
3587
- name: "TileJSON",
3588
- id: "tilejson",
3589
- module: "pmtiles",
3590
- version: VERSION5,
3591
- worker: true,
3592
- extensions: ["json"],
3593
- mimeTypes: ["application/json"],
3594
- text: true,
3595
- options: {
3596
- tilejson: {
3597
- maxValues: void 0
3598
- }
3599
- },
3600
- parse: async (arrayBuffer, options) => {
3601
- const jsonString = new TextDecoder().decode(arrayBuffer);
3602
- const json = JSON.parse(jsonString);
3603
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3604
- return parseTileJSON(json, tilejsonOptions);
3605
- },
3606
- parseTextSync: (text, options) => {
3607
- const json = JSON.parse(text);
3608
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3609
- return parseTileJSON(json, tilejsonOptions);
3610
- }
3611
- };
3612
-
3613
3614
  // ../../node_modules/pmtiles/dist/index.js
3614
3615
  var dist_exports = {};
3615
3616
  __export(dist_exports, {
@@ -5325,16 +5326,31 @@ var __exports__ = (() => {
5325
5326
 
5326
5327
  // src/pmtiles-source.ts
5327
5328
  var { PMTiles: PMTiles2 } = dist_exports;
5328
- var PMTilesSource = class extends DataSource {
5329
+ var VERSION6 = "1.0.0";
5330
+ var PMTilesSource = {
5331
+ name: "PMTiles",
5332
+ id: "pmtiles",
5333
+ module: "pmtiles",
5334
+ version: VERSION6,
5335
+ extensions: ["pmtiles"],
5336
+ mimeTypes: ["application/octet-stream"],
5337
+ options: { url: void 0, pmtiles: {} },
5338
+ type: "pmtiles",
5339
+ fromUrl: true,
5340
+ fromBlob: true,
5341
+ testURL: (url) => url.endsWith(".pmtiles"),
5342
+ createDataSource: (url, props) => new PMTilesTileSource(url, props)
5343
+ };
5344
+ var PMTilesTileSource = class extends DataSource {
5329
5345
  data;
5330
5346
  props;
5331
5347
  mimeType = null;
5332
5348
  pmtiles;
5333
5349
  metadata;
5334
- constructor(props) {
5350
+ constructor(data, props) {
5335
5351
  super(props);
5336
5352
  this.props = props;
5337
- const url = typeof props.url === "string" ? resolvePath(props.url) : new BlobSource(props.url, "pmtiles");
5353
+ const url = typeof data === "string" ? resolvePath(data) : new BlobSource(data, "pmtiles");
5338
5354
  this.data = props.url;
5339
5355
  this.pmtiles = new PMTiles2(url);
5340
5356
  this.getTileData = this.getTileData.bind(this);