@loaders.gl/pmtiles 4.2.0-alpha.4 → 4.2.0-alpha.6

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
@@ -2,8 +2,8 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
9
  var __create = Object.create;
@@ -27,6 +27,7 @@ var __exports__ = (() => {
27
27
  }
28
28
  return to;
29
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
31
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
32
  // If the importer is in node compatibility mode or this is not an ESM
32
33
  // file that has been converted to a CommonJS file using a Babel-
@@ -37,6 +38,13 @@ var __exports__ = (() => {
37
38
  ));
38
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
40
 
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
47
+
40
48
  // ../../node_modules/ieee754/index.js
41
49
  var require_ieee754 = __commonJS({
42
50
  "../../node_modules/ieee754/index.js"(exports) {
@@ -777,11 +785,12 @@ var __exports__ = (() => {
777
785
  }
778
786
  });
779
787
 
780
- // src/index.ts
781
- var src_exports = {};
782
- __export(src_exports, {
788
+ // bundle.ts
789
+ var bundle_exports = {};
790
+ __export(bundle_exports, {
783
791
  PMTilesSource: () => PMTilesSource
784
792
  });
793
+ __reExport(bundle_exports, __toESM(require_core(), 1));
785
794
 
786
795
  // ../loader-utils/src/lib/env-utils/assert.ts
787
796
  function assert(condition, message) {
@@ -801,7 +810,10 @@ var __exports__ = (() => {
801
810
  var window_ = globals.window || globals.self || globals.global || {};
802
811
  var global_ = globals.global || globals.self || globals.window || {};
803
812
  var document_ = globals.document || {};
804
- var isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
813
+ var isBrowser = (
814
+ // @ts-ignore process does not exist on browser
815
+ Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
816
+ );
805
817
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
806
818
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
807
819
 
@@ -869,23 +881,29 @@ var __exports__ = (() => {
869
881
 
870
882
  // ../loader-utils/src/lib/sources/data-source.ts
871
883
  var DataSource = class {
884
+ /** A resolved fetch function extracted from loadOptions prop */
885
+ fetch;
886
+ /** The actual load options, if calling a loaders.gl loader */
887
+ loadOptions;
872
888
  _needsRefresh = true;
889
+ props;
873
890
  constructor(props) {
874
- this.props = {
875
- ...props
876
- };
877
- this.loadOptions = {
878
- ...props.loadOptions
879
- };
891
+ this.props = { ...props };
892
+ this.loadOptions = { ...props.loadOptions };
880
893
  this.fetch = getFetchFunction(this.loadOptions);
881
894
  }
882
895
  setProps(props) {
883
896
  this.props = Object.assign(this.props, props);
884
897
  this.setNeedsRefresh();
885
898
  }
899
+ /** Mark this data source as needing a refresh (redraw) */
886
900
  setNeedsRefresh() {
887
901
  this._needsRefresh = true;
888
902
  }
903
+ /**
904
+ * Does this data source need refreshing?
905
+ * @note The specifics of the refresh mechanism depends on type of data source
906
+ */
889
907
  getNeedsRefresh(clear = true) {
890
908
  const needsRefresh = this._needsRefresh;
891
909
  if (clear) {
@@ -907,7 +925,7 @@ var __exports__ = (() => {
907
925
  }
908
926
 
909
927
  // ../images/src/lib/utils/version.ts
910
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
928
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
911
929
 
912
930
  // ../images/src/lib/category-api/image-type.ts
913
931
  var parseImageNode = globalThis.loaders?.parseImageNode;
@@ -1094,10 +1112,7 @@ var __exports__ = (() => {
1094
1112
  switch (brandMajor) {
1095
1113
  case "avif":
1096
1114
  case "avis":
1097
- return {
1098
- extension: "avif",
1099
- mimeType: "image/avif"
1100
- };
1115
+ return { extension: "avif", mimeType: "image/avif" };
1101
1116
  default:
1102
1117
  return null;
1103
1118
  }
@@ -1133,6 +1148,7 @@ var __exports__ = (() => {
1133
1148
  }
1134
1149
  return {
1135
1150
  mimeType: mediaType.mimeType,
1151
+ // TODO - decode width and height
1136
1152
  width: 0,
1137
1153
  height: 0
1138
1154
  };
@@ -1179,10 +1195,7 @@ var __exports__ = (() => {
1179
1195
  if (!isJpeg) {
1180
1196
  return null;
1181
1197
  }
1182
- const {
1183
- tableMarkers,
1184
- sofMarkers
1185
- } = getJpegMarkers();
1198
+ const { tableMarkers, sofMarkers } = getJpegMarkers();
1186
1199
  let i3 = 2;
1187
1200
  while (i3 + 9 < dataView.byteLength) {
1188
1201
  const marker = dataView.getUint16(i3, BIG_ENDIAN);
@@ -1190,7 +1203,9 @@ var __exports__ = (() => {
1190
1203
  return {
1191
1204
  mimeType: "image/jpeg",
1192
1205
  height: dataView.getUint16(i3 + 5, BIG_ENDIAN),
1206
+ // Number of lines
1193
1207
  width: dataView.getUint16(i3 + 7, BIG_ENDIAN)
1208
+ // Number of pixels per line
1194
1209
  };
1195
1210
  }
1196
1211
  if (!tableMarkers.has(marker)) {
@@ -1206,11 +1221,23 @@ var __exports__ = (() => {
1206
1221
  for (let i3 = 65504; i3 < 65520; ++i3) {
1207
1222
  tableMarkers.add(i3);
1208
1223
  }
1209
- const sofMarkers = /* @__PURE__ */ new Set([65472, 65473, 65474, 65475, 65477, 65478, 65479, 65481, 65482, 65483, 65485, 65486, 65487, 65502]);
1210
- return {
1211
- tableMarkers,
1212
- sofMarkers
1213
- };
1224
+ const sofMarkers = /* @__PURE__ */ new Set([
1225
+ 65472,
1226
+ 65473,
1227
+ 65474,
1228
+ 65475,
1229
+ 65477,
1230
+ 65478,
1231
+ 65479,
1232
+ 65481,
1233
+ 65482,
1234
+ 65483,
1235
+ 65485,
1236
+ 65486,
1237
+ 65487,
1238
+ 65502
1239
+ ]);
1240
+ return { tableMarkers, sofMarkers };
1214
1241
  }
1215
1242
  function toDataView(data) {
1216
1243
  if (data instanceof DataView) {
@@ -1227,9 +1254,7 @@ var __exports__ = (() => {
1227
1254
 
1228
1255
  // ../images/src/lib/parsers/parse-to-node-image.ts
1229
1256
  async function parseToNodeImage(arrayBuffer, options) {
1230
- const {
1231
- mimeType
1232
- } = getBinaryImageMetadata(arrayBuffer) || {};
1257
+ const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
1233
1258
  const parseImageNode2 = globalThis.loaders?.parseImageNode;
1234
1259
  assert(parseImageNode2);
1235
1260
  return await parseImageNode2(arrayBuffer, mimeType);
@@ -1240,9 +1265,7 @@ var __exports__ = (() => {
1240
1265
  options = options || {};
1241
1266
  const imageOptions = options.image || {};
1242
1267
  const imageType = imageOptions.type || "auto";
1243
- const {
1244
- url
1245
- } = context || {};
1268
+ const { url } = context || {};
1246
1269
  const loadType = getLoadableImageType(imageType);
1247
1270
  let image;
1248
1271
  switch (loadType) {
@@ -1276,12 +1299,23 @@ var __exports__ = (() => {
1276
1299
 
1277
1300
  // ../images/src/image-loader.ts
1278
1301
  var EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
1279
- var MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif", "image/bmp", "image/vnd.microsoft.icon", "image/svg+xml"];
1302
+ var MIME_TYPES = [
1303
+ "image/png",
1304
+ "image/jpeg",
1305
+ "image/gif",
1306
+ "image/webp",
1307
+ "image/avif",
1308
+ "image/bmp",
1309
+ "image/vnd.microsoft.icon",
1310
+ "image/svg+xml"
1311
+ ];
1280
1312
  var DEFAULT_IMAGE_LOADER_OPTIONS = {
1281
1313
  image: {
1282
1314
  type: "auto",
1283
1315
  decode: true
1316
+ // if format is HTML
1284
1317
  }
1318
+ // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
1285
1319
  };
1286
1320
  var ImageLoader = {
1287
1321
  id: "image",
@@ -1291,6 +1325,7 @@ var __exports__ = (() => {
1291
1325
  mimeTypes: MIME_TYPES,
1292
1326
  extensions: EXTENSIONS,
1293
1327
  parse: parseImage,
1328
+ // TODO: byteOffset, byteLength;
1294
1329
  tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
1295
1330
  options: DEFAULT_IMAGE_LOADER_OPTIONS
1296
1331
  };
@@ -1812,14 +1847,18 @@ var __exports__ = (() => {
1812
1847
  function flatGeojsonToBinary(features, geometryInfo, options) {
1813
1848
  const propArrayTypes = extractNumericPropTypes(features);
1814
1849
  const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1815
- return fillArrays(features, {
1816
- propArrayTypes,
1817
- ...geometryInfo
1818
- }, {
1819
- numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1820
- PositionDataType: options ? options.PositionDataType : Float32Array,
1821
- triangulate: options ? options.triangulate : true
1822
- });
1850
+ return fillArrays(
1851
+ features,
1852
+ {
1853
+ propArrayTypes,
1854
+ ...geometryInfo
1855
+ },
1856
+ {
1857
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1858
+ PositionDataType: options ? options.PositionDataType : Float32Array,
1859
+ triangulate: options ? options.triangulate : true
1860
+ }
1861
+ );
1823
1862
  }
1824
1863
  function extractNumericPropTypes(features) {
1825
1864
  const propArrayTypes = {};
@@ -1847,11 +1886,7 @@ var __exports__ = (() => {
1847
1886
  propArrayTypes,
1848
1887
  coordLength
1849
1888
  } = geometryInfo;
1850
- const {
1851
- numericPropKeys = [],
1852
- PositionDataType = Float32Array,
1853
- triangulate = true
1854
- } = options;
1889
+ const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
1855
1890
  const hasGlobalId = features[0] && "id" in features[0];
1856
1891
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1857
1892
  const points = {
@@ -1916,9 +1951,7 @@ var __exports__ = (() => {
1916
1951
  handlePoint(geometry, points, indexMap, coordLength, properties);
1917
1952
  points.properties.push(keepStringProperties(properties, numericPropKeys));
1918
1953
  if (hasGlobalId) {
1919
- points.fields.push({
1920
- id: feature.id
1921
- });
1954
+ points.fields.push({ id: feature.id });
1922
1955
  }
1923
1956
  indexMap.pointFeature++;
1924
1957
  break;
@@ -1926,9 +1959,7 @@ var __exports__ = (() => {
1926
1959
  handleLineString(geometry, lines, indexMap, coordLength, properties);
1927
1960
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
1928
1961
  if (hasGlobalId) {
1929
- lines.fields.push({
1930
- id: feature.id
1931
- });
1962
+ lines.fields.push({ id: feature.id });
1932
1963
  }
1933
1964
  indexMap.lineFeature++;
1934
1965
  break;
@@ -1936,9 +1967,7 @@ var __exports__ = (() => {
1936
1967
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1937
1968
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1938
1969
  if (hasGlobalId) {
1939
- polygons.fields.push({
1940
- id: feature.id
1941
- });
1970
+ polygons.fields.push({ id: feature.id });
1942
1971
  }
1943
1972
  indexMap.polygonFeature++;
1944
1973
  break;
@@ -1953,16 +1982,32 @@ var __exports__ = (() => {
1953
1982
  points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
1954
1983
  const nPositions = geometry.data.length / coordLength;
1955
1984
  fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
1956
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
1957
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
1985
+ points.globalFeatureIds.fill(
1986
+ indexMap.feature,
1987
+ indexMap.pointPosition,
1988
+ indexMap.pointPosition + nPositions
1989
+ );
1990
+ points.featureIds.fill(
1991
+ indexMap.pointFeature,
1992
+ indexMap.pointPosition,
1993
+ indexMap.pointPosition + nPositions
1994
+ );
1958
1995
  indexMap.pointPosition += nPositions;
1959
1996
  }
1960
1997
  function handleLineString(geometry, lines, indexMap, coordLength, properties) {
1961
1998
  lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
1962
1999
  const nPositions = geometry.data.length / coordLength;
1963
2000
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1964
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
1965
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
2001
+ lines.globalFeatureIds.fill(
2002
+ indexMap.feature,
2003
+ indexMap.linePosition,
2004
+ indexMap.linePosition + nPositions
2005
+ );
2006
+ lines.featureIds.fill(
2007
+ indexMap.lineFeature,
2008
+ indexMap.linePosition,
2009
+ indexMap.linePosition + nPositions
2010
+ );
1966
2011
  for (let i3 = 0, il = geometry.indices.length; i3 < il; ++i3) {
1967
2012
  const start = geometry.indices[i3];
1968
2013
  const end = i3 === il - 1 ? geometry.data.length : geometry.indices[i3 + 1];
@@ -1974,8 +2019,16 @@ var __exports__ = (() => {
1974
2019
  polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
1975
2020
  const nPositions = geometry.data.length / coordLength;
1976
2021
  fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1977
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1978
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
2022
+ polygons.globalFeatureIds.fill(
2023
+ indexMap.feature,
2024
+ indexMap.polygonPosition,
2025
+ indexMap.polygonPosition + nPositions
2026
+ );
2027
+ polygons.featureIds.fill(
2028
+ indexMap.polygonFeature,
2029
+ indexMap.polygonPosition,
2030
+ indexMap.polygonPosition + nPositions
2031
+ );
1979
2032
  for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
1980
2033
  const startPosition = indexMap.polygonPosition;
1981
2034
  polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
@@ -1984,16 +2037,15 @@ var __exports__ = (() => {
1984
2037
  const nextIndices = geometry.indices[l + 1];
1985
2038
  for (let i3 = 0, il = indices.length; i3 < il; ++i3) {
1986
2039
  const start = indices[i3];
1987
- const end = i3 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i3 + 1];
2040
+ const end = i3 === il - 1 ? (
2041
+ // last line, so either read to:
2042
+ nextIndices === void 0 ? geometry.data.length : nextIndices[0]
2043
+ ) : indices[i3 + 1];
1988
2044
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1989
2045
  indexMap.polygonPosition += (end - start) / coordLength;
1990
2046
  }
1991
2047
  const endPosition = indexMap.polygonPosition;
1992
- triangulatePolygon(polygons, areas, indices, {
1993
- startPosition,
1994
- endPosition,
1995
- coordLength
1996
- });
2048
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
1997
2049
  }
1998
2050
  }
1999
2051
  function triangulatePolygon(polygons, areas, indices, {
@@ -2017,10 +2069,7 @@ var __exports__ = (() => {
2017
2069
  function wrapProps(obj, size) {
2018
2070
  const returnObj = {};
2019
2071
  for (const key in obj) {
2020
- returnObj[key] = {
2021
- value: obj[key],
2022
- size
2023
- };
2072
+ returnObj[key] = { value: obj[key], size };
2024
2073
  }
2025
2074
  return returnObj;
2026
2075
  }
@@ -2029,70 +2078,32 @@ var __exports__ = (() => {
2029
2078
  shape: "binary-feature-collection",
2030
2079
  points: {
2031
2080
  ...points,
2032
- positions: {
2033
- value: points.positions,
2034
- size: coordLength
2035
- },
2036
- globalFeatureIds: {
2037
- value: points.globalFeatureIds,
2038
- size: 1
2039
- },
2040
- featureIds: {
2041
- value: points.featureIds,
2042
- size: 1
2043
- },
2081
+ positions: { value: points.positions, size: coordLength },
2082
+ globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
2083
+ featureIds: { value: points.featureIds, size: 1 },
2044
2084
  numericProps: wrapProps(points.numericProps, 1)
2045
2085
  },
2046
2086
  lines: {
2047
2087
  ...lines,
2048
- positions: {
2049
- value: lines.positions,
2050
- size: coordLength
2051
- },
2052
- pathIndices: {
2053
- value: lines.pathIndices,
2054
- size: 1
2055
- },
2056
- globalFeatureIds: {
2057
- value: lines.globalFeatureIds,
2058
- size: 1
2059
- },
2060
- featureIds: {
2061
- value: lines.featureIds,
2062
- size: 1
2063
- },
2088
+ positions: { value: lines.positions, size: coordLength },
2089
+ pathIndices: { value: lines.pathIndices, size: 1 },
2090
+ globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
2091
+ featureIds: { value: lines.featureIds, size: 1 },
2064
2092
  numericProps: wrapProps(lines.numericProps, 1)
2065
2093
  },
2066
2094
  polygons: {
2067
2095
  ...polygons,
2068
- positions: {
2069
- value: polygons.positions,
2070
- size: coordLength
2071
- },
2072
- polygonIndices: {
2073
- value: polygons.polygonIndices,
2074
- size: 1
2075
- },
2076
- primitivePolygonIndices: {
2077
- value: polygons.primitivePolygonIndices,
2078
- size: 1
2079
- },
2080
- globalFeatureIds: {
2081
- value: polygons.globalFeatureIds,
2082
- size: 1
2083
- },
2084
- featureIds: {
2085
- value: polygons.featureIds,
2086
- size: 1
2087
- },
2096
+ positions: { value: polygons.positions, size: coordLength },
2097
+ polygonIndices: { value: polygons.polygonIndices, size: 1 },
2098
+ primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
2099
+ globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
2100
+ featureIds: { value: polygons.featureIds, size: 1 },
2088
2101
  numericProps: wrapProps(polygons.numericProps, 1)
2089
2102
  }
2103
+ // triangles not expected
2090
2104
  };
2091
2105
  if (binaryFeatures.polygons && polygons.triangles) {
2092
- binaryFeatures.polygons.triangles = {
2093
- value: new Uint32Array(polygons.triangles),
2094
- size: 1
2095
- };
2106
+ binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
2096
2107
  }
2097
2108
  return binaryFeatures;
2098
2109
  }
@@ -2180,6 +2191,14 @@ var __exports__ = (() => {
2180
2191
 
2181
2192
  // ../mvt/src/lib/mapbox-vector-tile/vector-tile-feature.ts
2182
2193
  var VectorTileFeature = class {
2194
+ properties;
2195
+ extent;
2196
+ type;
2197
+ id;
2198
+ _pbf;
2199
+ _geometry;
2200
+ _keys;
2201
+ _values;
2183
2202
  static get types() {
2184
2203
  return ["Unknown", "Point", "LineString", "Polygon"];
2185
2204
  }
@@ -2194,6 +2213,7 @@ var __exports__ = (() => {
2194
2213
  this._values = values;
2195
2214
  pbf.readFields(readFeature, this, end);
2196
2215
  }
2216
+ // eslint-disable-next-line complexity, max-statements
2197
2217
  loadGeometry() {
2198
2218
  const pbf = this._pbf;
2199
2219
  pbf.pos = this._geometry;
@@ -2233,6 +2253,7 @@ var __exports__ = (() => {
2233
2253
  lines.push(line);
2234
2254
  return lines;
2235
2255
  }
2256
+ // eslint-disable-next-line max-statements
2236
2257
  bbox() {
2237
2258
  const pbf = this._pbf;
2238
2259
  pbf.pos = this._geometry;
@@ -2319,11 +2340,7 @@ var __exports__ = (() => {
2319
2340
  if (typeof options === "function") {
2320
2341
  return this._toGeoJSON(options);
2321
2342
  }
2322
- const {
2323
- x: x3,
2324
- y: y2,
2325
- z
2326
- } = options;
2343
+ const { x: x3, y: y2, z } = options;
2327
2344
  const size = this.extent * Math.pow(2, z);
2328
2345
  const x0 = this.extent * x3;
2329
2346
  const y0 = this.extent * y2;
@@ -2341,6 +2358,14 @@ var __exports__ = (() => {
2341
2358
 
2342
2359
  // ../mvt/src/lib/mapbox-vector-tile/vector-tile-layer.ts
2343
2360
  var VectorTileLayer = class {
2361
+ version;
2362
+ name;
2363
+ extent;
2364
+ length;
2365
+ _pbf;
2366
+ _keys;
2367
+ _values;
2368
+ _features;
2344
2369
  constructor(pbf, end) {
2345
2370
  this.version = 1;
2346
2371
  this.name = "";
@@ -2353,6 +2378,11 @@ var __exports__ = (() => {
2353
2378
  pbf.readFields(readLayer, this, end);
2354
2379
  this.length = this._features.length;
2355
2380
  }
2381
+ /**
2382
+ * return feature `i` from this layer as a `VectorTileFeature`
2383
+ * @param index
2384
+ * @returns feature
2385
+ */
2356
2386
  feature(i3) {
2357
2387
  if (i3 < 0 || i3 >= this._features.length) {
2358
2388
  throw new Error("feature index out of bounds");
@@ -2390,6 +2420,7 @@ var __exports__ = (() => {
2390
2420
 
2391
2421
  // ../mvt/src/lib/mapbox-vector-tile/vector-tile.ts
2392
2422
  var VectorTile = class {
2423
+ layers;
2393
2424
  constructor(pbf, end) {
2394
2425
  this.layers = pbf.readFields(readTile, {}, end);
2395
2426
  }
@@ -2453,12 +2484,7 @@ var __exports__ = (() => {
2453
2484
  areas.push(ringAreas);
2454
2485
  if (polygon.length)
2455
2486
  polygons.push(polygon);
2456
- return {
2457
- type,
2458
- areas,
2459
- indices: polygons,
2460
- data: geom.data
2461
- };
2487
+ return { type, areas, indices: polygons, data: geom.data };
2462
2488
  }
2463
2489
  function project(data, x0, y0, size) {
2464
2490
  for (let j = 0, jl = data.length; j < jl; j += 2) {
@@ -2497,6 +2523,16 @@ var __exports__ = (() => {
2497
2523
  var y;
2498
2524
  var i;
2499
2525
  var VectorTileFeature2 = class {
2526
+ properties;
2527
+ extent;
2528
+ type;
2529
+ id;
2530
+ _pbf;
2531
+ _geometry;
2532
+ _keys;
2533
+ _values;
2534
+ _geometryInfo;
2535
+ // eslint-disable-next-line max-params
2500
2536
  constructor(pbf, end, extent, keys, values, geometryInfo) {
2501
2537
  this.properties = {};
2502
2538
  this.extent = extent;
@@ -2509,6 +2545,7 @@ var __exports__ = (() => {
2509
2545
  this._geometryInfo = geometryInfo;
2510
2546
  pbf.readFields(readFeature2, this, end);
2511
2547
  }
2548
+ // eslint-disable-next-line complexity, max-statements
2512
2549
  loadGeometry() {
2513
2550
  const pbf = this._pbf;
2514
2551
  pbf.pos = this._geometry;
@@ -2545,11 +2582,13 @@ var __exports__ = (() => {
2545
2582
  throw new Error(`unknown command ${cmd}`);
2546
2583
  }
2547
2584
  }
2548
- return {
2549
- data,
2550
- indices
2551
- };
2585
+ return { data, indices };
2552
2586
  }
2587
+ /**
2588
+ *
2589
+ * @param transform
2590
+ * @returns result
2591
+ */
2553
2592
  _toBinaryCoordinates(transform) {
2554
2593
  const geom = this.loadGeometry();
2555
2594
  let geometry;
@@ -2559,19 +2598,13 @@ var __exports__ = (() => {
2559
2598
  case 1:
2560
2599
  this._geometryInfo.pointFeaturesCount++;
2561
2600
  this._geometryInfo.pointPositionsCount += geom.indices.length;
2562
- geometry = {
2563
- type: "Point",
2564
- ...geom
2565
- };
2601
+ geometry = { type: "Point", ...geom };
2566
2602
  break;
2567
2603
  case 2:
2568
2604
  this._geometryInfo.lineFeaturesCount++;
2569
2605
  this._geometryInfo.linePathsCount += geom.indices.length;
2570
2606
  this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
2571
- geometry = {
2572
- type: "LineString",
2573
- ...geom
2574
- };
2607
+ geometry = { type: "LineString", ...geom };
2575
2608
  break;
2576
2609
  case 3:
2577
2610
  geometry = classifyRings2(geom);
@@ -2585,11 +2618,7 @@ var __exports__ = (() => {
2585
2618
  default:
2586
2619
  throw new Error(`Invalid geometry type: ${this.type}`);
2587
2620
  }
2588
- const result = {
2589
- type: "Feature",
2590
- geometry,
2591
- properties: this.properties
2592
- };
2621
+ const result = { type: "Feature", geometry, properties: this.properties };
2593
2622
  if (this.id !== null) {
2594
2623
  result.id = this.id;
2595
2624
  }
@@ -2599,11 +2628,7 @@ var __exports__ = (() => {
2599
2628
  if (typeof options === "function") {
2600
2629
  return this._toBinaryCoordinates(options);
2601
2630
  }
2602
- const {
2603
- x: x3,
2604
- y: y2,
2605
- z
2606
- } = options;
2631
+ const { x: x3, y: y2, z } = options;
2607
2632
  const size = this.extent * Math.pow(2, z);
2608
2633
  const x0 = this.extent * x3;
2609
2634
  const y0 = this.extent * y2;
@@ -2613,6 +2638,14 @@ var __exports__ = (() => {
2613
2638
 
2614
2639
  // ../mvt/src/lib/binary-vector-tile/vector-tile-layer.ts
2615
2640
  var VectorTileLayer2 = class {
2641
+ version;
2642
+ name;
2643
+ extent;
2644
+ length;
2645
+ _pbf;
2646
+ _keys;
2647
+ _values;
2648
+ _features;
2616
2649
  constructor(pbf, end) {
2617
2650
  this.version = 1;
2618
2651
  this.name = "";
@@ -2625,13 +2658,27 @@ var __exports__ = (() => {
2625
2658
  pbf.readFields(readLayer2, this, end);
2626
2659
  this.length = this._features.length;
2627
2660
  }
2661
+ /**
2662
+ * return feature `i` from this layer as a `VectorTileFeature`
2663
+ *
2664
+ * @param index
2665
+ * @param geometryInfo
2666
+ * @returns {VectorTileFeature}
2667
+ */
2628
2668
  feature(i3, geometryInfo) {
2629
2669
  if (i3 < 0 || i3 >= this._features.length) {
2630
2670
  throw new Error("feature index out of bounds");
2631
2671
  }
2632
2672
  this._pbf.pos = this._features[i3];
2633
2673
  const end = this._pbf.readVarint() + this._pbf.pos;
2634
- return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
2674
+ return new VectorTileFeature2(
2675
+ this._pbf,
2676
+ end,
2677
+ this.extent,
2678
+ this._keys,
2679
+ this._values,
2680
+ geometryInfo
2681
+ );
2635
2682
  }
2636
2683
  };
2637
2684
  function readLayer2(tag, layer, pbf) {
@@ -2662,6 +2709,7 @@ var __exports__ = (() => {
2662
2709
 
2663
2710
  // ../mvt/src/lib/binary-vector-tile/vector-tile.ts
2664
2711
  var VectorTile2 = class {
2712
+ layers;
2665
2713
  constructor(pbf, end) {
2666
2714
  this.layers = pbf.readFields(readTile2, {}, end);
2667
2715
  }
@@ -2683,10 +2731,7 @@ var __exports__ = (() => {
2683
2731
  const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
2684
2732
  switch (shape) {
2685
2733
  case "columnar-table":
2686
- return {
2687
- shape: "columnar-table",
2688
- data: parseToBinary(arrayBuffer, mvtOptions)
2689
- };
2734
+ return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
2690
2735
  case "geojson-table": {
2691
2736
  const table = {
2692
2737
  shape: "geojson-table",
@@ -2768,9 +2813,7 @@ var __exports__ = (() => {
2768
2813
  throw new Error("mvt options required");
2769
2814
  }
2770
2815
  const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
2771
- const {
2772
- tileIndex
2773
- } = options.mvt;
2816
+ const { tileIndex } = options.mvt;
2774
2817
  const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2775
2818
  if (wgs84Coordinates && !hasTileIndex) {
2776
2819
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
@@ -2778,23 +2821,27 @@ var __exports__ = (() => {
2778
2821
  return options.mvt;
2779
2822
  }
2780
2823
  function getDecodedFeature(feature, options, layerName) {
2781
- const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
2824
+ const decodedFeature = feature.toGeoJSON(
2825
+ // @ts-expect-error What is going on here?
2826
+ options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
2827
+ );
2782
2828
  if (options.layerProperty) {
2783
2829
  decodedFeature.properties[options.layerProperty] = layerName;
2784
2830
  }
2785
2831
  return decodedFeature;
2786
2832
  }
2787
2833
  function getDecodedFeatureBinary(feature, options, layerName) {
2788
- const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
2834
+ const decodedFeature = feature.toBinaryCoordinates(
2835
+ // @ts-expect-error What is going on here?
2836
+ options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
2837
+ );
2789
2838
  if (options.layerProperty && decodedFeature.properties) {
2790
2839
  decodedFeature.properties[options.layerProperty] = layerName;
2791
2840
  }
2792
2841
  return decodedFeature;
2793
2842
  }
2794
2843
  function transformToLocalCoordinates(line, feature) {
2795
- const {
2796
- extent
2797
- } = feature;
2844
+ const { extent } = feature;
2798
2845
  for (let i3 = 0; i3 < line.length; i3++) {
2799
2846
  const p = line[i3];
2800
2847
  p[0] /= extent;
@@ -2802,23 +2849,27 @@ var __exports__ = (() => {
2802
2849
  }
2803
2850
  }
2804
2851
  function transformToLocalCoordinatesBinary(data, feature) {
2805
- const {
2806
- extent
2807
- } = feature;
2852
+ const { extent } = feature;
2808
2853
  for (let i3 = 0, il = data.length; i3 < il; ++i3) {
2809
2854
  data[i3] /= extent;
2810
2855
  }
2811
2856
  }
2812
2857
 
2813
2858
  // ../mvt/src/mvt-loader.ts
2814
- var VERSION2 = true ? "4.2.0-alpha.4" : "latest";
2859
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2815
2860
  var MVTWorkerLoader = {
2816
2861
  name: "Mapbox Vector Tile",
2817
2862
  id: "mvt",
2818
2863
  module: "mvt",
2819
2864
  version: VERSION2,
2865
+ // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
2820
2866
  extensions: ["mvt", "pbf"],
2821
- mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"],
2867
+ mimeTypes: [
2868
+ // https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile
2869
+ "application/vnd.mapbox-vector-tile",
2870
+ "application/x-protobuf"
2871
+ // 'application/octet-stream'
2872
+ ],
2822
2873
  worker: true,
2823
2874
  category: "geometry",
2824
2875
  options: {
@@ -2892,9 +2943,7 @@ var __exports__ = (() => {
2892
2943
  name: key,
2893
2944
  ...attributeTypeToFieldType(String(datatype))
2894
2945
  }));
2895
- const layer2 = {
2896
- ...layer
2897
- };
2946
+ const layer2 = { ...layer };
2898
2947
  delete layer2.fields;
2899
2948
  return {
2900
2949
  name: layer.id || "",
@@ -2936,9 +2985,7 @@ var __exports__ = (() => {
2936
2985
  return layers.map((layer) => {
2937
2986
  const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
2938
2987
  const fields = tilestatsLayer?.fields || [];
2939
- const layer2 = {
2940
- ...layer
2941
- };
2988
+ const layer2 = { ...layer };
2942
2989
  delete layer2.fields;
2943
2990
  return {
2944
2991
  ...layer2,
@@ -2950,7 +2997,10 @@ var __exports__ = (() => {
2950
2997
  function parseBounds(bounds) {
2951
2998
  const result = fromArrayOrString(bounds);
2952
2999
  if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
2953
- return [[result[0], result[1]], [result[2], result[3]]];
3000
+ return [
3001
+ [result[0], result[1]],
3002
+ [result[2], result[3]]
3003
+ ];
2954
3004
  }
2955
3005
  return void 0;
2956
3006
  }
@@ -3015,6 +3065,8 @@ var __exports__ = (() => {
3015
3065
  const fieldTypes = attributeTypeToFieldType(attribute.type);
3016
3066
  const field = {
3017
3067
  name: attribute.attribute,
3068
+ // what happens if attribute type is string...
3069
+ // filterProps: getFilterProps(fieldTypes.type, attribute),
3018
3070
  ...fieldTypes
3019
3071
  };
3020
3072
  if (typeof attribute.min === "number") {
@@ -3038,13 +3090,11 @@ var __exports__ = (() => {
3038
3090
  const type = aType.toLowerCase();
3039
3091
  if (!type || !attrTypeMap[type]) {
3040
3092
  }
3041
- return attrTypeMap[type] || {
3042
- type: "string"
3043
- };
3093
+ return attrTypeMap[type] || { type: "string" };
3044
3094
  }
3045
3095
 
3046
3096
  // ../mvt/src/tilejson-loader.ts
3047
- var VERSION3 = true ? "4.2.0-alpha.4" : "latest";
3097
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3048
3098
  var TileJSONLoader = {
3049
3099
  name: "TileJSON",
3050
3100
  id: "tilejson",
@@ -3062,29 +3112,23 @@ var __exports__ = (() => {
3062
3112
  parse: async (arrayBuffer, options) => {
3063
3113
  const jsonString = new TextDecoder().decode(arrayBuffer);
3064
3114
  const json = JSON.parse(jsonString);
3065
- const tilejsonOptions = {
3066
- ...TileJSONLoader.options.tilejson,
3067
- ...options?.tilejson
3068
- };
3115
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3069
3116
  return parseTileJSON(json, tilejsonOptions);
3070
3117
  },
3071
3118
  parseTextSync: (text, options) => {
3072
3119
  const json = JSON.parse(text);
3073
- const tilejsonOptions = {
3074
- ...TileJSONLoader.options.tilejson,
3075
- ...options?.tilejson
3076
- };
3120
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3077
3121
  return parseTileJSON(json, tilejsonOptions);
3078
3122
  }
3079
3123
  };
3080
3124
 
3081
- // ../../node_modules/pmtiles/dist/index.mjs
3125
+ // ../../node_modules/pmtiles/dist/index.js
3082
3126
  var dist_exports = {};
3083
3127
  __export(dist_exports, {
3084
3128
  Compression: () => Compression,
3085
3129
  EtagMismatch: () => EtagMismatch,
3086
3130
  FetchSource: () => FetchSource,
3087
- FileAPISource: () => FileAPISource,
3131
+ FileSource: () => FileSource,
3088
3132
  PMTiles: () => PMTiles,
3089
3133
  Protocol: () => Protocol,
3090
3134
  ResolvedValueCache: () => ResolvedValueCache,
@@ -3098,6 +3142,7 @@ var __exports__ = (() => {
3098
3142
  tileIdToZxy: () => tileIdToZxy,
3099
3143
  zxyToTileId: () => zxyToTileId
3100
3144
  });
3145
+ var __pow = Math.pow;
3101
3146
  var __async = (__this, __arguments, generator) => {
3102
3147
  return new Promise((resolve, reject) => {
3103
3148
  var fulfilled = (value) => {
@@ -3121,8 +3166,77 @@ var __exports__ = (() => {
3121
3166
  var u8 = Uint8Array;
3122
3167
  var u16 = Uint16Array;
3123
3168
  var i32 = Int32Array;
3124
- var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]);
3125
- var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]);
3169
+ var fleb = new u8([
3170
+ 0,
3171
+ 0,
3172
+ 0,
3173
+ 0,
3174
+ 0,
3175
+ 0,
3176
+ 0,
3177
+ 0,
3178
+ 1,
3179
+ 1,
3180
+ 1,
3181
+ 1,
3182
+ 2,
3183
+ 2,
3184
+ 2,
3185
+ 2,
3186
+ 3,
3187
+ 3,
3188
+ 3,
3189
+ 3,
3190
+ 4,
3191
+ 4,
3192
+ 4,
3193
+ 4,
3194
+ 5,
3195
+ 5,
3196
+ 5,
3197
+ 5,
3198
+ 0,
3199
+ /* unused */
3200
+ 0,
3201
+ 0,
3202
+ /* impossible */
3203
+ 0
3204
+ ]);
3205
+ var fdeb = new u8([
3206
+ 0,
3207
+ 0,
3208
+ 0,
3209
+ 0,
3210
+ 1,
3211
+ 1,
3212
+ 2,
3213
+ 2,
3214
+ 3,
3215
+ 3,
3216
+ 4,
3217
+ 4,
3218
+ 5,
3219
+ 5,
3220
+ 6,
3221
+ 6,
3222
+ 7,
3223
+ 7,
3224
+ 8,
3225
+ 8,
3226
+ 9,
3227
+ 9,
3228
+ 10,
3229
+ 10,
3230
+ 11,
3231
+ 11,
3232
+ 12,
3233
+ 12,
3234
+ 13,
3235
+ 13,
3236
+ /* unused */
3237
+ 0,
3238
+ 0
3239
+ ]);
3126
3240
  var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
3127
3241
  var freb = function(eb, start) {
3128
3242
  var b = new u16(31);
@@ -3251,6 +3365,7 @@ var __exports__ = (() => {
3251
3365
  "filename too long",
3252
3366
  "stream finishing",
3253
3367
  "invalid zip data"
3368
+ // determined by unknown compression method
3254
3369
  ];
3255
3370
  var err = function(ind, msg, nt) {
3256
3371
  var e = new Error(msg || ec[ind]);
@@ -3452,10 +3567,10 @@ var __exports__ = (() => {
3452
3567
  } catch (e) {
3453
3568
  }
3454
3569
  var shift = (n, shift2) => {
3455
- return n * Math.pow(2, shift2);
3570
+ return n * __pow(2, shift2);
3456
3571
  };
3457
3572
  var unshift = (n, shift2) => {
3458
- return Math.floor(n / Math.pow(2, shift2));
3573
+ return Math.floor(n / __pow(2, shift2));
3459
3574
  };
3460
3575
  var getUint24 = (view, pos) => {
3461
3576
  return shift(view.getUint16(pos + 1, true), 8) + view.getUint8(pos);
@@ -3464,40 +3579,40 @@ var __exports__ = (() => {
3464
3579
  return shift(view.getUint32(pos + 2, true), 16) + view.getUint16(pos, true);
3465
3580
  };
3466
3581
  var compare = (tz, tx, ty, view, i3) => {
3467
- if (tz != view.getUint8(i3))
3582
+ if (tz !== view.getUint8(i3))
3468
3583
  return tz - view.getUint8(i3);
3469
3584
  const x3 = getUint24(view, i3 + 1);
3470
- if (tx != x3)
3585
+ if (tx !== x3)
3471
3586
  return tx - x3;
3472
3587
  const y2 = getUint24(view, i3 + 4);
3473
- if (ty != y2)
3588
+ if (ty !== y2)
3474
3589
  return ty - y2;
3475
3590
  return 0;
3476
3591
  };
3477
3592
  var queryLeafdir = (view, z, x3, y2) => {
3478
- const offset_len = queryView(view, z | 128, x3, y2);
3479
- if (offset_len) {
3593
+ const offsetLen = queryView(view, z | 128, x3, y2);
3594
+ if (offsetLen) {
3480
3595
  return {
3481
3596
  z,
3482
3597
  x: x3,
3483
3598
  y: y2,
3484
- offset: offset_len[0],
3485
- length: offset_len[1],
3486
- is_dir: true
3599
+ offset: offsetLen[0],
3600
+ length: offsetLen[1],
3601
+ isDir: true
3487
3602
  };
3488
3603
  }
3489
3604
  return null;
3490
3605
  };
3491
3606
  var queryTile = (view, z, x3, y2) => {
3492
- const offset_len = queryView(view, z, x3, y2);
3493
- if (offset_len) {
3607
+ const offsetLen = queryView(view, z, x3, y2);
3608
+ if (offsetLen) {
3494
3609
  return {
3495
3610
  z,
3496
3611
  x: x3,
3497
3612
  y: y2,
3498
- offset: offset_len[0],
3499
- length: offset_len[1],
3500
- is_dir: false
3613
+ offset: offsetLen[0],
3614
+ length: offsetLen[1],
3615
+ isDir: false
3501
3616
  };
3502
3617
  }
3503
3618
  return null;
@@ -3519,10 +3634,10 @@ var __exports__ = (() => {
3519
3634
  return null;
3520
3635
  };
3521
3636
  var entrySort = (a, b) => {
3522
- if (a.is_dir && !b.is_dir) {
3637
+ if (a.isDir && !b.isDir) {
3523
3638
  return 1;
3524
3639
  }
3525
- if (!a.is_dir && b.is_dir) {
3640
+ if (!a.isDir && b.isDir) {
3526
3641
  return -1;
3527
3642
  }
3528
3643
  if (a.z !== b.z) {
@@ -3534,15 +3649,15 @@ var __exports__ = (() => {
3534
3649
  return a.y - b.y;
3535
3650
  };
3536
3651
  var parseEntry = (dataview, i3) => {
3537
- const z_raw = dataview.getUint8(i3 * 17);
3538
- const z = z_raw & 127;
3652
+ const zRaw = dataview.getUint8(i3 * 17);
3653
+ const z = zRaw & 127;
3539
3654
  return {
3540
3655
  z,
3541
3656
  x: getUint24(dataview, i3 * 17 + 1),
3542
3657
  y: getUint24(dataview, i3 * 17 + 4),
3543
3658
  offset: getUint48(dataview, i3 * 17 + 7),
3544
3659
  length: dataview.getUint32(i3 * 17 + 13, true),
3545
- is_dir: z_raw >> 7 === 1
3660
+ isDir: zRaw >> 7 === 1
3546
3661
  };
3547
3662
  };
3548
3663
  var sortDir = (a) => {
@@ -3560,7 +3675,7 @@ var __exports__ = (() => {
3560
3675
  for (let i3 = 0; i3 < entries.length; i3++) {
3561
3676
  const entry = entries[i3];
3562
3677
  let z = entry.z;
3563
- if (entry.is_dir)
3678
+ if (entry.isDir)
3564
3679
  z = z | 128;
3565
3680
  arr[i3 * 17] = z;
3566
3681
  arr[i3 * 17 + 1] = entry.x & 255;
@@ -3587,12 +3702,12 @@ var __exports__ = (() => {
3587
3702
  return null;
3588
3703
  const numEntries = view.byteLength / 17;
3589
3704
  const entry = parseEntry(view, numEntries - 1);
3590
- if (entry.is_dir) {
3591
- const leaf_level = entry.z;
3592
- const level_diff = tile.z - leaf_level;
3593
- const leaf_x = Math.trunc(tile.x / (1 << level_diff));
3594
- const leaf_y = Math.trunc(tile.y / (1 << level_diff));
3595
- return { z: leaf_level, x: leaf_x, y: leaf_y };
3705
+ if (entry.isDir) {
3706
+ const leafLevel = entry.z;
3707
+ const levelDiff = tile.z - leafLevel;
3708
+ const leafX = Math.trunc(tile.x / (1 << levelDiff));
3709
+ const leafY = Math.trunc(tile.y / (1 << levelDiff));
3710
+ return { z: leafLevel, x: leafX, y: leafY };
3596
3711
  }
3597
3712
  return null;
3598
3713
  };
@@ -3600,50 +3715,50 @@ var __exports__ = (() => {
3600
3715
  return __async(this, null, function* () {
3601
3716
  const resp = yield source.getBytes(0, 512e3);
3602
3717
  const dataview = new DataView(resp.data);
3603
- const json_size = dataview.getUint32(4, true);
3604
- const root_entries = dataview.getUint16(8, true);
3718
+ const jsonSize = dataview.getUint32(4, true);
3719
+ const rootEntries = dataview.getUint16(8, true);
3605
3720
  const dec = new TextDecoder("utf-8");
3606
- const json_metadata = JSON.parse(
3607
- dec.decode(new DataView(resp.data, 10, json_size))
3721
+ const jsonMetadata = JSON.parse(
3722
+ dec.decode(new DataView(resp.data, 10, jsonSize))
3608
3723
  );
3609
- let tile_compression = 0;
3610
- if (json_metadata.compression === "gzip") {
3611
- tile_compression = 2;
3724
+ let tileCompression = 0;
3725
+ if (jsonMetadata.compression === "gzip") {
3726
+ tileCompression = 2;
3612
3727
  }
3613
3728
  let minzoom = 0;
3614
- if ("minzoom" in json_metadata) {
3615
- minzoom = +json_metadata.minzoom;
3729
+ if ("minzoom" in jsonMetadata) {
3730
+ minzoom = +jsonMetadata.minzoom;
3616
3731
  }
3617
3732
  let maxzoom = 0;
3618
- if ("maxzoom" in json_metadata) {
3619
- maxzoom = +json_metadata.maxzoom;
3733
+ if ("maxzoom" in jsonMetadata) {
3734
+ maxzoom = +jsonMetadata.maxzoom;
3620
3735
  }
3621
- let center_lon = 0;
3622
- let center_lat = 0;
3623
- let center_zoom = 0;
3624
- let min_lon = -180;
3625
- let min_lat = -85;
3626
- let max_lon = 180;
3627
- let max_lat = 85;
3628
- if (json_metadata.bounds) {
3629
- const split = json_metadata.bounds.split(",");
3630
- min_lon = +split[0];
3631
- min_lat = +split[1];
3632
- max_lon = +split[2];
3633
- max_lat = +split[3];
3736
+ let centerLon = 0;
3737
+ let centerLat = 0;
3738
+ let centerZoom = 0;
3739
+ let minLon = -180;
3740
+ let minLat = -85;
3741
+ let maxLon = 180;
3742
+ let maxLat = 85;
3743
+ if (jsonMetadata.bounds) {
3744
+ const split = jsonMetadata.bounds.split(",");
3745
+ minLon = +split[0];
3746
+ minLat = +split[1];
3747
+ maxLon = +split[2];
3748
+ maxLat = +split[3];
3634
3749
  }
3635
- if (json_metadata.center) {
3636
- const split = json_metadata.center.split(",");
3637
- center_lon = +split[0];
3638
- center_lat = +split[1];
3639
- center_zoom = +split[2];
3750
+ if (jsonMetadata.center) {
3751
+ const split = jsonMetadata.center.split(",");
3752
+ centerLon = +split[0];
3753
+ centerLat = +split[1];
3754
+ centerZoom = +split[2];
3640
3755
  }
3641
3756
  const header = {
3642
3757
  specVersion: dataview.getUint16(2, true),
3643
- rootDirectoryOffset: 10 + json_size,
3644
- rootDirectoryLength: root_entries * 17,
3758
+ rootDirectoryOffset: 10 + jsonSize,
3759
+ rootDirectoryLength: rootEntries * 17,
3645
3760
  jsonMetadataOffset: 10,
3646
- jsonMetadataLength: json_size,
3761
+ jsonMetadataLength: jsonSize,
3647
3762
  leafDirectoryOffset: 0,
3648
3763
  leafDirectoryLength: void 0,
3649
3764
  tileDataOffset: 0,
@@ -3653,17 +3768,17 @@ var __exports__ = (() => {
3653
3768
  numTileContents: 0,
3654
3769
  clustered: false,
3655
3770
  internalCompression: 1,
3656
- tileCompression: tile_compression,
3771
+ tileCompression,
3657
3772
  tileType: 1,
3658
3773
  minZoom: minzoom,
3659
3774
  maxZoom: maxzoom,
3660
- minLon: min_lon,
3661
- minLat: min_lat,
3662
- maxLon: max_lon,
3663
- maxLat: max_lat,
3664
- centerZoom: center_zoom,
3665
- centerLon: center_lon,
3666
- centerLat: center_lat,
3775
+ minLon,
3776
+ minLat,
3777
+ maxLon,
3778
+ maxLat,
3779
+ centerZoom,
3780
+ centerLon,
3781
+ centerLat,
3667
3782
  etag: resp.etag
3668
3783
  };
3669
3784
  return header;
@@ -3671,59 +3786,59 @@ var __exports__ = (() => {
3671
3786
  }
3672
3787
  function getZxy(header, source, cache, z, x3, y2, signal) {
3673
3788
  return __async(this, null, function* () {
3674
- let root_dir = yield cache.getArrayBuffer(
3789
+ let rootDir = yield cache.getArrayBuffer(
3675
3790
  source,
3676
3791
  header.rootDirectoryOffset,
3677
3792
  header.rootDirectoryLength,
3678
3793
  header
3679
3794
  );
3680
3795
  if (header.specVersion === 1) {
3681
- root_dir = sortDir(root_dir);
3796
+ rootDir = sortDir(rootDir);
3682
3797
  }
3683
- const entry = queryTile(new DataView(root_dir), z, x3, y2);
3798
+ const entry = queryTile(new DataView(rootDir), z, x3, y2);
3684
3799
  if (entry) {
3685
3800
  const resp = yield source.getBytes(entry.offset, entry.length, signal);
3686
- let tile_data = resp.data;
3687
- const view = new DataView(tile_data);
3688
- if (view.getUint8(0) == 31 && view.getUint8(1) == 139) {
3689
- tile_data = decompressSync(new Uint8Array(tile_data));
3801
+ let tileData = resp.data;
3802
+ const view = new DataView(tileData);
3803
+ if (view.getUint8(0) === 31 && view.getUint8(1) === 139) {
3804
+ tileData = decompressSync(new Uint8Array(tileData));
3690
3805
  }
3691
3806
  return {
3692
- data: tile_data
3807
+ data: tileData
3693
3808
  };
3694
3809
  }
3695
- const leafcoords = deriveLeaf(new DataView(root_dir), { z, x: x3, y: y2 });
3810
+ const leafcoords = deriveLeaf(new DataView(rootDir), { z, x: x3, y: y2 });
3696
3811
  if (leafcoords) {
3697
- const leafdir_entry = queryLeafdir(
3698
- new DataView(root_dir),
3812
+ const leafdirEntry = queryLeafdir(
3813
+ new DataView(rootDir),
3699
3814
  leafcoords.z,
3700
3815
  leafcoords.x,
3701
3816
  leafcoords.y
3702
3817
  );
3703
- if (leafdir_entry) {
3704
- let leaf_dir = yield cache.getArrayBuffer(
3818
+ if (leafdirEntry) {
3819
+ let leafDir = yield cache.getArrayBuffer(
3705
3820
  source,
3706
- leafdir_entry.offset,
3707
- leafdir_entry.length,
3821
+ leafdirEntry.offset,
3822
+ leafdirEntry.length,
3708
3823
  header
3709
3824
  );
3710
3825
  if (header.specVersion === 1) {
3711
- leaf_dir = sortDir(leaf_dir);
3826
+ leafDir = sortDir(leafDir);
3712
3827
  }
3713
- const tile_entry = queryTile(new DataView(leaf_dir), z, x3, y2);
3714
- if (tile_entry) {
3828
+ const tileEntry = queryTile(new DataView(leafDir), z, x3, y2);
3829
+ if (tileEntry) {
3715
3830
  const resp = yield source.getBytes(
3716
- tile_entry.offset,
3717
- tile_entry.length,
3831
+ tileEntry.offset,
3832
+ tileEntry.length,
3718
3833
  signal
3719
3834
  );
3720
- let tile_data = resp.data;
3721
- const view = new DataView(tile_data);
3722
- if (view.getUint8(0) == 31 && view.getUint8(1) == 139) {
3723
- tile_data = decompressSync(new Uint8Array(tile_data));
3835
+ let tileData = resp.data;
3836
+ const view = new DataView(tileData);
3837
+ if (view.getUint8(0) === 31 && view.getUint8(1) === 139) {
3838
+ tileData = decompressSync(new Uint8Array(tileData));
3724
3839
  }
3725
3840
  return {
3726
- data: tile_data
3841
+ data: tileData
3727
3842
  };
3728
3843
  }
3729
3844
  }
@@ -3739,7 +3854,7 @@ var __exports__ = (() => {
3739
3854
  let loaded = false;
3740
3855
  let mimeType = "";
3741
3856
  const cls = L.GridLayer.extend({
3742
- createTile: function(coord, done) {
3857
+ createTile: (coord, done) => {
3743
3858
  const el = document.createElement("img");
3744
3859
  const controller = new AbortController();
3745
3860
  const signal = controller.signal;
@@ -3748,17 +3863,17 @@ var __exports__ = (() => {
3748
3863
  };
3749
3864
  if (!loaded) {
3750
3865
  source.getHeader().then((header) => {
3751
- if (header.tileType == 1) {
3866
+ if (header.tileType === 1) {
3752
3867
  console.error(
3753
3868
  "Error: archive contains MVT vector tiles, but leafletRasterLayer is for displaying raster tiles. See https://github.com/protomaps/PMTiles/tree/main/js for details."
3754
3869
  );
3755
- } else if (header.tileType == 2) {
3870
+ } else if (header.tileType === 2) {
3756
3871
  mimeType = "image/png";
3757
- } else if (header.tileType == 3) {
3872
+ } else if (header.tileType === 3) {
3758
3873
  mimeType = "image/jpeg";
3759
- } else if (header.tileType == 4) {
3874
+ } else if (header.tileType === 4) {
3760
3875
  mimeType = "image/webp";
3761
- } else if (header.tileType == 5) {
3876
+ } else if (header.tileType === 5) {
3762
3877
  mimeType = "image/avif";
3763
3878
  }
3764
3879
  });
@@ -3769,8 +3884,8 @@ var __exports__ = (() => {
3769
3884
  const blob = new Blob([arr.data], { type: mimeType });
3770
3885
  const imageUrl = window.URL.createObjectURL(blob);
3771
3886
  el.src = imageUrl;
3772
- el.cancel = null;
3773
- done(null, el);
3887
+ el.cancel = void 0;
3888
+ done(void 0, el);
3774
3889
  }
3775
3890
  }).catch((e) => {
3776
3891
  if (e.name !== "AbortError") {
@@ -3799,82 +3914,77 @@ var __exports__ = (() => {
3799
3914
  });
3800
3915
  return new cls(options);
3801
3916
  };
3917
+ var v3compat = (v4) => (requestParameters, arg2) => {
3918
+ if (arg2 instanceof AbortController) {
3919
+ return v4(requestParameters, arg2);
3920
+ }
3921
+ const abortController = new AbortController();
3922
+ v4(requestParameters, abortController).then(
3923
+ (result) => {
3924
+ return arg2(
3925
+ void 0,
3926
+ result.data,
3927
+ result.cacheControl || "",
3928
+ result.expires || ""
3929
+ );
3930
+ },
3931
+ (err2) => {
3932
+ return arg2(err2);
3933
+ }
3934
+ ).catch((e) => {
3935
+ return arg2(e);
3936
+ });
3937
+ return { cancel: () => abortController.abort() };
3938
+ };
3802
3939
  var Protocol = class {
3803
3940
  constructor() {
3804
- this.tile = (params, callback) => {
3805
- if (params.type == "json") {
3806
- const pmtiles_url = params.url.substr(10);
3807
- let instance = this.tiles.get(pmtiles_url);
3808
- if (!instance) {
3809
- instance = new PMTiles(pmtiles_url);
3810
- this.tiles.set(pmtiles_url, instance);
3941
+ this.tilev4 = (params, abortController) => __async(this, null, function* () {
3942
+ if (params.type === "json") {
3943
+ const pmtilesUrl2 = params.url.substr(10);
3944
+ let instance2 = this.tiles.get(pmtilesUrl2);
3945
+ if (!instance2) {
3946
+ instance2 = new PMTiles(pmtilesUrl2);
3947
+ this.tiles.set(pmtilesUrl2, instance2);
3811
3948
  }
3812
- instance.getHeader().then((h) => {
3813
- const tilejson = {
3814
- tiles: [params.url + "/{z}/{x}/{y}"],
3949
+ const h = yield instance2.getHeader();
3950
+ return {
3951
+ data: {
3952
+ tiles: [`${params.url}/{z}/{x}/{y}`],
3815
3953
  minzoom: h.minZoom,
3816
3954
  maxzoom: h.maxZoom,
3817
3955
  bounds: [h.minLon, h.minLat, h.maxLon, h.maxLat]
3818
- };
3819
- callback(null, tilejson, null, null);
3820
- }).catch((e) => {
3821
- callback(e, null, null, null);
3822
- });
3823
- return {
3824
- cancel: () => {
3825
3956
  }
3826
3957
  };
3827
- } else {
3828
- const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
3829
- const result = params.url.match(re);
3830
- if (!result) {
3831
- throw new Error("Invalid PMTiles protocol URL");
3832
- return {
3833
- cancel: () => {
3834
- }
3835
- };
3836
- }
3837
- const pmtiles_url = result[1];
3838
- let instance = this.tiles.get(pmtiles_url);
3839
- if (!instance) {
3840
- instance = new PMTiles(pmtiles_url);
3841
- this.tiles.set(pmtiles_url, instance);
3842
- }
3843
- const z = result[2];
3844
- const x3 = result[3];
3845
- const y2 = result[4];
3846
- const controller = new AbortController();
3847
- const signal = controller.signal;
3848
- let cancel = () => {
3849
- controller.abort();
3850
- };
3851
- instance.getHeader().then((header) => {
3852
- instance.getZxy(+z, +x3, +y2, signal).then((resp) => {
3853
- if (resp) {
3854
- callback(
3855
- null,
3856
- new Uint8Array(resp.data),
3857
- resp.cacheControl,
3858
- resp.expires
3859
- );
3860
- } else {
3861
- if (header.tileType == 1) {
3862
- callback(null, new Uint8Array(), null, null);
3863
- } else {
3864
- callback(null, null, null, null);
3865
- }
3866
- }
3867
- }).catch((e) => {
3868
- if (e.name !== "AbortError") {
3869
- callback(e, null, null, null);
3870
- }
3871
- });
3872
- });
3958
+ }
3959
+ const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
3960
+ const result = params.url.match(re);
3961
+ if (!result) {
3962
+ throw new Error("Invalid PMTiles protocol URL");
3963
+ }
3964
+ const pmtilesUrl = result[1];
3965
+ let instance = this.tiles.get(pmtilesUrl);
3966
+ if (!instance) {
3967
+ instance = new PMTiles(pmtilesUrl);
3968
+ this.tiles.set(pmtilesUrl, instance);
3969
+ }
3970
+ const z = result[2];
3971
+ const x3 = result[3];
3972
+ const y2 = result[4];
3973
+ const header = yield instance.getHeader();
3974
+ const resp = yield instance == null ? void 0 : instance.getZxy(+z, +x3, +y2, abortController.signal);
3975
+ if (resp) {
3873
3976
  return {
3874
- cancel
3977
+ data: new Uint8Array(resp.data),
3978
+ cacheControl: resp.cacheControl,
3979
+ expires: resp.expires
3875
3980
  };
3876
3981
  }
3877
- };
3982
+ if (header.tileType === 1) {
3983
+ return { data: new Uint8Array() };
3984
+ }
3985
+ return { data: null };
3986
+ });
3987
+ this.tile = v3compat(this.tilev4);
3878
3988
  this.tiles = /* @__PURE__ */ new Map();
3879
3989
  }
3880
3990
  add(p) {
@@ -3889,9 +3999,8 @@ var __exports__ = (() => {
3889
3999
  }
3890
4000
  function readVarintRemainder(l, p) {
3891
4001
  const buf = p.buf;
3892
- let h, b;
3893
- b = buf[p.pos++];
3894
- h = (b & 112) >> 4;
4002
+ let b = buf[p.pos++];
4003
+ let h = (b & 112) >> 4;
3895
4004
  if (b < 128)
3896
4005
  return toNum(l, h);
3897
4006
  b = buf[p.pos++];
@@ -3918,9 +4027,8 @@ var __exports__ = (() => {
3918
4027
  }
3919
4028
  function readVarint(p) {
3920
4029
  const buf = p.buf;
3921
- let val, b;
3922
- b = buf[p.pos++];
3923
- val = b & 127;
4030
+ let b = buf[p.pos++];
4031
+ let val = b & 127;
3924
4032
  if (b < 128)
3925
4033
  return val;
3926
4034
  b = buf[p.pos++];
@@ -3940,8 +4048,8 @@ var __exports__ = (() => {
3940
4048
  return readVarintRemainder(val, p);
3941
4049
  }
3942
4050
  function rotate(n, xy, rx, ry) {
3943
- if (ry == 0) {
3944
- if (rx == 1) {
4051
+ if (ry === 0) {
4052
+ if (rx === 1) {
3945
4053
  xy[0] = n - 1 - xy[0];
3946
4054
  xy[1] = n - 1 - xy[1];
3947
4055
  }
@@ -3951,7 +4059,7 @@ var __exports__ = (() => {
3951
4059
  }
3952
4060
  }
3953
4061
  function idOnLevel(z, pos) {
3954
- const n = Math.pow(2, z);
4062
+ const n = __pow(2, z);
3955
4063
  let rx = pos;
3956
4064
  let ry = pos;
3957
4065
  let t = pos;
@@ -4001,11 +4109,11 @@ var __exports__ = (() => {
4001
4109
  if (z > 26) {
4002
4110
  throw Error("Tile zoom level exceeds max safe number limit (26)");
4003
4111
  }
4004
- if (x3 > Math.pow(2, z) - 1 || y2 > Math.pow(2, z) - 1) {
4112
+ if (x3 > __pow(2, z) - 1 || y2 > __pow(2, z) - 1) {
4005
4113
  throw Error("tile x/y outside zoom level bounds");
4006
4114
  }
4007
4115
  const acc = tzValues[z];
4008
- const n = Math.pow(2, z);
4116
+ const n = __pow(2, z);
4009
4117
  let rx = 0;
4010
4118
  let ry = 0;
4011
4119
  let d = 0;
@@ -4022,13 +4130,13 @@ var __exports__ = (() => {
4022
4130
  }
4023
4131
  function tileIdToZxy(i3) {
4024
4132
  let acc = 0;
4025
- let z = 0;
4133
+ const z = 0;
4026
4134
  for (let z2 = 0; z2 < 27; z2++) {
4027
- const num_tiles = (1 << z2) * (1 << z2);
4028
- if (acc + num_tiles > i3) {
4135
+ const numTiles = (1 << z2) * (1 << z2);
4136
+ if (acc + numTiles > i3) {
4029
4137
  return idOnLevel(z2, i3 - acc);
4030
4138
  }
4031
- acc += num_tiles;
4139
+ acc += numTiles;
4032
4140
  }
4033
4141
  throw Error("Tile zoom level exceeds max safe number limit (26)");
4034
4142
  }
@@ -4044,19 +4152,22 @@ var __exports__ = (() => {
4044
4152
  return __async(this, null, function* () {
4045
4153
  if (compression === 1 || compression === 0) {
4046
4154
  return buf;
4047
- } else if (compression === 2) {
4048
- if (typeof globalThis.DecompressionStream == "undefined") {
4155
+ }
4156
+ if (compression === 2) {
4157
+ if (typeof globalThis.DecompressionStream === "undefined") {
4049
4158
  return decompressSync(new Uint8Array(buf));
4050
- } else {
4051
- let stream = new Response(buf).body;
4052
- let result = stream.pipeThrough(
4053
- new globalThis.DecompressionStream("gzip")
4054
- );
4055
- return new Response(result).arrayBuffer();
4056
4159
  }
4057
- } else {
4058
- throw Error("Compression method not supported");
4160
+ const stream = new Response(buf).body;
4161
+ if (!stream) {
4162
+ throw Error("Failed to read response stream");
4163
+ }
4164
+ const result = stream.pipeThrough(
4165
+ // biome-ignore lint: needed to detect DecompressionStream in browser+node+cloudflare workers
4166
+ new globalThis.DecompressionStream("gzip")
4167
+ );
4168
+ return new Response(result).arrayBuffer();
4059
4169
  }
4170
+ throw Error("Compression method not supported");
4060
4171
  });
4061
4172
  }
4062
4173
  var TileType = /* @__PURE__ */ ((TileType22) => {
@@ -4093,7 +4204,7 @@ var __exports__ = (() => {
4093
4204
  }
4094
4205
  return null;
4095
4206
  }
4096
- var FileAPISource = class {
4207
+ var FileSource = class {
4097
4208
  constructor(file) {
4098
4209
  this.file = file;
4099
4210
  }
@@ -4109,39 +4220,65 @@ var __exports__ = (() => {
4109
4220
  }
4110
4221
  };
4111
4222
  var FetchSource = class {
4112
- constructor(url) {
4223
+ constructor(url, customHeaders = new Headers()) {
4113
4224
  this.url = url;
4225
+ this.customHeaders = customHeaders;
4226
+ this.mustReload = false;
4114
4227
  }
4115
4228
  getKey() {
4116
4229
  return this.url;
4117
4230
  }
4118
- getBytes(offset, length2, signal) {
4231
+ setHeaders(customHeaders) {
4232
+ this.customHeaders = customHeaders;
4233
+ }
4234
+ getBytes(offset, length2, passedSignal, etag) {
4119
4235
  return __async(this, null, function* () {
4120
4236
  let controller;
4121
- if (!signal) {
4237
+ let signal;
4238
+ if (passedSignal) {
4239
+ signal = passedSignal;
4240
+ } else {
4122
4241
  controller = new AbortController();
4123
4242
  signal = controller.signal;
4124
4243
  }
4244
+ const requestHeaders = new Headers(this.customHeaders);
4245
+ requestHeaders.set("range", `bytes=${offset}-${offset + length2 - 1}`);
4246
+ let cache;
4247
+ if (this.mustReload) {
4248
+ cache = "reload";
4249
+ }
4125
4250
  let resp = yield fetch(this.url, {
4126
4251
  signal,
4127
- headers: { Range: "bytes=" + offset + "-" + (offset + length2 - 1) }
4252
+ cache,
4253
+ headers: requestHeaders
4254
+ //biome-ignore lint: "cache" is incompatible between cloudflare workers and browser
4128
4255
  });
4129
- if (resp.status === 416 && offset === 0) {
4130
- const content_range = resp.headers.get("Content-Range");
4131
- if (!content_range || !content_range.startsWith("bytes */")) {
4256
+ if (offset === 0 && resp.status === 416) {
4257
+ const contentRange = resp.headers.get("Content-Range");
4258
+ if (!contentRange || !contentRange.startsWith("bytes */")) {
4132
4259
  throw Error("Missing content-length on 416 response");
4133
4260
  }
4134
- const actual_length = +content_range.substr(8);
4261
+ const actualLength = +contentRange.substr(8);
4135
4262
  resp = yield fetch(this.url, {
4136
4263
  signal,
4137
- headers: { Range: "bytes=0-" + (actual_length - 1) }
4264
+ cache: "reload",
4265
+ headers: { range: `bytes=0-${actualLength - 1}` }
4266
+ //biome-ignore lint: "cache" is incompatible between cloudflare workers and browser
4138
4267
  });
4139
4268
  }
4269
+ let newEtag = resp.headers.get("Etag");
4270
+ if (newEtag == null ? void 0 : newEtag.startsWith("W/")) {
4271
+ newEtag = null;
4272
+ }
4273
+ if (resp.status === 416 || etag && newEtag && newEtag !== etag) {
4274
+ this.mustReload = true;
4275
+ throw new EtagMismatch(etag);
4276
+ }
4140
4277
  if (resp.status >= 300) {
4141
- throw Error("Bad response code: " + resp.status);
4278
+ throw Error(`Bad response code: ${resp.status}`);
4142
4279
  }
4143
- const content_length = resp.headers.get("Content-Length");
4144
- if (resp.status === 200 && (!content_length || +content_length > length2)) {
4280
+ const contentLength = resp.headers.get("Content-Length");
4281
+ if (resp.status === 200 && (!contentLength || +contentLength > length2)) {
4145
4282
  if (controller)
4146
4283
  controller.abort();
4147
4284
  throw Error(
@@ -4151,7 +4288,7 @@ var __exports__ = (() => {
4151
4288
  const a = yield resp.arrayBuffer();
4152
4289
  return {
4153
4290
  data: a,
4154
- etag: resp.headers.get("ETag") || void 0,
4291
+ etag: newEtag || void 0,
4155
4292
  cacheControl: resp.headers.get("Cache-Control") || void 0,
4156
4293
  expires: resp.headers.get("Expires") || void 0
4157
4294
  };
@@ -4161,18 +4298,18 @@ var __exports__ = (() => {
4161
4298
  function getUint64(v, offset) {
4162
4299
  const wh = v.getUint32(offset + 4, true);
4163
4300
  const wl = v.getUint32(offset + 0, true);
4164
- return wh * Math.pow(2, 32) + wl;
4301
+ return wh * __pow(2, 32) + wl;
4165
4302
  }
4166
4303
  function bytesToHeader(bytes, etag) {
4167
4304
  const v = new DataView(bytes);
4168
- const spec_version = v.getUint8(7);
4169
- if (spec_version > 3) {
4305
+ const specVersion = v.getUint8(7);
4306
+ if (specVersion > 3) {
4170
4307
  throw Error(
4171
- `Archive is spec version ${spec_version} but this library supports up to spec version 3`
4308
+ `Archive is spec version ${specVersion} but this library supports up to spec version 3`
4172
4309
  );
4173
4310
  }
4174
4311
  return {
4175
- specVersion: spec_version,
4312
+ specVersion,
4176
4313
  rootDirectoryOffset: getUint64(v, 8),
4177
4314
  rootDirectoryLength: getUint64(v, 16),
4178
4315
  jsonMetadataOffset: getUint64(v, 24),
@@ -4233,7 +4370,8 @@ var __exports__ = (() => {
4233
4370
  "PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"
4234
4371
  );
4235
4372
  return 2;
4236
- } else if (v.getUint16(2, true) === 1) {
4373
+ }
4374
+ if (v.getUint16(2, true) === 1) {
4237
4375
  console.warn(
4238
4376
  "PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"
4239
4377
  );
@@ -4243,7 +4381,7 @@ var __exports__ = (() => {
4243
4381
  }
4244
4382
  var EtagMismatch = class extends Error {
4245
4383
  };
4246
- function getHeaderAndRoot(source, decompress, prefetch, current_etag) {
4384
+ function getHeaderAndRoot(source, decompress) {
4247
4385
  return __async(this, null, function* () {
4248
4386
  const resp = yield source.getBytes(0, 16384);
4249
4387
  const v = new DataView(resp.data);
@@ -4254,34 +4392,21 @@ var __exports__ = (() => {
4254
4392
  return [yield v2_default.getHeader(source)];
4255
4393
  }
4256
4394
  const headerData = resp.data.slice(0, HEADER_SIZE_BYTES);
4257
- let resp_etag = resp.etag;
4258
- if (current_etag && resp.etag != current_etag) {
4259
- console.warn(
4260
- "ETag conflict detected; your HTTP server might not support content-based ETag headers. ETags disabled for " + source.getKey()
4261
- );
4262
- resp_etag = void 0;
4263
- }
4264
- const header = bytesToHeader(headerData, resp_etag);
4265
- if (prefetch) {
4266
- const rootDirData = resp.data.slice(
4267
- header.rootDirectoryOffset,
4268
- header.rootDirectoryOffset + header.rootDirectoryLength
4269
- );
4270
- const dirKey = source.getKey() + "|" + (header.etag || "") + "|" + header.rootDirectoryOffset + "|" + header.rootDirectoryLength;
4271
- const rootDir = deserializeIndex(
4272
- yield decompress(rootDirData, header.internalCompression)
4273
- );
4274
- return [header, [dirKey, rootDir.length, rootDir]];
4275
- }
4276
- return [header, void 0];
4395
+ const header = bytesToHeader(headerData, resp.etag);
4396
+ const rootDirData = resp.data.slice(
4397
+ header.rootDirectoryOffset,
4398
+ header.rootDirectoryOffset + header.rootDirectoryLength
4399
+ );
4400
+ const dirKey = `${source.getKey()}|${header.etag || ""}|${header.rootDirectoryOffset}|${header.rootDirectoryLength}`;
4401
+ const rootDir = deserializeIndex(
4402
+ yield decompress(rootDirData, header.internalCompression)
4403
+ );
4404
+ return [header, [dirKey, rootDir.length, rootDir]];
4277
4405
  });
4278
4406
  }
4279
4407
  function getDirectory(source, decompress, offset, length2, header) {
4280
4408
  return __async(this, null, function* () {
4281
- const resp = yield source.getBytes(offset, length2);
4282
- if (header.etag && header.etag !== resp.etag) {
4283
- throw new EtagMismatch(resp.etag);
4284
- }
4409
+ const resp = yield source.getBytes(offset, length2, void 0, header.etag);
4285
4410
  const data = yield decompress(resp.data, header.internalCompression);
4286
4411
  const directory = deserializeIndex(data);
4287
4412
  if (directory.length === 0) {
@@ -4295,23 +4420,18 @@ var __exports__ = (() => {
4295
4420
  this.cache = /* @__PURE__ */ new Map();
4296
4421
  this.maxCacheEntries = maxCacheEntries;
4297
4422
  this.counter = 1;
4298
- this.prefetch = prefetch;
4299
4423
  this.decompress = decompress;
4300
4424
  }
4301
- getHeader(source, current_etag) {
4425
+ getHeader(source) {
4302
4426
  return __async(this, null, function* () {
4303
4427
  const cacheKey = source.getKey();
4304
- if (this.cache.has(cacheKey)) {
4305
- this.cache.get(cacheKey).lastUsed = this.counter++;
4306
- const data = this.cache.get(cacheKey).data;
4428
+ const cacheValue = this.cache.get(cacheKey);
4429
+ if (cacheValue) {
4430
+ cacheValue.lastUsed = this.counter++;
4431
+ const data = cacheValue.data;
4307
4432
  return data;
4308
4433
  }
4309
- const res = yield getHeaderAndRoot(
4310
- source,
4311
- this.decompress,
4312
- this.prefetch,
4313
- current_etag
4314
- );
4434
+ const res = yield getHeaderAndRoot(source, this.decompress);
4315
4435
  if (res[1]) {
4316
4436
  this.cache.set(res[1][0], {
4317
4437
  lastUsed: this.counter++,
@@ -4328,10 +4448,11 @@ var __exports__ = (() => {
4328
4448
  }
4329
4449
  getDirectory(source, offset, length2, header) {
4330
4450
  return __async(this, null, function* () {
4331
- const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
4332
- if (this.cache.has(cacheKey)) {
4333
- this.cache.get(cacheKey).lastUsed = this.counter++;
4334
- const data = this.cache.get(cacheKey).data;
4451
+ const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
4452
+ const cacheValue = this.cache.get(cacheKey);
4453
+ if (cacheValue) {
4454
+ cacheValue.lastUsed = this.counter++;
4455
+ const data = cacheValue.data;
4335
4456
  return data;
4336
4457
  }
4337
4458
  const directory = yield getDirectory(
@@ -4349,18 +4470,17 @@ var __exports__ = (() => {
4349
4470
  return directory;
4350
4471
  });
4351
4472
  }
4473
+ // for v2 backwards compatibility
4352
4474
  getArrayBuffer(source, offset, length2, header) {
4353
4475
  return __async(this, null, function* () {
4354
- const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
4355
- if (this.cache.has(cacheKey)) {
4356
- this.cache.get(cacheKey).lastUsed = this.counter++;
4357
- const data = yield this.cache.get(cacheKey).data;
4476
+ const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
4477
+ const cacheValue = this.cache.get(cacheKey);
4478
+ if (cacheValue) {
4479
+ cacheValue.lastUsed = this.counter++;
4480
+ const data = yield cacheValue.data;
4358
4481
  return data;
4359
4482
  }
4360
- const resp = yield source.getBytes(offset, length2);
4361
- if (header.etag && header.etag !== resp.etag) {
4362
- throw new EtagMismatch(header.etag);
4363
- }
4483
+ const resp = yield source.getBytes(offset, length2, void 0, header.etag);
4364
4484
  this.cache.set(cacheKey, {
4365
4485
  lastUsed: this.counter++,
4366
4486
  data: resp.data
@@ -4373,9 +4493,9 @@ var __exports__ = (() => {
4373
4493
  if (this.cache.size > this.maxCacheEntries) {
4374
4494
  let minUsed = Infinity;
4375
4495
  let minKey = void 0;
4376
- this.cache.forEach((cache_value, key) => {
4377
- if (cache_value.lastUsed < minUsed) {
4378
- minUsed = cache_value.lastUsed;
4496
+ this.cache.forEach((cacheValue, key) => {
4497
+ if (cacheValue.lastUsed < minUsed) {
4498
+ minUsed = cacheValue.lastUsed;
4379
4499
  minKey = key;
4380
4500
  }
4381
4501
  });
@@ -4384,31 +4504,31 @@ var __exports__ = (() => {
4384
4504
  }
4385
4505
  }
4386
4506
  }
4387
- invalidate(source, current_etag) {
4507
+ invalidate(source) {
4388
4508
  return __async(this, null, function* () {
4389
4509
  this.cache.delete(source.getKey());
4390
- yield this.getHeader(source, current_etag);
4391
4510
  });
4392
4511
  }
4393
4512
  };
4394
4513
  var SharedPromiseCache = class {
4395
4514
  constructor(maxCacheEntries = 100, prefetch = true, decompress = defaultDecompress) {
4396
4515
  this.cache = /* @__PURE__ */ new Map();
4516
+ this.invalidations = /* @__PURE__ */ new Map();
4397
4517
  this.maxCacheEntries = maxCacheEntries;
4398
4518
  this.counter = 1;
4399
- this.prefetch = prefetch;
4400
4519
  this.decompress = decompress;
4401
4520
  }
4402
- getHeader(source, current_etag) {
4521
+ getHeader(source) {
4403
4522
  return __async(this, null, function* () {
4404
4523
  const cacheKey = source.getKey();
4405
- if (this.cache.has(cacheKey)) {
4406
- this.cache.get(cacheKey).lastUsed = this.counter++;
4407
- const data = yield this.cache.get(cacheKey).data;
4524
+ const cacheValue = this.cache.get(cacheKey);
4525
+ if (cacheValue) {
4526
+ cacheValue.lastUsed = this.counter++;
4527
+ const data = yield cacheValue.data;
4408
4528
  return data;
4409
4529
  }
4410
4530
  const p = new Promise((resolve, reject) => {
4411
- getHeaderAndRoot(source, this.decompress, this.prefetch, current_etag).then((res) => {
4531
+ getHeaderAndRoot(source, this.decompress).then((res) => {
4412
4532
  if (res[1]) {
4413
4533
  this.cache.set(res[1][0], {
4414
4534
  lastUsed: this.counter++,
@@ -4427,10 +4547,11 @@ var __exports__ = (() => {
4427
4547
  }
4428
4548
  getDirectory(source, offset, length2, header) {
4429
4549
  return __async(this, null, function* () {
4430
- const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
4431
- if (this.cache.has(cacheKey)) {
4432
- this.cache.get(cacheKey).lastUsed = this.counter++;
4433
- const data = yield this.cache.get(cacheKey).data;
4550
+ const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
4551
+ const cacheValue = this.cache.get(cacheKey);
4552
+ if (cacheValue) {
4553
+ cacheValue.lastUsed = this.counter++;
4554
+ const data = yield cacheValue.data;
4434
4555
  return data;
4435
4556
  }
4436
4557
  const p = new Promise((resolve, reject) => {
@@ -4445,19 +4566,18 @@ var __exports__ = (() => {
4445
4566
  return p;
4446
4567
  });
4447
4568
  }
4569
+ // for v2 backwards compatibility
4448
4570
  getArrayBuffer(source, offset, length2, header) {
4449
4571
  return __async(this, null, function* () {
4450
- const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
4451
- if (this.cache.has(cacheKey)) {
4452
- this.cache.get(cacheKey).lastUsed = this.counter++;
4453
- const data = yield this.cache.get(cacheKey).data;
4572
+ const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
4573
+ const cacheValue = this.cache.get(cacheKey);
4574
+ if (cacheValue) {
4575
+ cacheValue.lastUsed = this.counter++;
4576
+ const data = yield cacheValue.data;
4454
4577
  return data;
4455
4578
  }
4456
4579
  const p = new Promise((resolve, reject) => {
4457
- source.getBytes(offset, length2).then((resp) => {
4458
- if (header.etag && header.etag !== resp.etag) {
4459
- throw new EtagMismatch(resp.etag);
4460
- }
4580
+ source.getBytes(offset, length2, void 0, header.etag).then((resp) => {
4461
4581
  resolve(resp.data);
4462
4582
  if (this.cache.has(cacheKey)) {
4463
4583
  }
@@ -4474,23 +4594,33 @@ var __exports__ = (() => {
4474
4594
  if (this.cache.size >= this.maxCacheEntries) {
4475
4595
  let minUsed = Infinity;
4476
4596
  let minKey = void 0;
4477
- this.cache.forEach(
4478
- (cache_value, key) => {
4479
- if (cache_value.lastUsed < minUsed) {
4480
- minUsed = cache_value.lastUsed;
4481
- minKey = key;
4482
- }
4597
+ this.cache.forEach((cacheValue, key) => {
4598
+ if (cacheValue.lastUsed < minUsed) {
4599
+ minUsed = cacheValue.lastUsed;
4600
+ minKey = key;
4483
4601
  }
4484
- );
4602
+ });
4485
4603
  if (minKey) {
4486
4604
  this.cache.delete(minKey);
4487
4605
  }
4488
4606
  }
4489
4607
  }
4490
- invalidate(source, current_etag) {
4608
+ invalidate(source) {
4491
4609
  return __async(this, null, function* () {
4610
+ const key = source.getKey();
4611
+ if (this.invalidations.get(key)) {
4612
+ return yield this.invalidations.get(key);
4613
+ }
4492
4614
  this.cache.delete(source.getKey());
4493
- yield this.getHeader(source, current_etag);
4615
+ const p = new Promise((resolve, reject) => {
4616
+ this.getHeader(source).then((h) => {
4617
+ resolve();
4618
+ this.invalidations.delete(key);
4619
+ }).catch((e) => {
4620
+ reject(e);
4621
+ });
4622
+ });
4623
+ this.invalidations.set(key, p);
4494
4624
  });
4495
4625
  }
4496
4626
  };
@@ -4512,14 +4642,19 @@ var __exports__ = (() => {
4512
4642
  this.cache = new SharedPromiseCache();
4513
4643
  }
4514
4644
  }
4645
+ /**
4646
+ * Return the header of the archive,
4647
+ * including information such as tile type, min/max zoom, bounds, and summary statistics.
4648
+ */
4515
4649
  getHeader() {
4516
4650
  return __async(this, null, function* () {
4517
4651
  return yield this.cache.getHeader(this.source);
4518
4652
  });
4519
4653
  }
4654
+ /** @hidden */
4520
4655
  getZxyAttempt(z, x3, y2, signal) {
4521
4656
  return __async(this, null, function* () {
4522
- const tile_id = zxyToTileId(z, x3, y2);
4657
+ const tileId = zxyToTileId(z, x3, y2);
4523
4658
  const header = yield this.cache.getHeader(this.source);
4524
4659
  if (header.specVersion < 3) {
4525
4660
  return v2_default.getZxy(header, this.source, this.cache, z, x3, y2, signal);
@@ -4527,35 +4662,32 @@ var __exports__ = (() => {
4527
4662
  if (z < header.minZoom || z > header.maxZoom) {
4528
4663
  return void 0;
4529
4664
  }
4530
- let d_o = header.rootDirectoryOffset;
4531
- let d_l = header.rootDirectoryLength;
4665
+ let dO = header.rootDirectoryOffset;
4666
+ let dL = header.rootDirectoryLength;
4532
4667
  for (let depth = 0; depth <= 3; depth++) {
4533
4668
  const directory = yield this.cache.getDirectory(
4534
4669
  this.source,
4535
- d_o,
4536
- d_l,
4670
+ dO,
4671
+ dL,
4537
4672
  header
4538
4673
  );
4539
- const entry = findTile(directory, tile_id);
4674
+ const entry = findTile(directory, tileId);
4540
4675
  if (entry) {
4541
4676
  if (entry.runLength > 0) {
4542
4677
  const resp = yield this.source.getBytes(
4543
4678
  header.tileDataOffset + entry.offset,
4544
4679
  entry.length,
4545
- signal
4680
+ signal,
4681
+ header.etag
4546
4682
  );
4547
- if (header.etag && header.etag !== resp.etag) {
4548
- throw new EtagMismatch(resp.etag);
4549
- }
4550
4683
  return {
4551
4684
  data: yield this.decompress(resp.data, header.tileCompression),
4552
4685
  cacheControl: resp.cacheControl,
4553
4686
  expires: resp.expires
4554
4687
  };
4555
- } else {
4556
- d_o = header.leafDirectoryOffset + entry.offset;
4557
- d_l = entry.length;
4558
4688
  }
4689
+ dO = header.leafDirectoryOffset + entry.offset;
4690
+ dL = entry.length;
4559
4691
  } else {
4560
4692
  return void 0;
4561
4693
  }
@@ -4563,30 +4695,34 @@ var __exports__ = (() => {
4563
4695
  throw Error("Maximum directory depth exceeded");
4564
4696
  });
4565
4697
  }
4698
+ /**
4699
+ * Primary method to get a single tile bytes from an archive.
4700
+ *
4701
+ * Returns undefined if the tile does not exist in the archive.
4702
+ */
4566
4703
  getZxy(z, x3, y2, signal) {
4567
4704
  return __async(this, null, function* () {
4568
4705
  try {
4569
4706
  return yield this.getZxyAttempt(z, x3, y2, signal);
4570
4707
  } catch (e) {
4571
4708
  if (e instanceof EtagMismatch) {
4572
- this.cache.invalidate(this.source, e.message);
4709
+ this.cache.invalidate(this.source);
4573
4710
  return yield this.getZxyAttempt(z, x3, y2, signal);
4574
- } else {
4575
- throw e;
4576
4711
  }
4712
+ throw e;
4577
4713
  }
4578
4714
  });
4579
4715
  }
4716
+ /** @hidden */
4580
4717
  getMetadataAttempt() {
4581
4718
  return __async(this, null, function* () {
4582
4719
  const header = yield this.cache.getHeader(this.source);
4583
4720
  const resp = yield this.source.getBytes(
4584
4721
  header.jsonMetadataOffset,
4585
- header.jsonMetadataLength
4722
+ header.jsonMetadataLength,
4723
+ void 0,
4724
+ header.etag
4586
4725
  );
4587
- if (header.etag && header.etag !== resp.etag) {
4588
- throw new EtagMismatch(resp.etag);
4589
- }
4590
4726
  const decompressed = yield this.decompress(
4591
4727
  resp.data,
4592
4728
  header.internalCompression
@@ -4595,27 +4731,28 @@ var __exports__ = (() => {
4595
4731
  return JSON.parse(dec.decode(decompressed));
4596
4732
  });
4597
4733
  }
4734
+ /**
4735
+ * Return the arbitrary JSON metadata of the archive.
4736
+ */
4598
4737
  getMetadata() {
4599
4738
  return __async(this, null, function* () {
4600
4739
  try {
4601
4740
  return yield this.getMetadataAttempt();
4602
4741
  } catch (e) {
4603
4742
  if (e instanceof EtagMismatch) {
4604
- this.cache.invalidate(this.source, e.message);
4743
+ this.cache.invalidate(this.source);
4605
4744
  return yield this.getMetadataAttempt();
4606
- } else {
4607
- throw e;
4608
4745
  }
4746
+ throw e;
4609
4747
  }
4610
4748
  });
4611
4749
  }
4612
4750
  };
4613
4751
 
4614
4752
  // src/lib/parse-pmtiles.ts
4615
- var {
4616
- TileType: TileType2
4617
- } = dist_exports;
4618
- function parsePMTilesHeader(header, pmtilesMetadata, options, loadOptions) {
4753
+ var { TileType: TileType2 } = dist_exports;
4754
+ function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {
4755
+ const pmtilesMetadata = pmmetadata;
4619
4756
  let tilejson = null;
4620
4757
  if (pmtilesMetadata) {
4621
4758
  try {
@@ -4640,7 +4777,10 @@ var __exports__ = (() => {
4640
4777
  tileMIMEType: decodeTileType(header.tileType),
4641
4778
  minZoom: header.minZoom,
4642
4779
  maxZoom: header.maxZoom,
4643
- boundingBox: [[header.minLon, header.minLat], [header.maxLon, header.maxLat]],
4780
+ boundingBox: [
4781
+ [header.minLon, header.minLat],
4782
+ [header.maxLon, header.maxLat]
4783
+ ],
4644
4784
  center: [header.centerLon, header.centerLat],
4645
4785
  centerZoom: header.centerZoom,
4646
4786
  etag: header.etag
@@ -4673,10 +4813,13 @@ var __exports__ = (() => {
4673
4813
 
4674
4814
  // src/lib/blob-source.ts
4675
4815
  var BlobSource = class {
4816
+ blob;
4817
+ key;
4676
4818
  constructor(blob, key) {
4677
4819
  this.blob = blob;
4678
4820
  this.key = key;
4679
4821
  }
4822
+ // TODO - how is this used?
4680
4823
  getKey() {
4681
4824
  return this.blob.url || "";
4682
4825
  }
@@ -4685,16 +4828,21 @@ var __exports__ = (() => {
4685
4828
  const data = await slice.arrayBuffer();
4686
4829
  return {
4687
4830
  data
4831
+ // etag: response.headers.get('ETag') || undefined,
4832
+ // cacheControl: response.headers.get('Cache-Control') || undefined,
4833
+ // expires: response.headers.get('Expires') || undefined
4688
4834
  };
4689
4835
  }
4690
4836
  };
4691
4837
 
4692
4838
  // src/pmtiles-source.ts
4693
- var {
4694
- PMTiles: PMTiles2
4695
- } = dist_exports;
4839
+ var { PMTiles: PMTiles2 } = dist_exports;
4696
4840
  var PMTilesSource = class extends DataSource {
4841
+ data;
4842
+ props;
4697
4843
  mimeType = null;
4844
+ pmtiles;
4845
+ metadata;
4698
4846
  constructor(props) {
4699
4847
  super(props);
4700
4848
  this.props = props;
@@ -4707,9 +4855,12 @@ var __exports__ = (() => {
4707
4855
  async getMetadata() {
4708
4856
  const pmtilesHeader = await this.pmtiles.getHeader();
4709
4857
  const pmtilesMetadata = await this.pmtiles.getMetadata();
4710
- const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, {
4711
- includeFormatHeader: false
4712
- }, this.loadOptions);
4858
+ const metadata = parsePMTilesHeader(
4859
+ pmtilesHeader,
4860
+ pmtilesMetadata,
4861
+ { includeFormatHeader: false },
4862
+ this.loadOptions
4863
+ );
4713
4864
  if (this.props.attributions) {
4714
4865
  metadata.attributions = [...this.props.attributions, ...metadata.attributions || []];
4715
4866
  }
@@ -4719,11 +4870,7 @@ var __exports__ = (() => {
4719
4870
  return metadata;
4720
4871
  }
4721
4872
  async getTile(tileParams) {
4722
- const {
4723
- x: x3,
4724
- y: y2,
4725
- zoom: z
4726
- } = tileParams;
4873
+ const { x: x3, y: y2, zoom: z } = tileParams;
4727
4874
  const rangeResponse = await this.pmtiles.getZxy(z, x3, y2);
4728
4875
  const arrayBuffer = rangeResponse?.data;
4729
4876
  if (!arrayBuffer) {
@@ -4731,45 +4878,31 @@ var __exports__ = (() => {
4731
4878
  }
4732
4879
  return arrayBuffer;
4733
4880
  }
4881
+ // Tile Source interface implementation: deck.gl compatible API
4882
+ // TODO - currently only handles image tiles, not vector tiles
4734
4883
  async getTileData(tileParams) {
4735
- const {
4736
- x: x3,
4737
- y: y2,
4738
- z
4739
- } = tileParams.index;
4884
+ const { x: x3, y: y2, z } = tileParams.index;
4740
4885
  const metadata = await this.metadata;
4741
4886
  switch (metadata.tileMIMEType) {
4742
4887
  case "application/vnd.mapbox-vector-tile":
4743
- return await this.getVectorTile({
4744
- x: x3,
4745
- y: y2,
4746
- zoom: z,
4747
- layers: []
4748
- });
4888
+ return await this.getVectorTile({ x: x3, y: y2, zoom: z, layers: [] });
4749
4889
  default:
4750
- return await this.getImageTile({
4751
- x: x3,
4752
- y: y2,
4753
- zoom: z,
4754
- layers: []
4755
- });
4890
+ return await this.getImageTile({ x: x3, y: y2, zoom: z, layers: [] });
4756
4891
  }
4757
4892
  }
4893
+ // ImageTileSource interface implementation
4758
4894
  async getImageTile(tileParams) {
4759
4895
  const arrayBuffer = await this.getTile(tileParams);
4760
4896
  return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
4761
4897
  }
4898
+ // VectorTileSource interface implementation
4762
4899
  async getVectorTile(tileParams) {
4763
4900
  const arrayBuffer = await this.getTile(tileParams);
4764
4901
  const loadOptions = {
4765
4902
  shape: "geojson-table",
4766
4903
  mvt: {
4767
4904
  coordinates: "wgs84",
4768
- tileIndex: {
4769
- x: tileParams.x,
4770
- y: tileParams.y,
4771
- z: tileParams.zoom
4772
- },
4905
+ tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
4773
4906
  ...this.loadOptions?.mvt
4774
4907
  },
4775
4908
  ...this.loadOptions
@@ -4777,7 +4910,7 @@ var __exports__ = (() => {
4777
4910
  return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
4778
4911
  }
4779
4912
  };
4780
- return __toCommonJS(src_exports);
4913
+ return __toCommonJS(bundle_exports);
4781
4914
  })();
4782
4915
  /*! Bundled license information:
4783
4916