@loaders.gl/pmtiles 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 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
 
@@ -1399,7 +1400,16 @@ var __exports__ = (() => {
1399
1400
  // ../loader-utils/src/lib/log-utils/log.ts
1400
1401
  var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1401
1402
  var version = VERSION2[0] >= "0" && VERSION2[0] <= "9" ? `v${VERSION2}` : "";
1402
- var log = new Log({ id: `loaders.gl ${version}` });
1403
+ function createLog() {
1404
+ const log2 = new Log({ id: "loaders.gl" });
1405
+ globalThis.loaders = globalThis.loaders || {};
1406
+ globalThis.loaders.log = log2;
1407
+ globalThis.loaders.version = version;
1408
+ globalThis.probe = globalThis.probe || {};
1409
+ globalThis.probe.loaders = log2;
1410
+ return log2;
1411
+ }
1412
+ var log = createLog();
1403
1413
 
1404
1414
  // ../loader-utils/src/lib/path-utils/file-aliases.ts
1405
1415
  var pathPrefix = "";
@@ -1870,6 +1880,241 @@ var __exports__ = (() => {
1870
1880
  options: DEFAULT_IMAGE_LOADER_OPTIONS
1871
1881
  };
1872
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
+
1873
2118
  // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
1874
2119
  var DimIndex = {
1875
2120
  x: 0,
@@ -2684,6 +2929,39 @@ var __exports__ = (() => {
2684
2929
  }
2685
2930
  return sum;
2686
2931
  }
2932
+ function convertToLocalCoordinates(coordinates, extent) {
2933
+ if (Array.isArray(coordinates[0])) {
2934
+ for (const subcoords of coordinates) {
2935
+ convertToLocalCoordinates(subcoords, extent);
2936
+ }
2937
+ return;
2938
+ }
2939
+ const p = coordinates;
2940
+ p[0] /= extent;
2941
+ p[1] /= extent;
2942
+ }
2943
+ function convertToLocalCoordinatesFlat(data, extent) {
2944
+ for (let i2 = 0; i2 < data.length; ++i2) {
2945
+ data[i2] /= extent;
2946
+ }
2947
+ }
2948
+ function projectToLngLat(line, tileIndex, extent) {
2949
+ if (typeof line[0][0] !== "number") {
2950
+ for (const point of line) {
2951
+ projectToLngLat(point, tileIndex, extent);
2952
+ }
2953
+ return;
2954
+ }
2955
+ const size = extent * Math.pow(2, tileIndex.z);
2956
+ const x0 = extent * tileIndex.x;
2957
+ const y0 = extent * tileIndex.y;
2958
+ for (let j = 0; j < line.length; j++) {
2959
+ const p = line[j];
2960
+ p[0] = (p[0] + x0) * 360 / size - 180;
2961
+ const y2 = 180 - (p[1] + y0) * 360 / size;
2962
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2963
+ }
2964
+ }
2687
2965
  function projectToLngLatFlat(data, tileIndex, extent) {
2688
2966
  const { x: x2, y, z } = tileIndex;
2689
2967
  const size = extent * Math.pow(2, z);
@@ -2793,39 +3071,37 @@ var __exports__ = (() => {
2793
3071
  this._geometryInfo = geometryInfo;
2794
3072
  pbf.readFields(readFeature, this, end);
2795
3073
  }
2796
- toGeoJSON(options) {
3074
+ toGeoJSONFeature(coordinates, tileIndex) {
2797
3075
  const coords = this.loadGeometry();
2798
- if (typeof options === "function") {
2799
- return _toGeoJSON(this, coords, options);
2800
- }
2801
- const { x: x2, y, z } = options;
2802
- const size = this.extent * Math.pow(2, z);
2803
- const x0 = this.extent * x2;
2804
- const y0 = this.extent * y;
2805
- function project(line) {
2806
- for (let j = 0; j < line.length; j++) {
2807
- const p = line[j];
2808
- p[0] = (p[0] + x0) * 360 / size - 180;
2809
- const y2 = 180 - (p[1] + y0) * 360 / size;
2810
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2811
- }
3076
+ switch (coordinates) {
3077
+ case "wgs84":
3078
+ return _toGeoJSONFeature(
3079
+ this,
3080
+ coords,
3081
+ (line) => projectToLngLat(line, tileIndex, this.extent)
3082
+ );
3083
+ default:
3084
+ return _toGeoJSONFeature(this, coords, convertToLocalCoordinates);
2812
3085
  }
2813
- return _toGeoJSON(this, coords, project);
2814
3086
  }
2815
3087
  /**
2816
3088
  *
2817
3089
  * @param options
2818
3090
  * @returns
2819
3091
  */
2820
- toBinaryCoordinates(options) {
2821
- if (typeof options === "function") {
2822
- return this._toBinaryCoordinates(options);
3092
+ toBinaryFeature(coordinates, tileIndex) {
3093
+ const geom = this.loadFlatGeometry();
3094
+ switch (coordinates) {
3095
+ case "wgs84":
3096
+ return this._toBinaryCoordinates(
3097
+ geom,
3098
+ (coords) => projectToLngLatFlat(coords, tileIndex, this.extent)
3099
+ );
3100
+ default:
3101
+ return this._toBinaryCoordinates(geom, convertToLocalCoordinatesFlat);
2823
3102
  }
2824
- const tileIndex = options;
2825
- return this._toBinaryCoordinates(
2826
- (data) => projectToLngLatFlat(data, tileIndex, this.extent)
2827
- );
2828
3103
  }
3104
+ /** Read a bounding box from the feature */
2829
3105
  // eslint-disable-next-line max-statements
2830
3106
  bbox() {
2831
3107
  const pbf = this._pbf;
@@ -2869,10 +3145,9 @@ var __exports__ = (() => {
2869
3145
  * @param transform
2870
3146
  * @returns result
2871
3147
  */
2872
- _toBinaryCoordinates(transform) {
2873
- const geom = this.loadFlatGeometry();
3148
+ _toBinaryCoordinates(geom, transform) {
2874
3149
  let geometry;
2875
- transform(geom.data, this);
3150
+ transform(geom.data, this.extent);
2876
3151
  const coordLength = 2;
2877
3152
  switch (this.type) {
2878
3153
  case 1:
@@ -2949,6 +3224,28 @@ var __exports__ = (() => {
2949
3224
  lines.push(line);
2950
3225
  return lines;
2951
3226
  }
3227
+ /**
3228
+ * Expands the protobuf data to an intermediate Flat GeoJSON
3229
+ * data format, which maps closely to the binary data buffers.
3230
+ * It is similar to GeoJSON, but rather than storing the coordinates
3231
+ * in multidimensional arrays, we have a 1D `data` with all the
3232
+ * coordinates, and then index into this using the `indices`
3233
+ * parameter, e.g.
3234
+ *
3235
+ * geometry: {
3236
+ * type: 'Point', data: [1,2], indices: [0]
3237
+ * }
3238
+ * geometry: {
3239
+ * type: 'LineString', data: [1,2,3,4,...], indices: [0]
3240
+ * }
3241
+ * geometry: {
3242
+ * type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
3243
+ * }
3244
+ * Thus the indices member lets us look up the relevant range
3245
+ * from the data array.
3246
+ * The Multi* versions of the above types share the same data
3247
+ * structure, just with multiple elements in the indices array
3248
+ */
2952
3249
  // eslint-disable-next-line complexity, max-statements
2953
3250
  loadFlatGeometry() {
2954
3251
  const pbf = this._pbf;
@@ -2991,7 +3288,7 @@ var __exports__ = (() => {
2991
3288
  }
2992
3289
  };
2993
3290
  __publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
2994
- function _toGeoJSON(vtFeature, coords, transform) {
3291
+ function _toGeoJSONFeature(vtFeature, coords, transform) {
2995
3292
  let type = VectorTileFeature.types[vtFeature.type];
2996
3293
  let i2;
2997
3294
  let j;
@@ -3003,19 +3300,19 @@ var __exports__ = (() => {
3003
3300
  points[i2] = coords[i2][0];
3004
3301
  }
3005
3302
  coordinates = points;
3006
- transform(coordinates, vtFeature);
3303
+ transform(coordinates, vtFeature.extent);
3007
3304
  break;
3008
3305
  case 2:
3009
3306
  coordinates = coords;
3010
3307
  for (i2 = 0; i2 < coordinates.length; i2++) {
3011
- transform(coordinates[i2], vtFeature);
3308
+ transform(coordinates[i2], vtFeature.extent);
3012
3309
  }
3013
3310
  break;
3014
3311
  case 3:
3015
3312
  coordinates = classifyRings(coords);
3016
3313
  for (i2 = 0; i2 < coordinates.length; i2++) {
3017
3314
  for (j = 0; j < coordinates[i2].length; j++) {
3018
- transform(coordinates[i2][j], vtFeature);
3315
+ transform(coordinates[i2][j], vtFeature.extent);
3019
3316
  }
3020
3317
  }
3021
3318
  break;
@@ -3036,7 +3333,8 @@ var __exports__ = (() => {
3036
3333
  properties: vtFeature.properties
3037
3334
  };
3038
3335
  if (vtFeature.id !== null) {
3039
- result.id = vtFeature.id;
3336
+ result.properties ||= {};
3337
+ result.properties.id = vtFeature.id;
3040
3338
  }
3041
3339
  return result;
3042
3340
  }
@@ -3259,9 +3557,9 @@ var __exports__ = (() => {
3259
3557
  return options.mvt;
3260
3558
  }
3261
3559
  function getDecodedFeature(feature, options, layerName) {
3262
- const decodedFeature = feature.toGeoJSON(
3263
- // @ts-expect-error What is going on here?
3264
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
3560
+ const decodedFeature = feature.toGeoJSONFeature(
3561
+ options.coordinates || "local",
3562
+ options.tileIndex
3265
3563
  );
3266
3564
  if (options.layerProperty) {
3267
3565
  decodedFeature.properties ||= {};
@@ -3270,39 +3568,22 @@ var __exports__ = (() => {
3270
3568
  return decodedFeature;
3271
3569
  }
3272
3570
  function getDecodedFeatureBinary(feature, options, layerName) {
3273
- const decodedFeature = feature.toBinaryCoordinates(
3274
- // @ts-expect-error
3275
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
3276
- );
3571
+ const decodedFeature = feature.toBinaryFeature(options.coordinates || "local", options.tileIndex);
3277
3572
  if (options.layerProperty && decodedFeature.properties) {
3278
3573
  decodedFeature.properties[options.layerProperty] = layerName;
3279
3574
  }
3280
3575
  return decodedFeature;
3281
3576
  }
3282
- function transformToLocalCoordinates(line, feature) {
3283
- const { extent } = feature;
3284
- for (let i2 = 0; i2 < line.length; i2++) {
3285
- const p = line[i2];
3286
- p[0] /= extent;
3287
- p[1] /= extent;
3288
- }
3289
- }
3290
- function transformToLocalCoordinatesBinary(data, feature) {
3291
- const { extent } = feature;
3292
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
3293
- data[i2] /= extent;
3294
- }
3295
- }
3296
3577
 
3297
3578
  // ../mvt/src/mvt-loader.ts
3298
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3579
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3299
3580
  var MVTWorkerLoader = {
3300
3581
  dataType: null,
3301
3582
  batchType: null,
3302
3583
  name: "Mapbox Vector Tile",
3303
3584
  id: "mvt",
3304
3585
  module: "mvt",
3305
- version: VERSION4,
3586
+ version: VERSION5,
3306
3587
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
3307
3588
  extensions: ["mvt", "pbf"],
3308
3589
  mimeTypes: [
@@ -3330,241 +3611,6 @@ var __exports__ = (() => {
3330
3611
  binary: true
3331
3612
  };
3332
3613
 
3333
- // ../mvt/src/lib/parse-tilejson.ts
3334
- var isObject = (x2) => x2 !== null && typeof x2 === "object";
3335
- function parseTileJSON(jsonMetadata, options) {
3336
- if (!jsonMetadata || !isObject(jsonMetadata)) {
3337
- return null;
3338
- }
3339
- let tileJSON = {
3340
- name: jsonMetadata.name || "",
3341
- description: jsonMetadata.description || ""
3342
- };
3343
- if (typeof jsonMetadata.generator === "string") {
3344
- tileJSON.generator = jsonMetadata.generator;
3345
- }
3346
- if (typeof jsonMetadata.generator_options === "string") {
3347
- tileJSON.generatorOptions = jsonMetadata.generator_options;
3348
- }
3349
- tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
3350
- tileJSON.center = parseCenter(jsonMetadata.center);
3351
- tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
3352
- tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
3353
- if (typeof jsonMetadata?.json === "string") {
3354
- try {
3355
- tileJSON.metaJson = JSON.parse(jsonMetadata.json);
3356
- } catch (error) {
3357
- console.warn("Failed to parse tilejson.json field", error);
3358
- }
3359
- }
3360
- const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
3361
- const tileStatsLayers = parseTilestatsLayers(tilestats, options);
3362
- const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
3363
- const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
3364
- tileJSON = {
3365
- ...tileJSON,
3366
- layers
3367
- };
3368
- if (tileJSON.maxZoom === null && layers.length > 0) {
3369
- tileJSON.maxZoom = layers[0].maxZoom || null;
3370
- }
3371
- if (tileJSON.minZoom === null && layers.length > 0) {
3372
- tileJSON.minZoom = layers[0].minZoom || null;
3373
- }
3374
- return tileJSON;
3375
- }
3376
- function parseTileJSONLayers(layers) {
3377
- if (!Array.isArray(layers)) {
3378
- return [];
3379
- }
3380
- return layers.map((layer) => parseTileJSONLayer(layer));
3381
- }
3382
- function parseTileJSONLayer(layer) {
3383
- const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
3384
- name: key,
3385
- ...attributeTypeToFieldType(String(datatype))
3386
- }));
3387
- const layer2 = { ...layer };
3388
- delete layer2.fields;
3389
- return {
3390
- name: layer.id || "",
3391
- ...layer2,
3392
- fields
3393
- };
3394
- }
3395
- function parseTilestatsLayers(tilestats, options) {
3396
- if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
3397
- return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
3398
- }
3399
- return [];
3400
- }
3401
- function parseTilestatsForLayer(layer, options) {
3402
- const fields = [];
3403
- const indexedAttributes = {};
3404
- const attributes = layer.attributes || [];
3405
- for (const attribute of attributes) {
3406
- const name = attribute.attribute;
3407
- if (typeof name === "string") {
3408
- if (name.split("|").length > 1) {
3409
- const fname = name.split("|")[0];
3410
- indexedAttributes[fname] = indexedAttributes[fname] || [];
3411
- indexedAttributes[fname].push(attribute);
3412
- console.warn("ignoring tilestats indexed field", fname);
3413
- } else if (!fields[name]) {
3414
- fields.push(attributeToField(attribute, options));
3415
- } else {
3416
- }
3417
- }
3418
- }
3419
- return {
3420
- name: layer.layer || "",
3421
- dominantGeometry: layer.geometry,
3422
- fields
3423
- };
3424
- }
3425
- function mergeLayers(layers, tilestatsLayers) {
3426
- return layers.map((layer) => {
3427
- const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
3428
- const fields = tilestatsLayer?.fields || [];
3429
- const layer2 = { ...layer };
3430
- delete layer2.fields;
3431
- return {
3432
- ...layer2,
3433
- ...tilestatsLayer,
3434
- fields
3435
- };
3436
- });
3437
- }
3438
- function parseBounds(bounds) {
3439
- const result = fromArrayOrString(bounds);
3440
- if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
3441
- return [
3442
- [result[0], result[1]],
3443
- [result[2], result[3]]
3444
- ];
3445
- }
3446
- return void 0;
3447
- }
3448
- function parseCenter(center) {
3449
- const result = fromArrayOrString(center);
3450
- if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
3451
- return result;
3452
- }
3453
- return null;
3454
- }
3455
- function safeParseFloat(input) {
3456
- const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
3457
- return result === null || isNaN(result) ? null : result;
3458
- }
3459
- function isLat(num) {
3460
- return Number.isFinite(num) && num <= 90 && num >= -90;
3461
- }
3462
- function isLng(num) {
3463
- return Number.isFinite(num) && num <= 180 && num >= -180;
3464
- }
3465
- function isZoom(num) {
3466
- return Number.isFinite(num) && num >= 0 && num <= 22;
3467
- }
3468
- function fromArrayOrString(data) {
3469
- if (typeof data === "string") {
3470
- return data.split(",").map(parseFloat);
3471
- } else if (Array.isArray(data)) {
3472
- return data;
3473
- }
3474
- return null;
3475
- }
3476
- var attrTypeMap = {
3477
- number: {
3478
- type: "float32"
3479
- },
3480
- numeric: {
3481
- type: "float32"
3482
- },
3483
- string: {
3484
- type: "utf8"
3485
- },
3486
- vachar: {
3487
- type: "utf8"
3488
- },
3489
- float: {
3490
- type: "float32"
3491
- },
3492
- int: {
3493
- type: "int32"
3494
- },
3495
- int4: {
3496
- type: "int32"
3497
- },
3498
- boolean: {
3499
- type: "boolean"
3500
- },
3501
- bool: {
3502
- type: "boolean"
3503
- }
3504
- };
3505
- function attributeToField(attribute = {}, options) {
3506
- const fieldTypes = attributeTypeToFieldType(attribute.type);
3507
- const field = {
3508
- name: attribute.attribute,
3509
- // what happens if attribute type is string...
3510
- // filterProps: getFilterProps(fieldTypes.type, attribute),
3511
- ...fieldTypes
3512
- };
3513
- if (typeof attribute.min === "number") {
3514
- field.min = attribute.min;
3515
- }
3516
- if (typeof attribute.max === "number") {
3517
- field.max = attribute.max;
3518
- }
3519
- if (typeof attribute.count === "number") {
3520
- field.uniqueValueCount = attribute.count;
3521
- }
3522
- if (attribute.values) {
3523
- field.values = attribute.values;
3524
- }
3525
- if (field.values && typeof options.maxValues === "number") {
3526
- field.values = field.values?.slice(0, options.maxValues);
3527
- }
3528
- return field;
3529
- }
3530
- function attributeTypeToFieldType(aType) {
3531
- const type = aType.toLowerCase();
3532
- if (!type || !attrTypeMap[type]) {
3533
- }
3534
- return attrTypeMap[type] || { type: "string" };
3535
- }
3536
-
3537
- // ../mvt/src/tilejson-loader.ts
3538
- var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3539
- var TileJSONLoader = {
3540
- dataType: null,
3541
- batchType: null,
3542
- name: "TileJSON",
3543
- id: "tilejson",
3544
- module: "pmtiles",
3545
- version: VERSION5,
3546
- worker: true,
3547
- extensions: ["json"],
3548
- mimeTypes: ["application/json"],
3549
- text: true,
3550
- options: {
3551
- tilejson: {
3552
- maxValues: void 0
3553
- }
3554
- },
3555
- parse: async (arrayBuffer, options) => {
3556
- const jsonString = new TextDecoder().decode(arrayBuffer);
3557
- const json = JSON.parse(jsonString);
3558
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3559
- return parseTileJSON(json, tilejsonOptions);
3560
- },
3561
- parseTextSync: (text, options) => {
3562
- const json = JSON.parse(text);
3563
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3564
- return parseTileJSON(json, tilejsonOptions);
3565
- }
3566
- };
3567
-
3568
3614
  // ../../node_modules/pmtiles/dist/index.js
3569
3615
  var dist_exports = {};
3570
3616
  __export(dist_exports, {
@@ -5280,21 +5326,39 @@ var __exports__ = (() => {
5280
5326
 
5281
5327
  // src/pmtiles-source.ts
5282
5328
  var { PMTiles: PMTiles2 } = dist_exports;
5283
- 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 {
5284
5345
  data;
5285
5346
  props;
5286
5347
  mimeType = null;
5287
5348
  pmtiles;
5288
5349
  metadata;
5289
- constructor(props) {
5350
+ constructor(data, props) {
5290
5351
  super(props);
5291
5352
  this.props = props;
5292
- 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");
5293
5354
  this.data = props.url;
5294
5355
  this.pmtiles = new PMTiles2(url);
5295
5356
  this.getTileData = this.getTileData.bind(this);
5296
5357
  this.metadata = this.getMetadata();
5297
5358
  }
5359
+ async getSchema() {
5360
+ return { fields: [], metadata: {} };
5361
+ }
5298
5362
  async getMetadata() {
5299
5363
  const pmtilesHeader = await this.pmtiles.getHeader();
5300
5364
  const pmtilesMetadata = await this.pmtiles.getMetadata();