@loaders.gl/pmtiles 4.2.0-alpha.3 → 4.2.0-alpha.5
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 +638 -551
- package/dist/dist.min.js +14 -0
- package/dist/index.cjs +12 -15
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/blob-source.js +27 -17
- package/dist/lib/parse-pmtiles.d.ts +2 -2
- package/dist/lib/parse-pmtiles.d.ts.map +1 -1
- package/dist/lib/parse-pmtiles.js +75 -57
- package/dist/pmtiles-source.d.ts +1 -1
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/pmtiles-source.js +79 -97
- package/package.json +13 -9
- package/src/lib/parse-pmtiles.ts +4 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/blob-source.js.map +0 -1
- package/dist/lib/parse-pmtiles.js.map +0 -1
- package/dist/pmtiles-source.js.map +0 -1
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['
|
|
6
|
-
else root['
|
|
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
|
-
//
|
|
781
|
-
var
|
|
782
|
-
__export(
|
|
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 =
|
|
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,24 @@ var __exports__ = (() => {
|
|
|
869
881
|
|
|
870
882
|
// ../loader-utils/src/lib/sources/data-source.ts
|
|
871
883
|
var DataSource = class {
|
|
872
|
-
_needsRefresh = true;
|
|
873
884
|
constructor(props) {
|
|
874
|
-
this.
|
|
875
|
-
|
|
876
|
-
};
|
|
877
|
-
this.loadOptions = {
|
|
878
|
-
...props.loadOptions
|
|
879
|
-
};
|
|
885
|
+
this._needsRefresh = true;
|
|
886
|
+
this.props = { ...props };
|
|
887
|
+
this.loadOptions = { ...props.loadOptions };
|
|
880
888
|
this.fetch = getFetchFunction(this.loadOptions);
|
|
881
889
|
}
|
|
882
890
|
setProps(props) {
|
|
883
891
|
this.props = Object.assign(this.props, props);
|
|
884
892
|
this.setNeedsRefresh();
|
|
885
893
|
}
|
|
894
|
+
/** Mark this data source as needing a refresh (redraw) */
|
|
886
895
|
setNeedsRefresh() {
|
|
887
896
|
this._needsRefresh = true;
|
|
888
897
|
}
|
|
898
|
+
/**
|
|
899
|
+
* Does this data source need refreshing?
|
|
900
|
+
* @note The specifics of the refresh mechanism depends on type of data source
|
|
901
|
+
*/
|
|
889
902
|
getNeedsRefresh(clear = true) {
|
|
890
903
|
const needsRefresh = this._needsRefresh;
|
|
891
904
|
if (clear) {
|
|
@@ -907,7 +920,7 @@ var __exports__ = (() => {
|
|
|
907
920
|
}
|
|
908
921
|
|
|
909
922
|
// ../images/src/lib/utils/version.ts
|
|
910
|
-
var VERSION =
|
|
923
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
911
924
|
|
|
912
925
|
// ../images/src/lib/category-api/image-type.ts
|
|
913
926
|
var parseImageNode = globalThis.loaders?.parseImageNode;
|
|
@@ -1094,10 +1107,7 @@ var __exports__ = (() => {
|
|
|
1094
1107
|
switch (brandMajor) {
|
|
1095
1108
|
case "avif":
|
|
1096
1109
|
case "avis":
|
|
1097
|
-
return {
|
|
1098
|
-
extension: "avif",
|
|
1099
|
-
mimeType: "image/avif"
|
|
1100
|
-
};
|
|
1110
|
+
return { extension: "avif", mimeType: "image/avif" };
|
|
1101
1111
|
default:
|
|
1102
1112
|
return null;
|
|
1103
1113
|
}
|
|
@@ -1133,6 +1143,7 @@ var __exports__ = (() => {
|
|
|
1133
1143
|
}
|
|
1134
1144
|
return {
|
|
1135
1145
|
mimeType: mediaType.mimeType,
|
|
1146
|
+
// TODO - decode width and height
|
|
1136
1147
|
width: 0,
|
|
1137
1148
|
height: 0
|
|
1138
1149
|
};
|
|
@@ -1179,10 +1190,7 @@ var __exports__ = (() => {
|
|
|
1179
1190
|
if (!isJpeg) {
|
|
1180
1191
|
return null;
|
|
1181
1192
|
}
|
|
1182
|
-
const {
|
|
1183
|
-
tableMarkers,
|
|
1184
|
-
sofMarkers
|
|
1185
|
-
} = getJpegMarkers();
|
|
1193
|
+
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
1186
1194
|
let i3 = 2;
|
|
1187
1195
|
while (i3 + 9 < dataView.byteLength) {
|
|
1188
1196
|
const marker = dataView.getUint16(i3, BIG_ENDIAN);
|
|
@@ -1190,7 +1198,9 @@ var __exports__ = (() => {
|
|
|
1190
1198
|
return {
|
|
1191
1199
|
mimeType: "image/jpeg",
|
|
1192
1200
|
height: dataView.getUint16(i3 + 5, BIG_ENDIAN),
|
|
1201
|
+
// Number of lines
|
|
1193
1202
|
width: dataView.getUint16(i3 + 7, BIG_ENDIAN)
|
|
1203
|
+
// Number of pixels per line
|
|
1194
1204
|
};
|
|
1195
1205
|
}
|
|
1196
1206
|
if (!tableMarkers.has(marker)) {
|
|
@@ -1206,11 +1216,23 @@ var __exports__ = (() => {
|
|
|
1206
1216
|
for (let i3 = 65504; i3 < 65520; ++i3) {
|
|
1207
1217
|
tableMarkers.add(i3);
|
|
1208
1218
|
}
|
|
1209
|
-
const sofMarkers = /* @__PURE__ */ new Set([
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1219
|
+
const sofMarkers = /* @__PURE__ */ new Set([
|
|
1220
|
+
65472,
|
|
1221
|
+
65473,
|
|
1222
|
+
65474,
|
|
1223
|
+
65475,
|
|
1224
|
+
65477,
|
|
1225
|
+
65478,
|
|
1226
|
+
65479,
|
|
1227
|
+
65481,
|
|
1228
|
+
65482,
|
|
1229
|
+
65483,
|
|
1230
|
+
65485,
|
|
1231
|
+
65486,
|
|
1232
|
+
65487,
|
|
1233
|
+
65502
|
|
1234
|
+
]);
|
|
1235
|
+
return { tableMarkers, sofMarkers };
|
|
1214
1236
|
}
|
|
1215
1237
|
function toDataView(data) {
|
|
1216
1238
|
if (data instanceof DataView) {
|
|
@@ -1227,9 +1249,7 @@ var __exports__ = (() => {
|
|
|
1227
1249
|
|
|
1228
1250
|
// ../images/src/lib/parsers/parse-to-node-image.ts
|
|
1229
1251
|
async function parseToNodeImage(arrayBuffer, options) {
|
|
1230
|
-
const {
|
|
1231
|
-
mimeType
|
|
1232
|
-
} = getBinaryImageMetadata(arrayBuffer) || {};
|
|
1252
|
+
const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
|
|
1233
1253
|
const parseImageNode2 = globalThis.loaders?.parseImageNode;
|
|
1234
1254
|
assert(parseImageNode2);
|
|
1235
1255
|
return await parseImageNode2(arrayBuffer, mimeType);
|
|
@@ -1240,9 +1260,7 @@ var __exports__ = (() => {
|
|
|
1240
1260
|
options = options || {};
|
|
1241
1261
|
const imageOptions = options.image || {};
|
|
1242
1262
|
const imageType = imageOptions.type || "auto";
|
|
1243
|
-
const {
|
|
1244
|
-
url
|
|
1245
|
-
} = context || {};
|
|
1263
|
+
const { url } = context || {};
|
|
1246
1264
|
const loadType = getLoadableImageType(imageType);
|
|
1247
1265
|
let image;
|
|
1248
1266
|
switch (loadType) {
|
|
@@ -1276,12 +1294,23 @@ var __exports__ = (() => {
|
|
|
1276
1294
|
|
|
1277
1295
|
// ../images/src/image-loader.ts
|
|
1278
1296
|
var EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
|
|
1279
|
-
var MIME_TYPES = [
|
|
1297
|
+
var MIME_TYPES = [
|
|
1298
|
+
"image/png",
|
|
1299
|
+
"image/jpeg",
|
|
1300
|
+
"image/gif",
|
|
1301
|
+
"image/webp",
|
|
1302
|
+
"image/avif",
|
|
1303
|
+
"image/bmp",
|
|
1304
|
+
"image/vnd.microsoft.icon",
|
|
1305
|
+
"image/svg+xml"
|
|
1306
|
+
];
|
|
1280
1307
|
var DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
1281
1308
|
image: {
|
|
1282
1309
|
type: "auto",
|
|
1283
1310
|
decode: true
|
|
1311
|
+
// if format is HTML
|
|
1284
1312
|
}
|
|
1313
|
+
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
1285
1314
|
};
|
|
1286
1315
|
var ImageLoader = {
|
|
1287
1316
|
id: "image",
|
|
@@ -1291,6 +1320,7 @@ var __exports__ = (() => {
|
|
|
1291
1320
|
mimeTypes: MIME_TYPES,
|
|
1292
1321
|
extensions: EXTENSIONS,
|
|
1293
1322
|
parse: parseImage,
|
|
1323
|
+
// TODO: byteOffset, byteLength;
|
|
1294
1324
|
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
1295
1325
|
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
1296
1326
|
};
|
|
@@ -1812,14 +1842,18 @@ var __exports__ = (() => {
|
|
|
1812
1842
|
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1813
1843
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
1814
1844
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1815
|
-
return fillArrays(
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1845
|
+
return fillArrays(
|
|
1846
|
+
features,
|
|
1847
|
+
{
|
|
1848
|
+
propArrayTypes,
|
|
1849
|
+
...geometryInfo
|
|
1850
|
+
},
|
|
1851
|
+
{
|
|
1852
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1853
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
1854
|
+
triangulate: options ? options.triangulate : true
|
|
1855
|
+
}
|
|
1856
|
+
);
|
|
1823
1857
|
}
|
|
1824
1858
|
function extractNumericPropTypes(features) {
|
|
1825
1859
|
const propArrayTypes = {};
|
|
@@ -1847,11 +1881,7 @@ var __exports__ = (() => {
|
|
|
1847
1881
|
propArrayTypes,
|
|
1848
1882
|
coordLength
|
|
1849
1883
|
} = geometryInfo;
|
|
1850
|
-
const {
|
|
1851
|
-
numericPropKeys = [],
|
|
1852
|
-
PositionDataType = Float32Array,
|
|
1853
|
-
triangulate = true
|
|
1854
|
-
} = options;
|
|
1884
|
+
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
1855
1885
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
1856
1886
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1857
1887
|
const points = {
|
|
@@ -1916,9 +1946,7 @@ var __exports__ = (() => {
|
|
|
1916
1946
|
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1917
1947
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1918
1948
|
if (hasGlobalId) {
|
|
1919
|
-
points.fields.push({
|
|
1920
|
-
id: feature.id
|
|
1921
|
-
});
|
|
1949
|
+
points.fields.push({ id: feature.id });
|
|
1922
1950
|
}
|
|
1923
1951
|
indexMap.pointFeature++;
|
|
1924
1952
|
break;
|
|
@@ -1926,9 +1954,7 @@ var __exports__ = (() => {
|
|
|
1926
1954
|
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1927
1955
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1928
1956
|
if (hasGlobalId) {
|
|
1929
|
-
lines.fields.push({
|
|
1930
|
-
id: feature.id
|
|
1931
|
-
});
|
|
1957
|
+
lines.fields.push({ id: feature.id });
|
|
1932
1958
|
}
|
|
1933
1959
|
indexMap.lineFeature++;
|
|
1934
1960
|
break;
|
|
@@ -1936,9 +1962,7 @@ var __exports__ = (() => {
|
|
|
1936
1962
|
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1937
1963
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1938
1964
|
if (hasGlobalId) {
|
|
1939
|
-
polygons.fields.push({
|
|
1940
|
-
id: feature.id
|
|
1941
|
-
});
|
|
1965
|
+
polygons.fields.push({ id: feature.id });
|
|
1942
1966
|
}
|
|
1943
1967
|
indexMap.polygonFeature++;
|
|
1944
1968
|
break;
|
|
@@ -1953,16 +1977,32 @@ var __exports__ = (() => {
|
|
|
1953
1977
|
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1954
1978
|
const nPositions = geometry.data.length / coordLength;
|
|
1955
1979
|
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1956
|
-
points.globalFeatureIds.fill(
|
|
1957
|
-
|
|
1980
|
+
points.globalFeatureIds.fill(
|
|
1981
|
+
indexMap.feature,
|
|
1982
|
+
indexMap.pointPosition,
|
|
1983
|
+
indexMap.pointPosition + nPositions
|
|
1984
|
+
);
|
|
1985
|
+
points.featureIds.fill(
|
|
1986
|
+
indexMap.pointFeature,
|
|
1987
|
+
indexMap.pointPosition,
|
|
1988
|
+
indexMap.pointPosition + nPositions
|
|
1989
|
+
);
|
|
1958
1990
|
indexMap.pointPosition += nPositions;
|
|
1959
1991
|
}
|
|
1960
1992
|
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1961
1993
|
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1962
1994
|
const nPositions = geometry.data.length / coordLength;
|
|
1963
1995
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1964
|
-
lines.globalFeatureIds.fill(
|
|
1965
|
-
|
|
1996
|
+
lines.globalFeatureIds.fill(
|
|
1997
|
+
indexMap.feature,
|
|
1998
|
+
indexMap.linePosition,
|
|
1999
|
+
indexMap.linePosition + nPositions
|
|
2000
|
+
);
|
|
2001
|
+
lines.featureIds.fill(
|
|
2002
|
+
indexMap.lineFeature,
|
|
2003
|
+
indexMap.linePosition,
|
|
2004
|
+
indexMap.linePosition + nPositions
|
|
2005
|
+
);
|
|
1966
2006
|
for (let i3 = 0, il = geometry.indices.length; i3 < il; ++i3) {
|
|
1967
2007
|
const start = geometry.indices[i3];
|
|
1968
2008
|
const end = i3 === il - 1 ? geometry.data.length : geometry.indices[i3 + 1];
|
|
@@ -1974,8 +2014,16 @@ var __exports__ = (() => {
|
|
|
1974
2014
|
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1975
2015
|
const nPositions = geometry.data.length / coordLength;
|
|
1976
2016
|
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1977
|
-
polygons.globalFeatureIds.fill(
|
|
1978
|
-
|
|
2017
|
+
polygons.globalFeatureIds.fill(
|
|
2018
|
+
indexMap.feature,
|
|
2019
|
+
indexMap.polygonPosition,
|
|
2020
|
+
indexMap.polygonPosition + nPositions
|
|
2021
|
+
);
|
|
2022
|
+
polygons.featureIds.fill(
|
|
2023
|
+
indexMap.polygonFeature,
|
|
2024
|
+
indexMap.polygonPosition,
|
|
2025
|
+
indexMap.polygonPosition + nPositions
|
|
2026
|
+
);
|
|
1979
2027
|
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1980
2028
|
const startPosition = indexMap.polygonPosition;
|
|
1981
2029
|
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
@@ -1984,16 +2032,15 @@ var __exports__ = (() => {
|
|
|
1984
2032
|
const nextIndices = geometry.indices[l + 1];
|
|
1985
2033
|
for (let i3 = 0, il = indices.length; i3 < il; ++i3) {
|
|
1986
2034
|
const start = indices[i3];
|
|
1987
|
-
const end = i3 === il - 1 ?
|
|
2035
|
+
const end = i3 === il - 1 ? (
|
|
2036
|
+
// last line, so either read to:
|
|
2037
|
+
nextIndices === void 0 ? geometry.data.length : nextIndices[0]
|
|
2038
|
+
) : indices[i3 + 1];
|
|
1988
2039
|
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1989
2040
|
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1990
2041
|
}
|
|
1991
2042
|
const endPosition = indexMap.polygonPosition;
|
|
1992
|
-
triangulatePolygon(polygons, areas, indices, {
|
|
1993
|
-
startPosition,
|
|
1994
|
-
endPosition,
|
|
1995
|
-
coordLength
|
|
1996
|
-
});
|
|
2043
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1997
2044
|
}
|
|
1998
2045
|
}
|
|
1999
2046
|
function triangulatePolygon(polygons, areas, indices, {
|
|
@@ -2017,10 +2064,7 @@ var __exports__ = (() => {
|
|
|
2017
2064
|
function wrapProps(obj, size) {
|
|
2018
2065
|
const returnObj = {};
|
|
2019
2066
|
for (const key in obj) {
|
|
2020
|
-
returnObj[key] = {
|
|
2021
|
-
value: obj[key],
|
|
2022
|
-
size
|
|
2023
|
-
};
|
|
2067
|
+
returnObj[key] = { value: obj[key], size };
|
|
2024
2068
|
}
|
|
2025
2069
|
return returnObj;
|
|
2026
2070
|
}
|
|
@@ -2029,70 +2073,32 @@ var __exports__ = (() => {
|
|
|
2029
2073
|
shape: "binary-feature-collection",
|
|
2030
2074
|
points: {
|
|
2031
2075
|
...points,
|
|
2032
|
-
positions: {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
},
|
|
2036
|
-
globalFeatureIds: {
|
|
2037
|
-
value: points.globalFeatureIds,
|
|
2038
|
-
size: 1
|
|
2039
|
-
},
|
|
2040
|
-
featureIds: {
|
|
2041
|
-
value: points.featureIds,
|
|
2042
|
-
size: 1
|
|
2043
|
-
},
|
|
2076
|
+
positions: { value: points.positions, size: coordLength },
|
|
2077
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
2078
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
2044
2079
|
numericProps: wrapProps(points.numericProps, 1)
|
|
2045
2080
|
},
|
|
2046
2081
|
lines: {
|
|
2047
2082
|
...lines,
|
|
2048
|
-
positions: {
|
|
2049
|
-
|
|
2050
|
-
|
|
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
|
-
},
|
|
2083
|
+
positions: { value: lines.positions, size: coordLength },
|
|
2084
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
2085
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
2086
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
2064
2087
|
numericProps: wrapProps(lines.numericProps, 1)
|
|
2065
2088
|
},
|
|
2066
2089
|
polygons: {
|
|
2067
2090
|
...polygons,
|
|
2068
|
-
positions: {
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
},
|
|
2072
|
-
|
|
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
|
-
},
|
|
2091
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
2092
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
2093
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
2094
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
2095
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
2088
2096
|
numericProps: wrapProps(polygons.numericProps, 1)
|
|
2089
2097
|
}
|
|
2098
|
+
// triangles not expected
|
|
2090
2099
|
};
|
|
2091
2100
|
if (binaryFeatures.polygons && polygons.triangles) {
|
|
2092
|
-
binaryFeatures.polygons.triangles = {
|
|
2093
|
-
value: new Uint32Array(polygons.triangles),
|
|
2094
|
-
size: 1
|
|
2095
|
-
};
|
|
2101
|
+
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
2096
2102
|
}
|
|
2097
2103
|
return binaryFeatures;
|
|
2098
2104
|
}
|
|
@@ -2194,6 +2200,7 @@ var __exports__ = (() => {
|
|
|
2194
2200
|
this._values = values;
|
|
2195
2201
|
pbf.readFields(readFeature, this, end);
|
|
2196
2202
|
}
|
|
2203
|
+
// eslint-disable-next-line complexity, max-statements
|
|
2197
2204
|
loadGeometry() {
|
|
2198
2205
|
const pbf = this._pbf;
|
|
2199
2206
|
pbf.pos = this._geometry;
|
|
@@ -2233,6 +2240,7 @@ var __exports__ = (() => {
|
|
|
2233
2240
|
lines.push(line);
|
|
2234
2241
|
return lines;
|
|
2235
2242
|
}
|
|
2243
|
+
// eslint-disable-next-line max-statements
|
|
2236
2244
|
bbox() {
|
|
2237
2245
|
const pbf = this._pbf;
|
|
2238
2246
|
pbf.pos = this._geometry;
|
|
@@ -2319,11 +2327,7 @@ var __exports__ = (() => {
|
|
|
2319
2327
|
if (typeof options === "function") {
|
|
2320
2328
|
return this._toGeoJSON(options);
|
|
2321
2329
|
}
|
|
2322
|
-
const {
|
|
2323
|
-
x: x3,
|
|
2324
|
-
y: y2,
|
|
2325
|
-
z
|
|
2326
|
-
} = options;
|
|
2330
|
+
const { x: x3, y: y2, z } = options;
|
|
2327
2331
|
const size = this.extent * Math.pow(2, z);
|
|
2328
2332
|
const x0 = this.extent * x3;
|
|
2329
2333
|
const y0 = this.extent * y2;
|
|
@@ -2353,6 +2357,11 @@ var __exports__ = (() => {
|
|
|
2353
2357
|
pbf.readFields(readLayer, this, end);
|
|
2354
2358
|
this.length = this._features.length;
|
|
2355
2359
|
}
|
|
2360
|
+
/**
|
|
2361
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
2362
|
+
* @param index
|
|
2363
|
+
* @returns feature
|
|
2364
|
+
*/
|
|
2356
2365
|
feature(i3) {
|
|
2357
2366
|
if (i3 < 0 || i3 >= this._features.length) {
|
|
2358
2367
|
throw new Error("feature index out of bounds");
|
|
@@ -2453,12 +2462,7 @@ var __exports__ = (() => {
|
|
|
2453
2462
|
areas.push(ringAreas);
|
|
2454
2463
|
if (polygon.length)
|
|
2455
2464
|
polygons.push(polygon);
|
|
2456
|
-
return {
|
|
2457
|
-
type,
|
|
2458
|
-
areas,
|
|
2459
|
-
indices: polygons,
|
|
2460
|
-
data: geom.data
|
|
2461
|
-
};
|
|
2465
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
2462
2466
|
}
|
|
2463
2467
|
function project(data, x0, y0, size) {
|
|
2464
2468
|
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
@@ -2497,6 +2501,7 @@ var __exports__ = (() => {
|
|
|
2497
2501
|
var y;
|
|
2498
2502
|
var i;
|
|
2499
2503
|
var VectorTileFeature2 = class {
|
|
2504
|
+
// eslint-disable-next-line max-params
|
|
2500
2505
|
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
2501
2506
|
this.properties = {};
|
|
2502
2507
|
this.extent = extent;
|
|
@@ -2509,6 +2514,7 @@ var __exports__ = (() => {
|
|
|
2509
2514
|
this._geometryInfo = geometryInfo;
|
|
2510
2515
|
pbf.readFields(readFeature2, this, end);
|
|
2511
2516
|
}
|
|
2517
|
+
// eslint-disable-next-line complexity, max-statements
|
|
2512
2518
|
loadGeometry() {
|
|
2513
2519
|
const pbf = this._pbf;
|
|
2514
2520
|
pbf.pos = this._geometry;
|
|
@@ -2545,11 +2551,13 @@ var __exports__ = (() => {
|
|
|
2545
2551
|
throw new Error(`unknown command ${cmd}`);
|
|
2546
2552
|
}
|
|
2547
2553
|
}
|
|
2548
|
-
return {
|
|
2549
|
-
data,
|
|
2550
|
-
indices
|
|
2551
|
-
};
|
|
2554
|
+
return { data, indices };
|
|
2552
2555
|
}
|
|
2556
|
+
/**
|
|
2557
|
+
*
|
|
2558
|
+
* @param transform
|
|
2559
|
+
* @returns result
|
|
2560
|
+
*/
|
|
2553
2561
|
_toBinaryCoordinates(transform) {
|
|
2554
2562
|
const geom = this.loadGeometry();
|
|
2555
2563
|
let geometry;
|
|
@@ -2559,19 +2567,13 @@ var __exports__ = (() => {
|
|
|
2559
2567
|
case 1:
|
|
2560
2568
|
this._geometryInfo.pointFeaturesCount++;
|
|
2561
2569
|
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
2562
|
-
geometry = {
|
|
2563
|
-
type: "Point",
|
|
2564
|
-
...geom
|
|
2565
|
-
};
|
|
2570
|
+
geometry = { type: "Point", ...geom };
|
|
2566
2571
|
break;
|
|
2567
2572
|
case 2:
|
|
2568
2573
|
this._geometryInfo.lineFeaturesCount++;
|
|
2569
2574
|
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
2570
2575
|
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
2571
|
-
geometry = {
|
|
2572
|
-
type: "LineString",
|
|
2573
|
-
...geom
|
|
2574
|
-
};
|
|
2576
|
+
geometry = { type: "LineString", ...geom };
|
|
2575
2577
|
break;
|
|
2576
2578
|
case 3:
|
|
2577
2579
|
geometry = classifyRings2(geom);
|
|
@@ -2585,11 +2587,7 @@ var __exports__ = (() => {
|
|
|
2585
2587
|
default:
|
|
2586
2588
|
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
2587
2589
|
}
|
|
2588
|
-
const result = {
|
|
2589
|
-
type: "Feature",
|
|
2590
|
-
geometry,
|
|
2591
|
-
properties: this.properties
|
|
2592
|
-
};
|
|
2590
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
2593
2591
|
if (this.id !== null) {
|
|
2594
2592
|
result.id = this.id;
|
|
2595
2593
|
}
|
|
@@ -2599,11 +2597,7 @@ var __exports__ = (() => {
|
|
|
2599
2597
|
if (typeof options === "function") {
|
|
2600
2598
|
return this._toBinaryCoordinates(options);
|
|
2601
2599
|
}
|
|
2602
|
-
const {
|
|
2603
|
-
x: x3,
|
|
2604
|
-
y: y2,
|
|
2605
|
-
z
|
|
2606
|
-
} = options;
|
|
2600
|
+
const { x: x3, y: y2, z } = options;
|
|
2607
2601
|
const size = this.extent * Math.pow(2, z);
|
|
2608
2602
|
const x0 = this.extent * x3;
|
|
2609
2603
|
const y0 = this.extent * y2;
|
|
@@ -2625,13 +2619,27 @@ var __exports__ = (() => {
|
|
|
2625
2619
|
pbf.readFields(readLayer2, this, end);
|
|
2626
2620
|
this.length = this._features.length;
|
|
2627
2621
|
}
|
|
2622
|
+
/**
|
|
2623
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
2624
|
+
*
|
|
2625
|
+
* @param index
|
|
2626
|
+
* @param geometryInfo
|
|
2627
|
+
* @returns {VectorTileFeature}
|
|
2628
|
+
*/
|
|
2628
2629
|
feature(i3, geometryInfo) {
|
|
2629
2630
|
if (i3 < 0 || i3 >= this._features.length) {
|
|
2630
2631
|
throw new Error("feature index out of bounds");
|
|
2631
2632
|
}
|
|
2632
2633
|
this._pbf.pos = this._features[i3];
|
|
2633
2634
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2634
|
-
return new VectorTileFeature2(
|
|
2635
|
+
return new VectorTileFeature2(
|
|
2636
|
+
this._pbf,
|
|
2637
|
+
end,
|
|
2638
|
+
this.extent,
|
|
2639
|
+
this._keys,
|
|
2640
|
+
this._values,
|
|
2641
|
+
geometryInfo
|
|
2642
|
+
);
|
|
2635
2643
|
}
|
|
2636
2644
|
};
|
|
2637
2645
|
function readLayer2(tag, layer, pbf) {
|
|
@@ -2683,10 +2691,7 @@ var __exports__ = (() => {
|
|
|
2683
2691
|
const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
|
|
2684
2692
|
switch (shape) {
|
|
2685
2693
|
case "columnar-table":
|
|
2686
|
-
return {
|
|
2687
|
-
shape: "columnar-table",
|
|
2688
|
-
data: parseToBinary(arrayBuffer, mvtOptions)
|
|
2689
|
-
};
|
|
2694
|
+
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2690
2695
|
case "geojson-table": {
|
|
2691
2696
|
const table = {
|
|
2692
2697
|
shape: "geojson-table",
|
|
@@ -2768,9 +2773,7 @@ var __exports__ = (() => {
|
|
|
2768
2773
|
throw new Error("mvt options required");
|
|
2769
2774
|
}
|
|
2770
2775
|
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2771
|
-
const {
|
|
2772
|
-
tileIndex
|
|
2773
|
-
} = options.mvt;
|
|
2776
|
+
const { tileIndex } = options.mvt;
|
|
2774
2777
|
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2775
2778
|
if (wgs84Coordinates && !hasTileIndex) {
|
|
2776
2779
|
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
@@ -2778,23 +2781,27 @@ var __exports__ = (() => {
|
|
|
2778
2781
|
return options.mvt;
|
|
2779
2782
|
}
|
|
2780
2783
|
function getDecodedFeature(feature, options, layerName) {
|
|
2781
|
-
const decodedFeature = feature.toGeoJSON(
|
|
2784
|
+
const decodedFeature = feature.toGeoJSON(
|
|
2785
|
+
// @ts-expect-error What is going on here?
|
|
2786
|
+
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
|
|
2787
|
+
);
|
|
2782
2788
|
if (options.layerProperty) {
|
|
2783
2789
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2784
2790
|
}
|
|
2785
2791
|
return decodedFeature;
|
|
2786
2792
|
}
|
|
2787
2793
|
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2788
|
-
const decodedFeature = feature.toBinaryCoordinates(
|
|
2794
|
+
const decodedFeature = feature.toBinaryCoordinates(
|
|
2795
|
+
// @ts-expect-error What is going on here?
|
|
2796
|
+
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
2797
|
+
);
|
|
2789
2798
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2790
2799
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2791
2800
|
}
|
|
2792
2801
|
return decodedFeature;
|
|
2793
2802
|
}
|
|
2794
2803
|
function transformToLocalCoordinates(line, feature) {
|
|
2795
|
-
const {
|
|
2796
|
-
extent
|
|
2797
|
-
} = feature;
|
|
2804
|
+
const { extent } = feature;
|
|
2798
2805
|
for (let i3 = 0; i3 < line.length; i3++) {
|
|
2799
2806
|
const p = line[i3];
|
|
2800
2807
|
p[0] /= extent;
|
|
@@ -2802,23 +2809,27 @@ var __exports__ = (() => {
|
|
|
2802
2809
|
}
|
|
2803
2810
|
}
|
|
2804
2811
|
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2805
|
-
const {
|
|
2806
|
-
extent
|
|
2807
|
-
} = feature;
|
|
2812
|
+
const { extent } = feature;
|
|
2808
2813
|
for (let i3 = 0, il = data.length; i3 < il; ++i3) {
|
|
2809
2814
|
data[i3] /= extent;
|
|
2810
2815
|
}
|
|
2811
2816
|
}
|
|
2812
2817
|
|
|
2813
2818
|
// ../mvt/src/mvt-loader.ts
|
|
2814
|
-
var VERSION2 =
|
|
2819
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2815
2820
|
var MVTWorkerLoader = {
|
|
2816
2821
|
name: "Mapbox Vector Tile",
|
|
2817
2822
|
id: "mvt",
|
|
2818
2823
|
module: "mvt",
|
|
2819
2824
|
version: VERSION2,
|
|
2825
|
+
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
2820
2826
|
extensions: ["mvt", "pbf"],
|
|
2821
|
-
mimeTypes: [
|
|
2827
|
+
mimeTypes: [
|
|
2828
|
+
// https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile
|
|
2829
|
+
"application/vnd.mapbox-vector-tile",
|
|
2830
|
+
"application/x-protobuf"
|
|
2831
|
+
// 'application/octet-stream'
|
|
2832
|
+
],
|
|
2822
2833
|
worker: true,
|
|
2823
2834
|
category: "geometry",
|
|
2824
2835
|
options: {
|
|
@@ -2892,9 +2903,7 @@ var __exports__ = (() => {
|
|
|
2892
2903
|
name: key,
|
|
2893
2904
|
...attributeTypeToFieldType(String(datatype))
|
|
2894
2905
|
}));
|
|
2895
|
-
const layer2 = {
|
|
2896
|
-
...layer
|
|
2897
|
-
};
|
|
2906
|
+
const layer2 = { ...layer };
|
|
2898
2907
|
delete layer2.fields;
|
|
2899
2908
|
return {
|
|
2900
2909
|
name: layer.id || "",
|
|
@@ -2936,9 +2945,7 @@ var __exports__ = (() => {
|
|
|
2936
2945
|
return layers.map((layer) => {
|
|
2937
2946
|
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
2938
2947
|
const fields = tilestatsLayer?.fields || [];
|
|
2939
|
-
const layer2 = {
|
|
2940
|
-
...layer
|
|
2941
|
-
};
|
|
2948
|
+
const layer2 = { ...layer };
|
|
2942
2949
|
delete layer2.fields;
|
|
2943
2950
|
return {
|
|
2944
2951
|
...layer2,
|
|
@@ -2950,7 +2957,10 @@ var __exports__ = (() => {
|
|
|
2950
2957
|
function parseBounds(bounds) {
|
|
2951
2958
|
const result = fromArrayOrString(bounds);
|
|
2952
2959
|
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
2953
|
-
return [
|
|
2960
|
+
return [
|
|
2961
|
+
[result[0], result[1]],
|
|
2962
|
+
[result[2], result[3]]
|
|
2963
|
+
];
|
|
2954
2964
|
}
|
|
2955
2965
|
return void 0;
|
|
2956
2966
|
}
|
|
@@ -3015,6 +3025,8 @@ var __exports__ = (() => {
|
|
|
3015
3025
|
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
3016
3026
|
const field = {
|
|
3017
3027
|
name: attribute.attribute,
|
|
3028
|
+
// what happens if attribute type is string...
|
|
3029
|
+
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
3018
3030
|
...fieldTypes
|
|
3019
3031
|
};
|
|
3020
3032
|
if (typeof attribute.min === "number") {
|
|
@@ -3038,13 +3050,11 @@ var __exports__ = (() => {
|
|
|
3038
3050
|
const type = aType.toLowerCase();
|
|
3039
3051
|
if (!type || !attrTypeMap[type]) {
|
|
3040
3052
|
}
|
|
3041
|
-
return attrTypeMap[type] || {
|
|
3042
|
-
type: "string"
|
|
3043
|
-
};
|
|
3053
|
+
return attrTypeMap[type] || { type: "string" };
|
|
3044
3054
|
}
|
|
3045
3055
|
|
|
3046
3056
|
// ../mvt/src/tilejson-loader.ts
|
|
3047
|
-
var VERSION3 =
|
|
3057
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3048
3058
|
var TileJSONLoader = {
|
|
3049
3059
|
name: "TileJSON",
|
|
3050
3060
|
id: "tilejson",
|
|
@@ -3062,29 +3072,23 @@ var __exports__ = (() => {
|
|
|
3062
3072
|
parse: async (arrayBuffer, options) => {
|
|
3063
3073
|
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
3064
3074
|
const json = JSON.parse(jsonString);
|
|
3065
|
-
const tilejsonOptions = {
|
|
3066
|
-
...TileJSONLoader.options.tilejson,
|
|
3067
|
-
...options?.tilejson
|
|
3068
|
-
};
|
|
3075
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3069
3076
|
return parseTileJSON(json, tilejsonOptions);
|
|
3070
3077
|
},
|
|
3071
3078
|
parseTextSync: (text, options) => {
|
|
3072
3079
|
const json = JSON.parse(text);
|
|
3073
|
-
const tilejsonOptions = {
|
|
3074
|
-
...TileJSONLoader.options.tilejson,
|
|
3075
|
-
...options?.tilejson
|
|
3076
|
-
};
|
|
3080
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3077
3081
|
return parseTileJSON(json, tilejsonOptions);
|
|
3078
3082
|
}
|
|
3079
3083
|
};
|
|
3080
3084
|
|
|
3081
|
-
// ../../node_modules/pmtiles/dist/index.
|
|
3085
|
+
// ../../node_modules/pmtiles/dist/index.js
|
|
3082
3086
|
var dist_exports = {};
|
|
3083
3087
|
__export(dist_exports, {
|
|
3084
3088
|
Compression: () => Compression,
|
|
3085
3089
|
EtagMismatch: () => EtagMismatch,
|
|
3086
3090
|
FetchSource: () => FetchSource,
|
|
3087
|
-
|
|
3091
|
+
FileSource: () => FileSource,
|
|
3088
3092
|
PMTiles: () => PMTiles,
|
|
3089
3093
|
Protocol: () => Protocol,
|
|
3090
3094
|
ResolvedValueCache: () => ResolvedValueCache,
|
|
@@ -3098,6 +3102,7 @@ var __exports__ = (() => {
|
|
|
3098
3102
|
tileIdToZxy: () => tileIdToZxy,
|
|
3099
3103
|
zxyToTileId: () => zxyToTileId
|
|
3100
3104
|
});
|
|
3105
|
+
var __pow = Math.pow;
|
|
3101
3106
|
var __async = (__this, __arguments, generator) => {
|
|
3102
3107
|
return new Promise((resolve, reject) => {
|
|
3103
3108
|
var fulfilled = (value) => {
|
|
@@ -3121,8 +3126,77 @@ var __exports__ = (() => {
|
|
|
3121
3126
|
var u8 = Uint8Array;
|
|
3122
3127
|
var u16 = Uint16Array;
|
|
3123
3128
|
var i32 = Int32Array;
|
|
3124
|
-
var fleb = new u8([
|
|
3125
|
-
|
|
3129
|
+
var fleb = new u8([
|
|
3130
|
+
0,
|
|
3131
|
+
0,
|
|
3132
|
+
0,
|
|
3133
|
+
0,
|
|
3134
|
+
0,
|
|
3135
|
+
0,
|
|
3136
|
+
0,
|
|
3137
|
+
0,
|
|
3138
|
+
1,
|
|
3139
|
+
1,
|
|
3140
|
+
1,
|
|
3141
|
+
1,
|
|
3142
|
+
2,
|
|
3143
|
+
2,
|
|
3144
|
+
2,
|
|
3145
|
+
2,
|
|
3146
|
+
3,
|
|
3147
|
+
3,
|
|
3148
|
+
3,
|
|
3149
|
+
3,
|
|
3150
|
+
4,
|
|
3151
|
+
4,
|
|
3152
|
+
4,
|
|
3153
|
+
4,
|
|
3154
|
+
5,
|
|
3155
|
+
5,
|
|
3156
|
+
5,
|
|
3157
|
+
5,
|
|
3158
|
+
0,
|
|
3159
|
+
/* unused */
|
|
3160
|
+
0,
|
|
3161
|
+
0,
|
|
3162
|
+
/* impossible */
|
|
3163
|
+
0
|
|
3164
|
+
]);
|
|
3165
|
+
var fdeb = new u8([
|
|
3166
|
+
0,
|
|
3167
|
+
0,
|
|
3168
|
+
0,
|
|
3169
|
+
0,
|
|
3170
|
+
1,
|
|
3171
|
+
1,
|
|
3172
|
+
2,
|
|
3173
|
+
2,
|
|
3174
|
+
3,
|
|
3175
|
+
3,
|
|
3176
|
+
4,
|
|
3177
|
+
4,
|
|
3178
|
+
5,
|
|
3179
|
+
5,
|
|
3180
|
+
6,
|
|
3181
|
+
6,
|
|
3182
|
+
7,
|
|
3183
|
+
7,
|
|
3184
|
+
8,
|
|
3185
|
+
8,
|
|
3186
|
+
9,
|
|
3187
|
+
9,
|
|
3188
|
+
10,
|
|
3189
|
+
10,
|
|
3190
|
+
11,
|
|
3191
|
+
11,
|
|
3192
|
+
12,
|
|
3193
|
+
12,
|
|
3194
|
+
13,
|
|
3195
|
+
13,
|
|
3196
|
+
/* unused */
|
|
3197
|
+
0,
|
|
3198
|
+
0
|
|
3199
|
+
]);
|
|
3126
3200
|
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
3127
3201
|
var freb = function(eb, start) {
|
|
3128
3202
|
var b = new u16(31);
|
|
@@ -3251,6 +3325,7 @@ var __exports__ = (() => {
|
|
|
3251
3325
|
"filename too long",
|
|
3252
3326
|
"stream finishing",
|
|
3253
3327
|
"invalid zip data"
|
|
3328
|
+
// determined by unknown compression method
|
|
3254
3329
|
];
|
|
3255
3330
|
var err = function(ind, msg, nt) {
|
|
3256
3331
|
var e = new Error(msg || ec[ind]);
|
|
@@ -3452,10 +3527,10 @@ var __exports__ = (() => {
|
|
|
3452
3527
|
} catch (e) {
|
|
3453
3528
|
}
|
|
3454
3529
|
var shift = (n, shift2) => {
|
|
3455
|
-
return n *
|
|
3530
|
+
return n * __pow(2, shift2);
|
|
3456
3531
|
};
|
|
3457
3532
|
var unshift = (n, shift2) => {
|
|
3458
|
-
return Math.floor(n /
|
|
3533
|
+
return Math.floor(n / __pow(2, shift2));
|
|
3459
3534
|
};
|
|
3460
3535
|
var getUint24 = (view, pos) => {
|
|
3461
3536
|
return shift(view.getUint16(pos + 1, true), 8) + view.getUint8(pos);
|
|
@@ -3464,40 +3539,40 @@ var __exports__ = (() => {
|
|
|
3464
3539
|
return shift(view.getUint32(pos + 2, true), 16) + view.getUint16(pos, true);
|
|
3465
3540
|
};
|
|
3466
3541
|
var compare = (tz, tx, ty, view, i3) => {
|
|
3467
|
-
if (tz
|
|
3542
|
+
if (tz !== view.getUint8(i3))
|
|
3468
3543
|
return tz - view.getUint8(i3);
|
|
3469
3544
|
const x3 = getUint24(view, i3 + 1);
|
|
3470
|
-
if (tx
|
|
3545
|
+
if (tx !== x3)
|
|
3471
3546
|
return tx - x3;
|
|
3472
3547
|
const y2 = getUint24(view, i3 + 4);
|
|
3473
|
-
if (ty
|
|
3548
|
+
if (ty !== y2)
|
|
3474
3549
|
return ty - y2;
|
|
3475
3550
|
return 0;
|
|
3476
3551
|
};
|
|
3477
3552
|
var queryLeafdir = (view, z, x3, y2) => {
|
|
3478
|
-
const
|
|
3479
|
-
if (
|
|
3553
|
+
const offsetLen = queryView(view, z | 128, x3, y2);
|
|
3554
|
+
if (offsetLen) {
|
|
3480
3555
|
return {
|
|
3481
3556
|
z,
|
|
3482
3557
|
x: x3,
|
|
3483
3558
|
y: y2,
|
|
3484
|
-
offset:
|
|
3485
|
-
length:
|
|
3486
|
-
|
|
3559
|
+
offset: offsetLen[0],
|
|
3560
|
+
length: offsetLen[1],
|
|
3561
|
+
isDir: true
|
|
3487
3562
|
};
|
|
3488
3563
|
}
|
|
3489
3564
|
return null;
|
|
3490
3565
|
};
|
|
3491
3566
|
var queryTile = (view, z, x3, y2) => {
|
|
3492
|
-
const
|
|
3493
|
-
if (
|
|
3567
|
+
const offsetLen = queryView(view, z, x3, y2);
|
|
3568
|
+
if (offsetLen) {
|
|
3494
3569
|
return {
|
|
3495
3570
|
z,
|
|
3496
3571
|
x: x3,
|
|
3497
3572
|
y: y2,
|
|
3498
|
-
offset:
|
|
3499
|
-
length:
|
|
3500
|
-
|
|
3573
|
+
offset: offsetLen[0],
|
|
3574
|
+
length: offsetLen[1],
|
|
3575
|
+
isDir: false
|
|
3501
3576
|
};
|
|
3502
3577
|
}
|
|
3503
3578
|
return null;
|
|
@@ -3519,10 +3594,10 @@ var __exports__ = (() => {
|
|
|
3519
3594
|
return null;
|
|
3520
3595
|
};
|
|
3521
3596
|
var entrySort = (a, b) => {
|
|
3522
|
-
if (a.
|
|
3597
|
+
if (a.isDir && !b.isDir) {
|
|
3523
3598
|
return 1;
|
|
3524
3599
|
}
|
|
3525
|
-
if (!a.
|
|
3600
|
+
if (!a.isDir && b.isDir) {
|
|
3526
3601
|
return -1;
|
|
3527
3602
|
}
|
|
3528
3603
|
if (a.z !== b.z) {
|
|
@@ -3534,15 +3609,15 @@ var __exports__ = (() => {
|
|
|
3534
3609
|
return a.y - b.y;
|
|
3535
3610
|
};
|
|
3536
3611
|
var parseEntry = (dataview, i3) => {
|
|
3537
|
-
const
|
|
3538
|
-
const z =
|
|
3612
|
+
const zRaw = dataview.getUint8(i3 * 17);
|
|
3613
|
+
const z = zRaw & 127;
|
|
3539
3614
|
return {
|
|
3540
3615
|
z,
|
|
3541
3616
|
x: getUint24(dataview, i3 * 17 + 1),
|
|
3542
3617
|
y: getUint24(dataview, i3 * 17 + 4),
|
|
3543
3618
|
offset: getUint48(dataview, i3 * 17 + 7),
|
|
3544
3619
|
length: dataview.getUint32(i3 * 17 + 13, true),
|
|
3545
|
-
|
|
3620
|
+
isDir: zRaw >> 7 === 1
|
|
3546
3621
|
};
|
|
3547
3622
|
};
|
|
3548
3623
|
var sortDir = (a) => {
|
|
@@ -3560,7 +3635,7 @@ var __exports__ = (() => {
|
|
|
3560
3635
|
for (let i3 = 0; i3 < entries.length; i3++) {
|
|
3561
3636
|
const entry = entries[i3];
|
|
3562
3637
|
let z = entry.z;
|
|
3563
|
-
if (entry.
|
|
3638
|
+
if (entry.isDir)
|
|
3564
3639
|
z = z | 128;
|
|
3565
3640
|
arr[i3 * 17] = z;
|
|
3566
3641
|
arr[i3 * 17 + 1] = entry.x & 255;
|
|
@@ -3587,12 +3662,12 @@ var __exports__ = (() => {
|
|
|
3587
3662
|
return null;
|
|
3588
3663
|
const numEntries = view.byteLength / 17;
|
|
3589
3664
|
const entry = parseEntry(view, numEntries - 1);
|
|
3590
|
-
if (entry.
|
|
3591
|
-
const
|
|
3592
|
-
const
|
|
3593
|
-
const
|
|
3594
|
-
const
|
|
3595
|
-
return { z:
|
|
3665
|
+
if (entry.isDir) {
|
|
3666
|
+
const leafLevel = entry.z;
|
|
3667
|
+
const levelDiff = tile.z - leafLevel;
|
|
3668
|
+
const leafX = Math.trunc(tile.x / (1 << levelDiff));
|
|
3669
|
+
const leafY = Math.trunc(tile.y / (1 << levelDiff));
|
|
3670
|
+
return { z: leafLevel, x: leafX, y: leafY };
|
|
3596
3671
|
}
|
|
3597
3672
|
return null;
|
|
3598
3673
|
};
|
|
@@ -3600,50 +3675,50 @@ var __exports__ = (() => {
|
|
|
3600
3675
|
return __async(this, null, function* () {
|
|
3601
3676
|
const resp = yield source.getBytes(0, 512e3);
|
|
3602
3677
|
const dataview = new DataView(resp.data);
|
|
3603
|
-
const
|
|
3604
|
-
const
|
|
3678
|
+
const jsonSize = dataview.getUint32(4, true);
|
|
3679
|
+
const rootEntries = dataview.getUint16(8, true);
|
|
3605
3680
|
const dec = new TextDecoder("utf-8");
|
|
3606
|
-
const
|
|
3607
|
-
dec.decode(new DataView(resp.data, 10,
|
|
3681
|
+
const jsonMetadata = JSON.parse(
|
|
3682
|
+
dec.decode(new DataView(resp.data, 10, jsonSize))
|
|
3608
3683
|
);
|
|
3609
|
-
let
|
|
3610
|
-
if (
|
|
3611
|
-
|
|
3684
|
+
let tileCompression = 0;
|
|
3685
|
+
if (jsonMetadata.compression === "gzip") {
|
|
3686
|
+
tileCompression = 2;
|
|
3612
3687
|
}
|
|
3613
3688
|
let minzoom = 0;
|
|
3614
|
-
if ("minzoom" in
|
|
3615
|
-
minzoom = +
|
|
3689
|
+
if ("minzoom" in jsonMetadata) {
|
|
3690
|
+
minzoom = +jsonMetadata.minzoom;
|
|
3616
3691
|
}
|
|
3617
3692
|
let maxzoom = 0;
|
|
3618
|
-
if ("maxzoom" in
|
|
3619
|
-
maxzoom = +
|
|
3693
|
+
if ("maxzoom" in jsonMetadata) {
|
|
3694
|
+
maxzoom = +jsonMetadata.maxzoom;
|
|
3620
3695
|
}
|
|
3621
|
-
let
|
|
3622
|
-
let
|
|
3623
|
-
let
|
|
3624
|
-
let
|
|
3625
|
-
let
|
|
3626
|
-
let
|
|
3627
|
-
let
|
|
3628
|
-
if (
|
|
3629
|
-
const split =
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3696
|
+
let centerLon = 0;
|
|
3697
|
+
let centerLat = 0;
|
|
3698
|
+
let centerZoom = 0;
|
|
3699
|
+
let minLon = -180;
|
|
3700
|
+
let minLat = -85;
|
|
3701
|
+
let maxLon = 180;
|
|
3702
|
+
let maxLat = 85;
|
|
3703
|
+
if (jsonMetadata.bounds) {
|
|
3704
|
+
const split = jsonMetadata.bounds.split(",");
|
|
3705
|
+
minLon = +split[0];
|
|
3706
|
+
minLat = +split[1];
|
|
3707
|
+
maxLon = +split[2];
|
|
3708
|
+
maxLat = +split[3];
|
|
3634
3709
|
}
|
|
3635
|
-
if (
|
|
3636
|
-
const split =
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3710
|
+
if (jsonMetadata.center) {
|
|
3711
|
+
const split = jsonMetadata.center.split(",");
|
|
3712
|
+
centerLon = +split[0];
|
|
3713
|
+
centerLat = +split[1];
|
|
3714
|
+
centerZoom = +split[2];
|
|
3640
3715
|
}
|
|
3641
3716
|
const header = {
|
|
3642
3717
|
specVersion: dataview.getUint16(2, true),
|
|
3643
|
-
rootDirectoryOffset: 10 +
|
|
3644
|
-
rootDirectoryLength:
|
|
3718
|
+
rootDirectoryOffset: 10 + jsonSize,
|
|
3719
|
+
rootDirectoryLength: rootEntries * 17,
|
|
3645
3720
|
jsonMetadataOffset: 10,
|
|
3646
|
-
jsonMetadataLength:
|
|
3721
|
+
jsonMetadataLength: jsonSize,
|
|
3647
3722
|
leafDirectoryOffset: 0,
|
|
3648
3723
|
leafDirectoryLength: void 0,
|
|
3649
3724
|
tileDataOffset: 0,
|
|
@@ -3653,17 +3728,17 @@ var __exports__ = (() => {
|
|
|
3653
3728
|
numTileContents: 0,
|
|
3654
3729
|
clustered: false,
|
|
3655
3730
|
internalCompression: 1,
|
|
3656
|
-
tileCompression
|
|
3731
|
+
tileCompression,
|
|
3657
3732
|
tileType: 1,
|
|
3658
3733
|
minZoom: minzoom,
|
|
3659
3734
|
maxZoom: maxzoom,
|
|
3660
|
-
minLon
|
|
3661
|
-
minLat
|
|
3662
|
-
maxLon
|
|
3663
|
-
maxLat
|
|
3664
|
-
centerZoom
|
|
3665
|
-
centerLon
|
|
3666
|
-
centerLat
|
|
3735
|
+
minLon,
|
|
3736
|
+
minLat,
|
|
3737
|
+
maxLon,
|
|
3738
|
+
maxLat,
|
|
3739
|
+
centerZoom,
|
|
3740
|
+
centerLon,
|
|
3741
|
+
centerLat,
|
|
3667
3742
|
etag: resp.etag
|
|
3668
3743
|
};
|
|
3669
3744
|
return header;
|
|
@@ -3671,59 +3746,59 @@ var __exports__ = (() => {
|
|
|
3671
3746
|
}
|
|
3672
3747
|
function getZxy(header, source, cache, z, x3, y2, signal) {
|
|
3673
3748
|
return __async(this, null, function* () {
|
|
3674
|
-
let
|
|
3749
|
+
let rootDir = yield cache.getArrayBuffer(
|
|
3675
3750
|
source,
|
|
3676
3751
|
header.rootDirectoryOffset,
|
|
3677
3752
|
header.rootDirectoryLength,
|
|
3678
3753
|
header
|
|
3679
3754
|
);
|
|
3680
3755
|
if (header.specVersion === 1) {
|
|
3681
|
-
|
|
3756
|
+
rootDir = sortDir(rootDir);
|
|
3682
3757
|
}
|
|
3683
|
-
const entry = queryTile(new DataView(
|
|
3758
|
+
const entry = queryTile(new DataView(rootDir), z, x3, y2);
|
|
3684
3759
|
if (entry) {
|
|
3685
3760
|
const resp = yield source.getBytes(entry.offset, entry.length, signal);
|
|
3686
|
-
let
|
|
3687
|
-
const view = new DataView(
|
|
3688
|
-
if (view.getUint8(0)
|
|
3689
|
-
|
|
3761
|
+
let tileData = resp.data;
|
|
3762
|
+
const view = new DataView(tileData);
|
|
3763
|
+
if (view.getUint8(0) === 31 && view.getUint8(1) === 139) {
|
|
3764
|
+
tileData = decompressSync(new Uint8Array(tileData));
|
|
3690
3765
|
}
|
|
3691
3766
|
return {
|
|
3692
|
-
data:
|
|
3767
|
+
data: tileData
|
|
3693
3768
|
};
|
|
3694
3769
|
}
|
|
3695
|
-
const leafcoords = deriveLeaf(new DataView(
|
|
3770
|
+
const leafcoords = deriveLeaf(new DataView(rootDir), { z, x: x3, y: y2 });
|
|
3696
3771
|
if (leafcoords) {
|
|
3697
|
-
const
|
|
3698
|
-
new DataView(
|
|
3772
|
+
const leafdirEntry = queryLeafdir(
|
|
3773
|
+
new DataView(rootDir),
|
|
3699
3774
|
leafcoords.z,
|
|
3700
3775
|
leafcoords.x,
|
|
3701
3776
|
leafcoords.y
|
|
3702
3777
|
);
|
|
3703
|
-
if (
|
|
3704
|
-
let
|
|
3778
|
+
if (leafdirEntry) {
|
|
3779
|
+
let leafDir = yield cache.getArrayBuffer(
|
|
3705
3780
|
source,
|
|
3706
|
-
|
|
3707
|
-
|
|
3781
|
+
leafdirEntry.offset,
|
|
3782
|
+
leafdirEntry.length,
|
|
3708
3783
|
header
|
|
3709
3784
|
);
|
|
3710
3785
|
if (header.specVersion === 1) {
|
|
3711
|
-
|
|
3786
|
+
leafDir = sortDir(leafDir);
|
|
3712
3787
|
}
|
|
3713
|
-
const
|
|
3714
|
-
if (
|
|
3788
|
+
const tileEntry = queryTile(new DataView(leafDir), z, x3, y2);
|
|
3789
|
+
if (tileEntry) {
|
|
3715
3790
|
const resp = yield source.getBytes(
|
|
3716
|
-
|
|
3717
|
-
|
|
3791
|
+
tileEntry.offset,
|
|
3792
|
+
tileEntry.length,
|
|
3718
3793
|
signal
|
|
3719
3794
|
);
|
|
3720
|
-
let
|
|
3721
|
-
const view = new DataView(
|
|
3722
|
-
if (view.getUint8(0)
|
|
3723
|
-
|
|
3795
|
+
let tileData = resp.data;
|
|
3796
|
+
const view = new DataView(tileData);
|
|
3797
|
+
if (view.getUint8(0) === 31 && view.getUint8(1) === 139) {
|
|
3798
|
+
tileData = decompressSync(new Uint8Array(tileData));
|
|
3724
3799
|
}
|
|
3725
3800
|
return {
|
|
3726
|
-
data:
|
|
3801
|
+
data: tileData
|
|
3727
3802
|
};
|
|
3728
3803
|
}
|
|
3729
3804
|
}
|
|
@@ -3739,7 +3814,7 @@ var __exports__ = (() => {
|
|
|
3739
3814
|
let loaded = false;
|
|
3740
3815
|
let mimeType = "";
|
|
3741
3816
|
const cls = L.GridLayer.extend({
|
|
3742
|
-
createTile:
|
|
3817
|
+
createTile: (coord, done) => {
|
|
3743
3818
|
const el = document.createElement("img");
|
|
3744
3819
|
const controller = new AbortController();
|
|
3745
3820
|
const signal = controller.signal;
|
|
@@ -3748,17 +3823,17 @@ var __exports__ = (() => {
|
|
|
3748
3823
|
};
|
|
3749
3824
|
if (!loaded) {
|
|
3750
3825
|
source.getHeader().then((header) => {
|
|
3751
|
-
if (header.tileType
|
|
3826
|
+
if (header.tileType === 1) {
|
|
3752
3827
|
console.error(
|
|
3753
3828
|
"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
3829
|
);
|
|
3755
|
-
} else if (header.tileType
|
|
3830
|
+
} else if (header.tileType === 2) {
|
|
3756
3831
|
mimeType = "image/png";
|
|
3757
|
-
} else if (header.tileType
|
|
3832
|
+
} else if (header.tileType === 3) {
|
|
3758
3833
|
mimeType = "image/jpeg";
|
|
3759
|
-
} else if (header.tileType
|
|
3834
|
+
} else if (header.tileType === 4) {
|
|
3760
3835
|
mimeType = "image/webp";
|
|
3761
|
-
} else if (header.tileType
|
|
3836
|
+
} else if (header.tileType === 5) {
|
|
3762
3837
|
mimeType = "image/avif";
|
|
3763
3838
|
}
|
|
3764
3839
|
});
|
|
@@ -3769,8 +3844,8 @@ var __exports__ = (() => {
|
|
|
3769
3844
|
const blob = new Blob([arr.data], { type: mimeType });
|
|
3770
3845
|
const imageUrl = window.URL.createObjectURL(blob);
|
|
3771
3846
|
el.src = imageUrl;
|
|
3772
|
-
el.cancel =
|
|
3773
|
-
done(
|
|
3847
|
+
el.cancel = void 0;
|
|
3848
|
+
done(void 0, el);
|
|
3774
3849
|
}
|
|
3775
3850
|
}).catch((e) => {
|
|
3776
3851
|
if (e.name !== "AbortError") {
|
|
@@ -3799,82 +3874,77 @@ var __exports__ = (() => {
|
|
|
3799
3874
|
});
|
|
3800
3875
|
return new cls(options);
|
|
3801
3876
|
};
|
|
3877
|
+
var v3compat = (v4) => (requestParameters, arg2) => {
|
|
3878
|
+
if (arg2 instanceof AbortController) {
|
|
3879
|
+
return v4(requestParameters, arg2);
|
|
3880
|
+
}
|
|
3881
|
+
const abortController = new AbortController();
|
|
3882
|
+
v4(requestParameters, abortController).then(
|
|
3883
|
+
(result) => {
|
|
3884
|
+
return arg2(
|
|
3885
|
+
void 0,
|
|
3886
|
+
result.data,
|
|
3887
|
+
result.cacheControl || "",
|
|
3888
|
+
result.expires || ""
|
|
3889
|
+
);
|
|
3890
|
+
},
|
|
3891
|
+
(err2) => {
|
|
3892
|
+
return arg2(err2);
|
|
3893
|
+
}
|
|
3894
|
+
).catch((e) => {
|
|
3895
|
+
return arg2(e);
|
|
3896
|
+
});
|
|
3897
|
+
return { cancel: () => abortController.abort() };
|
|
3898
|
+
};
|
|
3802
3899
|
var Protocol = class {
|
|
3803
3900
|
constructor() {
|
|
3804
|
-
this.
|
|
3805
|
-
if (params.type
|
|
3806
|
-
const
|
|
3807
|
-
let
|
|
3808
|
-
if (!
|
|
3809
|
-
|
|
3810
|
-
this.tiles.set(
|
|
3901
|
+
this.tilev4 = (params, abortController) => __async(this, null, function* () {
|
|
3902
|
+
if (params.type === "json") {
|
|
3903
|
+
const pmtilesUrl2 = params.url.substr(10);
|
|
3904
|
+
let instance2 = this.tiles.get(pmtilesUrl2);
|
|
3905
|
+
if (!instance2) {
|
|
3906
|
+
instance2 = new PMTiles(pmtilesUrl2);
|
|
3907
|
+
this.tiles.set(pmtilesUrl2, instance2);
|
|
3811
3908
|
}
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3909
|
+
const h = yield instance2.getHeader();
|
|
3910
|
+
return {
|
|
3911
|
+
data: {
|
|
3912
|
+
tiles: [`${params.url}/{z}/{x}/{y}`],
|
|
3815
3913
|
minzoom: h.minZoom,
|
|
3816
3914
|
maxzoom: h.maxZoom,
|
|
3817
3915
|
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
3916
|
}
|
|
3826
3917
|
};
|
|
3827
|
-
}
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
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
|
-
});
|
|
3918
|
+
}
|
|
3919
|
+
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
|
|
3920
|
+
const result = params.url.match(re);
|
|
3921
|
+
if (!result) {
|
|
3922
|
+
throw new Error("Invalid PMTiles protocol URL");
|
|
3923
|
+
}
|
|
3924
|
+
const pmtilesUrl = result[1];
|
|
3925
|
+
let instance = this.tiles.get(pmtilesUrl);
|
|
3926
|
+
if (!instance) {
|
|
3927
|
+
instance = new PMTiles(pmtilesUrl);
|
|
3928
|
+
this.tiles.set(pmtilesUrl, instance);
|
|
3929
|
+
}
|
|
3930
|
+
const z = result[2];
|
|
3931
|
+
const x3 = result[3];
|
|
3932
|
+
const y2 = result[4];
|
|
3933
|
+
const header = yield instance.getHeader();
|
|
3934
|
+
const resp = yield instance == null ? void 0 : instance.getZxy(+z, +x3, +y2, abortController.signal);
|
|
3935
|
+
if (resp) {
|
|
3873
3936
|
return {
|
|
3874
|
-
|
|
3937
|
+
data: new Uint8Array(resp.data),
|
|
3938
|
+
cacheControl: resp.cacheControl,
|
|
3939
|
+
expires: resp.expires
|
|
3875
3940
|
};
|
|
3876
3941
|
}
|
|
3877
|
-
|
|
3942
|
+
if (header.tileType === 1) {
|
|
3943
|
+
return { data: new Uint8Array() };
|
|
3944
|
+
}
|
|
3945
|
+
return { data: null };
|
|
3946
|
+
});
|
|
3947
|
+
this.tile = v3compat(this.tilev4);
|
|
3878
3948
|
this.tiles = /* @__PURE__ */ new Map();
|
|
3879
3949
|
}
|
|
3880
3950
|
add(p) {
|
|
@@ -3889,9 +3959,8 @@ var __exports__ = (() => {
|
|
|
3889
3959
|
}
|
|
3890
3960
|
function readVarintRemainder(l, p) {
|
|
3891
3961
|
const buf = p.buf;
|
|
3892
|
-
let
|
|
3893
|
-
|
|
3894
|
-
h = (b & 112) >> 4;
|
|
3962
|
+
let b = buf[p.pos++];
|
|
3963
|
+
let h = (b & 112) >> 4;
|
|
3895
3964
|
if (b < 128)
|
|
3896
3965
|
return toNum(l, h);
|
|
3897
3966
|
b = buf[p.pos++];
|
|
@@ -3918,9 +3987,8 @@ var __exports__ = (() => {
|
|
|
3918
3987
|
}
|
|
3919
3988
|
function readVarint(p) {
|
|
3920
3989
|
const buf = p.buf;
|
|
3921
|
-
let
|
|
3922
|
-
|
|
3923
|
-
val = b & 127;
|
|
3990
|
+
let b = buf[p.pos++];
|
|
3991
|
+
let val = b & 127;
|
|
3924
3992
|
if (b < 128)
|
|
3925
3993
|
return val;
|
|
3926
3994
|
b = buf[p.pos++];
|
|
@@ -3940,8 +4008,8 @@ var __exports__ = (() => {
|
|
|
3940
4008
|
return readVarintRemainder(val, p);
|
|
3941
4009
|
}
|
|
3942
4010
|
function rotate(n, xy, rx, ry) {
|
|
3943
|
-
if (ry
|
|
3944
|
-
if (rx
|
|
4011
|
+
if (ry === 0) {
|
|
4012
|
+
if (rx === 1) {
|
|
3945
4013
|
xy[0] = n - 1 - xy[0];
|
|
3946
4014
|
xy[1] = n - 1 - xy[1];
|
|
3947
4015
|
}
|
|
@@ -3951,7 +4019,7 @@ var __exports__ = (() => {
|
|
|
3951
4019
|
}
|
|
3952
4020
|
}
|
|
3953
4021
|
function idOnLevel(z, pos) {
|
|
3954
|
-
const n =
|
|
4022
|
+
const n = __pow(2, z);
|
|
3955
4023
|
let rx = pos;
|
|
3956
4024
|
let ry = pos;
|
|
3957
4025
|
let t = pos;
|
|
@@ -4001,11 +4069,11 @@ var __exports__ = (() => {
|
|
|
4001
4069
|
if (z > 26) {
|
|
4002
4070
|
throw Error("Tile zoom level exceeds max safe number limit (26)");
|
|
4003
4071
|
}
|
|
4004
|
-
if (x3 >
|
|
4072
|
+
if (x3 > __pow(2, z) - 1 || y2 > __pow(2, z) - 1) {
|
|
4005
4073
|
throw Error("tile x/y outside zoom level bounds");
|
|
4006
4074
|
}
|
|
4007
4075
|
const acc = tzValues[z];
|
|
4008
|
-
const n =
|
|
4076
|
+
const n = __pow(2, z);
|
|
4009
4077
|
let rx = 0;
|
|
4010
4078
|
let ry = 0;
|
|
4011
4079
|
let d = 0;
|
|
@@ -4022,13 +4090,13 @@ var __exports__ = (() => {
|
|
|
4022
4090
|
}
|
|
4023
4091
|
function tileIdToZxy(i3) {
|
|
4024
4092
|
let acc = 0;
|
|
4025
|
-
|
|
4093
|
+
const z = 0;
|
|
4026
4094
|
for (let z2 = 0; z2 < 27; z2++) {
|
|
4027
|
-
const
|
|
4028
|
-
if (acc +
|
|
4095
|
+
const numTiles = (1 << z2) * (1 << z2);
|
|
4096
|
+
if (acc + numTiles > i3) {
|
|
4029
4097
|
return idOnLevel(z2, i3 - acc);
|
|
4030
4098
|
}
|
|
4031
|
-
acc +=
|
|
4099
|
+
acc += numTiles;
|
|
4032
4100
|
}
|
|
4033
4101
|
throw Error("Tile zoom level exceeds max safe number limit (26)");
|
|
4034
4102
|
}
|
|
@@ -4044,19 +4112,22 @@ var __exports__ = (() => {
|
|
|
4044
4112
|
return __async(this, null, function* () {
|
|
4045
4113
|
if (compression === 1 || compression === 0) {
|
|
4046
4114
|
return buf;
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4115
|
+
}
|
|
4116
|
+
if (compression === 2) {
|
|
4117
|
+
if (typeof globalThis.DecompressionStream === "undefined") {
|
|
4049
4118
|
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
4119
|
}
|
|
4057
|
-
|
|
4058
|
-
|
|
4120
|
+
const stream = new Response(buf).body;
|
|
4121
|
+
if (!stream) {
|
|
4122
|
+
throw Error("Failed to read response stream");
|
|
4123
|
+
}
|
|
4124
|
+
const result = stream.pipeThrough(
|
|
4125
|
+
// biome-ignore lint: needed to detect DecompressionStream in browser+node+cloudflare workers
|
|
4126
|
+
new globalThis.DecompressionStream("gzip")
|
|
4127
|
+
);
|
|
4128
|
+
return new Response(result).arrayBuffer();
|
|
4059
4129
|
}
|
|
4130
|
+
throw Error("Compression method not supported");
|
|
4060
4131
|
});
|
|
4061
4132
|
}
|
|
4062
4133
|
var TileType = /* @__PURE__ */ ((TileType22) => {
|
|
@@ -4093,7 +4164,7 @@ var __exports__ = (() => {
|
|
|
4093
4164
|
}
|
|
4094
4165
|
return null;
|
|
4095
4166
|
}
|
|
4096
|
-
var
|
|
4167
|
+
var FileSource = class {
|
|
4097
4168
|
constructor(file) {
|
|
4098
4169
|
this.file = file;
|
|
4099
4170
|
}
|
|
@@ -4109,39 +4180,65 @@ var __exports__ = (() => {
|
|
|
4109
4180
|
}
|
|
4110
4181
|
};
|
|
4111
4182
|
var FetchSource = class {
|
|
4112
|
-
constructor(url) {
|
|
4183
|
+
constructor(url, customHeaders = new Headers()) {
|
|
4113
4184
|
this.url = url;
|
|
4185
|
+
this.customHeaders = customHeaders;
|
|
4186
|
+
this.mustReload = false;
|
|
4114
4187
|
}
|
|
4115
4188
|
getKey() {
|
|
4116
4189
|
return this.url;
|
|
4117
4190
|
}
|
|
4118
|
-
|
|
4191
|
+
setHeaders(customHeaders) {
|
|
4192
|
+
this.customHeaders = customHeaders;
|
|
4193
|
+
}
|
|
4194
|
+
getBytes(offset, length2, passedSignal, etag) {
|
|
4119
4195
|
return __async(this, null, function* () {
|
|
4120
4196
|
let controller;
|
|
4121
|
-
|
|
4197
|
+
let signal;
|
|
4198
|
+
if (passedSignal) {
|
|
4199
|
+
signal = passedSignal;
|
|
4200
|
+
} else {
|
|
4122
4201
|
controller = new AbortController();
|
|
4123
4202
|
signal = controller.signal;
|
|
4124
4203
|
}
|
|
4204
|
+
const requestHeaders = new Headers(this.customHeaders);
|
|
4205
|
+
requestHeaders.set("range", `bytes=${offset}-${offset + length2 - 1}`);
|
|
4206
|
+
let cache;
|
|
4207
|
+
if (this.mustReload) {
|
|
4208
|
+
cache = "reload";
|
|
4209
|
+
}
|
|
4125
4210
|
let resp = yield fetch(this.url, {
|
|
4126
4211
|
signal,
|
|
4127
|
-
|
|
4212
|
+
cache,
|
|
4213
|
+
headers: requestHeaders
|
|
4214
|
+
//biome-ignore lint: "cache" is incompatible between cloudflare workers and browser
|
|
4128
4215
|
});
|
|
4129
|
-
if (
|
|
4130
|
-
const
|
|
4131
|
-
if (!
|
|
4216
|
+
if (offset === 0 && resp.status === 416) {
|
|
4217
|
+
const contentRange = resp.headers.get("Content-Range");
|
|
4218
|
+
if (!contentRange || !contentRange.startsWith("bytes */")) {
|
|
4132
4219
|
throw Error("Missing content-length on 416 response");
|
|
4133
4220
|
}
|
|
4134
|
-
const
|
|
4221
|
+
const actualLength = +contentRange.substr(8);
|
|
4135
4222
|
resp = yield fetch(this.url, {
|
|
4136
4223
|
signal,
|
|
4137
|
-
|
|
4224
|
+
cache: "reload",
|
|
4225
|
+
headers: { range: `bytes=0-${actualLength - 1}` }
|
|
4226
|
+
//biome-ignore lint: "cache" is incompatible between cloudflare workers and browser
|
|
4138
4227
|
});
|
|
4139
4228
|
}
|
|
4229
|
+
let newEtag = resp.headers.get("Etag");
|
|
4230
|
+
if (newEtag == null ? void 0 : newEtag.startsWith("W/")) {
|
|
4231
|
+
newEtag = null;
|
|
4232
|
+
}
|
|
4233
|
+
if (resp.status === 416 || etag && newEtag && newEtag !== etag) {
|
|
4234
|
+
this.mustReload = true;
|
|
4235
|
+
throw new EtagMismatch(etag);
|
|
4236
|
+
}
|
|
4140
4237
|
if (resp.status >= 300) {
|
|
4141
|
-
throw Error(
|
|
4238
|
+
throw Error(`Bad response code: ${resp.status}`);
|
|
4142
4239
|
}
|
|
4143
|
-
const
|
|
4144
|
-
if (resp.status === 200 && (!
|
|
4240
|
+
const contentLength = resp.headers.get("Content-Length");
|
|
4241
|
+
if (resp.status === 200 && (!contentLength || +contentLength > length2)) {
|
|
4145
4242
|
if (controller)
|
|
4146
4243
|
controller.abort();
|
|
4147
4244
|
throw Error(
|
|
@@ -4151,7 +4248,7 @@ var __exports__ = (() => {
|
|
|
4151
4248
|
const a = yield resp.arrayBuffer();
|
|
4152
4249
|
return {
|
|
4153
4250
|
data: a,
|
|
4154
|
-
etag:
|
|
4251
|
+
etag: newEtag || void 0,
|
|
4155
4252
|
cacheControl: resp.headers.get("Cache-Control") || void 0,
|
|
4156
4253
|
expires: resp.headers.get("Expires") || void 0
|
|
4157
4254
|
};
|
|
@@ -4161,18 +4258,18 @@ var __exports__ = (() => {
|
|
|
4161
4258
|
function getUint64(v, offset) {
|
|
4162
4259
|
const wh = v.getUint32(offset + 4, true);
|
|
4163
4260
|
const wl = v.getUint32(offset + 0, true);
|
|
4164
|
-
return wh *
|
|
4261
|
+
return wh * __pow(2, 32) + wl;
|
|
4165
4262
|
}
|
|
4166
4263
|
function bytesToHeader(bytes, etag) {
|
|
4167
4264
|
const v = new DataView(bytes);
|
|
4168
|
-
const
|
|
4169
|
-
if (
|
|
4265
|
+
const specVersion = v.getUint8(7);
|
|
4266
|
+
if (specVersion > 3) {
|
|
4170
4267
|
throw Error(
|
|
4171
|
-
`Archive is spec version ${
|
|
4268
|
+
`Archive is spec version ${specVersion} but this library supports up to spec version 3`
|
|
4172
4269
|
);
|
|
4173
4270
|
}
|
|
4174
4271
|
return {
|
|
4175
|
-
specVersion
|
|
4272
|
+
specVersion,
|
|
4176
4273
|
rootDirectoryOffset: getUint64(v, 8),
|
|
4177
4274
|
rootDirectoryLength: getUint64(v, 16),
|
|
4178
4275
|
jsonMetadataOffset: getUint64(v, 24),
|
|
@@ -4233,7 +4330,8 @@ var __exports__ = (() => {
|
|
|
4233
4330
|
"PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"
|
|
4234
4331
|
);
|
|
4235
4332
|
return 2;
|
|
4236
|
-
}
|
|
4333
|
+
}
|
|
4334
|
+
if (v.getUint16(2, true) === 1) {
|
|
4237
4335
|
console.warn(
|
|
4238
4336
|
"PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"
|
|
4239
4337
|
);
|
|
@@ -4243,7 +4341,7 @@ var __exports__ = (() => {
|
|
|
4243
4341
|
}
|
|
4244
4342
|
var EtagMismatch = class extends Error {
|
|
4245
4343
|
};
|
|
4246
|
-
function getHeaderAndRoot(source, decompress
|
|
4344
|
+
function getHeaderAndRoot(source, decompress) {
|
|
4247
4345
|
return __async(this, null, function* () {
|
|
4248
4346
|
const resp = yield source.getBytes(0, 16384);
|
|
4249
4347
|
const v = new DataView(resp.data);
|
|
@@ -4254,34 +4352,21 @@ var __exports__ = (() => {
|
|
|
4254
4352
|
return [yield v2_default.getHeader(source)];
|
|
4255
4353
|
}
|
|
4256
4354
|
const headerData = resp.data.slice(0, HEADER_SIZE_BYTES);
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
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];
|
|
4355
|
+
const header = bytesToHeader(headerData, resp.etag);
|
|
4356
|
+
const rootDirData = resp.data.slice(
|
|
4357
|
+
header.rootDirectoryOffset,
|
|
4358
|
+
header.rootDirectoryOffset + header.rootDirectoryLength
|
|
4359
|
+
);
|
|
4360
|
+
const dirKey = `${source.getKey()}|${header.etag || ""}|${header.rootDirectoryOffset}|${header.rootDirectoryLength}`;
|
|
4361
|
+
const rootDir = deserializeIndex(
|
|
4362
|
+
yield decompress(rootDirData, header.internalCompression)
|
|
4363
|
+
);
|
|
4364
|
+
return [header, [dirKey, rootDir.length, rootDir]];
|
|
4277
4365
|
});
|
|
4278
4366
|
}
|
|
4279
4367
|
function getDirectory(source, decompress, offset, length2, header) {
|
|
4280
4368
|
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
|
-
}
|
|
4369
|
+
const resp = yield source.getBytes(offset, length2, void 0, header.etag);
|
|
4285
4370
|
const data = yield decompress(resp.data, header.internalCompression);
|
|
4286
4371
|
const directory = deserializeIndex(data);
|
|
4287
4372
|
if (directory.length === 0) {
|
|
@@ -4295,23 +4380,18 @@ var __exports__ = (() => {
|
|
|
4295
4380
|
this.cache = /* @__PURE__ */ new Map();
|
|
4296
4381
|
this.maxCacheEntries = maxCacheEntries;
|
|
4297
4382
|
this.counter = 1;
|
|
4298
|
-
this.prefetch = prefetch;
|
|
4299
4383
|
this.decompress = decompress;
|
|
4300
4384
|
}
|
|
4301
|
-
getHeader(source
|
|
4385
|
+
getHeader(source) {
|
|
4302
4386
|
return __async(this, null, function* () {
|
|
4303
4387
|
const cacheKey = source.getKey();
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4388
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4389
|
+
if (cacheValue) {
|
|
4390
|
+
cacheValue.lastUsed = this.counter++;
|
|
4391
|
+
const data = cacheValue.data;
|
|
4307
4392
|
return data;
|
|
4308
4393
|
}
|
|
4309
|
-
const res = yield getHeaderAndRoot(
|
|
4310
|
-
source,
|
|
4311
|
-
this.decompress,
|
|
4312
|
-
this.prefetch,
|
|
4313
|
-
current_etag
|
|
4314
|
-
);
|
|
4394
|
+
const res = yield getHeaderAndRoot(source, this.decompress);
|
|
4315
4395
|
if (res[1]) {
|
|
4316
4396
|
this.cache.set(res[1][0], {
|
|
4317
4397
|
lastUsed: this.counter++,
|
|
@@ -4328,10 +4408,11 @@ var __exports__ = (() => {
|
|
|
4328
4408
|
}
|
|
4329
4409
|
getDirectory(source, offset, length2, header) {
|
|
4330
4410
|
return __async(this, null, function* () {
|
|
4331
|
-
const cacheKey = source.getKey()
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4411
|
+
const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
|
|
4412
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4413
|
+
if (cacheValue) {
|
|
4414
|
+
cacheValue.lastUsed = this.counter++;
|
|
4415
|
+
const data = cacheValue.data;
|
|
4335
4416
|
return data;
|
|
4336
4417
|
}
|
|
4337
4418
|
const directory = yield getDirectory(
|
|
@@ -4349,18 +4430,17 @@ var __exports__ = (() => {
|
|
|
4349
4430
|
return directory;
|
|
4350
4431
|
});
|
|
4351
4432
|
}
|
|
4433
|
+
// for v2 backwards compatibility
|
|
4352
4434
|
getArrayBuffer(source, offset, length2, header) {
|
|
4353
4435
|
return __async(this, null, function* () {
|
|
4354
|
-
const cacheKey = source.getKey()
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4436
|
+
const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
|
|
4437
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4438
|
+
if (cacheValue) {
|
|
4439
|
+
cacheValue.lastUsed = this.counter++;
|
|
4440
|
+
const data = yield cacheValue.data;
|
|
4358
4441
|
return data;
|
|
4359
4442
|
}
|
|
4360
|
-
const resp = yield source.getBytes(offset, length2);
|
|
4361
|
-
if (header.etag && header.etag !== resp.etag) {
|
|
4362
|
-
throw new EtagMismatch(header.etag);
|
|
4363
|
-
}
|
|
4443
|
+
const resp = yield source.getBytes(offset, length2, void 0, header.etag);
|
|
4364
4444
|
this.cache.set(cacheKey, {
|
|
4365
4445
|
lastUsed: this.counter++,
|
|
4366
4446
|
data: resp.data
|
|
@@ -4373,9 +4453,9 @@ var __exports__ = (() => {
|
|
|
4373
4453
|
if (this.cache.size > this.maxCacheEntries) {
|
|
4374
4454
|
let minUsed = Infinity;
|
|
4375
4455
|
let minKey = void 0;
|
|
4376
|
-
this.cache.forEach((
|
|
4377
|
-
if (
|
|
4378
|
-
minUsed =
|
|
4456
|
+
this.cache.forEach((cacheValue, key) => {
|
|
4457
|
+
if (cacheValue.lastUsed < minUsed) {
|
|
4458
|
+
minUsed = cacheValue.lastUsed;
|
|
4379
4459
|
minKey = key;
|
|
4380
4460
|
}
|
|
4381
4461
|
});
|
|
@@ -4384,31 +4464,31 @@ var __exports__ = (() => {
|
|
|
4384
4464
|
}
|
|
4385
4465
|
}
|
|
4386
4466
|
}
|
|
4387
|
-
invalidate(source
|
|
4467
|
+
invalidate(source) {
|
|
4388
4468
|
return __async(this, null, function* () {
|
|
4389
4469
|
this.cache.delete(source.getKey());
|
|
4390
|
-
yield this.getHeader(source, current_etag);
|
|
4391
4470
|
});
|
|
4392
4471
|
}
|
|
4393
4472
|
};
|
|
4394
4473
|
var SharedPromiseCache = class {
|
|
4395
4474
|
constructor(maxCacheEntries = 100, prefetch = true, decompress = defaultDecompress) {
|
|
4396
4475
|
this.cache = /* @__PURE__ */ new Map();
|
|
4476
|
+
this.invalidations = /* @__PURE__ */ new Map();
|
|
4397
4477
|
this.maxCacheEntries = maxCacheEntries;
|
|
4398
4478
|
this.counter = 1;
|
|
4399
|
-
this.prefetch = prefetch;
|
|
4400
4479
|
this.decompress = decompress;
|
|
4401
4480
|
}
|
|
4402
|
-
getHeader(source
|
|
4481
|
+
getHeader(source) {
|
|
4403
4482
|
return __async(this, null, function* () {
|
|
4404
4483
|
const cacheKey = source.getKey();
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4484
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4485
|
+
if (cacheValue) {
|
|
4486
|
+
cacheValue.lastUsed = this.counter++;
|
|
4487
|
+
const data = yield cacheValue.data;
|
|
4408
4488
|
return data;
|
|
4409
4489
|
}
|
|
4410
4490
|
const p = new Promise((resolve, reject) => {
|
|
4411
|
-
getHeaderAndRoot(source, this.decompress
|
|
4491
|
+
getHeaderAndRoot(source, this.decompress).then((res) => {
|
|
4412
4492
|
if (res[1]) {
|
|
4413
4493
|
this.cache.set(res[1][0], {
|
|
4414
4494
|
lastUsed: this.counter++,
|
|
@@ -4427,10 +4507,11 @@ var __exports__ = (() => {
|
|
|
4427
4507
|
}
|
|
4428
4508
|
getDirectory(source, offset, length2, header) {
|
|
4429
4509
|
return __async(this, null, function* () {
|
|
4430
|
-
const cacheKey = source.getKey()
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4510
|
+
const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
|
|
4511
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4512
|
+
if (cacheValue) {
|
|
4513
|
+
cacheValue.lastUsed = this.counter++;
|
|
4514
|
+
const data = yield cacheValue.data;
|
|
4434
4515
|
return data;
|
|
4435
4516
|
}
|
|
4436
4517
|
const p = new Promise((resolve, reject) => {
|
|
@@ -4445,19 +4526,18 @@ var __exports__ = (() => {
|
|
|
4445
4526
|
return p;
|
|
4446
4527
|
});
|
|
4447
4528
|
}
|
|
4529
|
+
// for v2 backwards compatibility
|
|
4448
4530
|
getArrayBuffer(source, offset, length2, header) {
|
|
4449
4531
|
return __async(this, null, function* () {
|
|
4450
|
-
const cacheKey = source.getKey()
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4532
|
+
const cacheKey = `${source.getKey()}|${header.etag || ""}|${offset}|${length2}`;
|
|
4533
|
+
const cacheValue = this.cache.get(cacheKey);
|
|
4534
|
+
if (cacheValue) {
|
|
4535
|
+
cacheValue.lastUsed = this.counter++;
|
|
4536
|
+
const data = yield cacheValue.data;
|
|
4454
4537
|
return data;
|
|
4455
4538
|
}
|
|
4456
4539
|
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
|
-
}
|
|
4540
|
+
source.getBytes(offset, length2, void 0, header.etag).then((resp) => {
|
|
4461
4541
|
resolve(resp.data);
|
|
4462
4542
|
if (this.cache.has(cacheKey)) {
|
|
4463
4543
|
}
|
|
@@ -4474,23 +4554,33 @@ var __exports__ = (() => {
|
|
|
4474
4554
|
if (this.cache.size >= this.maxCacheEntries) {
|
|
4475
4555
|
let minUsed = Infinity;
|
|
4476
4556
|
let minKey = void 0;
|
|
4477
|
-
this.cache.forEach(
|
|
4478
|
-
(
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
minKey = key;
|
|
4482
|
-
}
|
|
4557
|
+
this.cache.forEach((cacheValue, key) => {
|
|
4558
|
+
if (cacheValue.lastUsed < minUsed) {
|
|
4559
|
+
minUsed = cacheValue.lastUsed;
|
|
4560
|
+
minKey = key;
|
|
4483
4561
|
}
|
|
4484
|
-
);
|
|
4562
|
+
});
|
|
4485
4563
|
if (minKey) {
|
|
4486
4564
|
this.cache.delete(minKey);
|
|
4487
4565
|
}
|
|
4488
4566
|
}
|
|
4489
4567
|
}
|
|
4490
|
-
invalidate(source
|
|
4568
|
+
invalidate(source) {
|
|
4491
4569
|
return __async(this, null, function* () {
|
|
4570
|
+
const key = source.getKey();
|
|
4571
|
+
if (this.invalidations.get(key)) {
|
|
4572
|
+
return yield this.invalidations.get(key);
|
|
4573
|
+
}
|
|
4492
4574
|
this.cache.delete(source.getKey());
|
|
4493
|
-
|
|
4575
|
+
const p = new Promise((resolve, reject) => {
|
|
4576
|
+
this.getHeader(source).then((h) => {
|
|
4577
|
+
resolve();
|
|
4578
|
+
this.invalidations.delete(key);
|
|
4579
|
+
}).catch((e) => {
|
|
4580
|
+
reject(e);
|
|
4581
|
+
});
|
|
4582
|
+
});
|
|
4583
|
+
this.invalidations.set(key, p);
|
|
4494
4584
|
});
|
|
4495
4585
|
}
|
|
4496
4586
|
};
|
|
@@ -4512,14 +4602,19 @@ var __exports__ = (() => {
|
|
|
4512
4602
|
this.cache = new SharedPromiseCache();
|
|
4513
4603
|
}
|
|
4514
4604
|
}
|
|
4605
|
+
/**
|
|
4606
|
+
* Return the header of the archive,
|
|
4607
|
+
* including information such as tile type, min/max zoom, bounds, and summary statistics.
|
|
4608
|
+
*/
|
|
4515
4609
|
getHeader() {
|
|
4516
4610
|
return __async(this, null, function* () {
|
|
4517
4611
|
return yield this.cache.getHeader(this.source);
|
|
4518
4612
|
});
|
|
4519
4613
|
}
|
|
4614
|
+
/** @hidden */
|
|
4520
4615
|
getZxyAttempt(z, x3, y2, signal) {
|
|
4521
4616
|
return __async(this, null, function* () {
|
|
4522
|
-
const
|
|
4617
|
+
const tileId = zxyToTileId(z, x3, y2);
|
|
4523
4618
|
const header = yield this.cache.getHeader(this.source);
|
|
4524
4619
|
if (header.specVersion < 3) {
|
|
4525
4620
|
return v2_default.getZxy(header, this.source, this.cache, z, x3, y2, signal);
|
|
@@ -4527,35 +4622,32 @@ var __exports__ = (() => {
|
|
|
4527
4622
|
if (z < header.minZoom || z > header.maxZoom) {
|
|
4528
4623
|
return void 0;
|
|
4529
4624
|
}
|
|
4530
|
-
let
|
|
4531
|
-
let
|
|
4625
|
+
let dO = header.rootDirectoryOffset;
|
|
4626
|
+
let dL = header.rootDirectoryLength;
|
|
4532
4627
|
for (let depth = 0; depth <= 3; depth++) {
|
|
4533
4628
|
const directory = yield this.cache.getDirectory(
|
|
4534
4629
|
this.source,
|
|
4535
|
-
|
|
4536
|
-
|
|
4630
|
+
dO,
|
|
4631
|
+
dL,
|
|
4537
4632
|
header
|
|
4538
4633
|
);
|
|
4539
|
-
const entry = findTile(directory,
|
|
4634
|
+
const entry = findTile(directory, tileId);
|
|
4540
4635
|
if (entry) {
|
|
4541
4636
|
if (entry.runLength > 0) {
|
|
4542
4637
|
const resp = yield this.source.getBytes(
|
|
4543
4638
|
header.tileDataOffset + entry.offset,
|
|
4544
4639
|
entry.length,
|
|
4545
|
-
signal
|
|
4640
|
+
signal,
|
|
4641
|
+
header.etag
|
|
4546
4642
|
);
|
|
4547
|
-
if (header.etag && header.etag !== resp.etag) {
|
|
4548
|
-
throw new EtagMismatch(resp.etag);
|
|
4549
|
-
}
|
|
4550
4643
|
return {
|
|
4551
4644
|
data: yield this.decompress(resp.data, header.tileCompression),
|
|
4552
4645
|
cacheControl: resp.cacheControl,
|
|
4553
4646
|
expires: resp.expires
|
|
4554
4647
|
};
|
|
4555
|
-
} else {
|
|
4556
|
-
d_o = header.leafDirectoryOffset + entry.offset;
|
|
4557
|
-
d_l = entry.length;
|
|
4558
4648
|
}
|
|
4649
|
+
dO = header.leafDirectoryOffset + entry.offset;
|
|
4650
|
+
dL = entry.length;
|
|
4559
4651
|
} else {
|
|
4560
4652
|
return void 0;
|
|
4561
4653
|
}
|
|
@@ -4563,30 +4655,34 @@ var __exports__ = (() => {
|
|
|
4563
4655
|
throw Error("Maximum directory depth exceeded");
|
|
4564
4656
|
});
|
|
4565
4657
|
}
|
|
4658
|
+
/**
|
|
4659
|
+
* Primary method to get a single tile bytes from an archive.
|
|
4660
|
+
*
|
|
4661
|
+
* Returns undefined if the tile does not exist in the archive.
|
|
4662
|
+
*/
|
|
4566
4663
|
getZxy(z, x3, y2, signal) {
|
|
4567
4664
|
return __async(this, null, function* () {
|
|
4568
4665
|
try {
|
|
4569
4666
|
return yield this.getZxyAttempt(z, x3, y2, signal);
|
|
4570
4667
|
} catch (e) {
|
|
4571
4668
|
if (e instanceof EtagMismatch) {
|
|
4572
|
-
this.cache.invalidate(this.source
|
|
4669
|
+
this.cache.invalidate(this.source);
|
|
4573
4670
|
return yield this.getZxyAttempt(z, x3, y2, signal);
|
|
4574
|
-
} else {
|
|
4575
|
-
throw e;
|
|
4576
4671
|
}
|
|
4672
|
+
throw e;
|
|
4577
4673
|
}
|
|
4578
4674
|
});
|
|
4579
4675
|
}
|
|
4676
|
+
/** @hidden */
|
|
4580
4677
|
getMetadataAttempt() {
|
|
4581
4678
|
return __async(this, null, function* () {
|
|
4582
4679
|
const header = yield this.cache.getHeader(this.source);
|
|
4583
4680
|
const resp = yield this.source.getBytes(
|
|
4584
4681
|
header.jsonMetadataOffset,
|
|
4585
|
-
header.jsonMetadataLength
|
|
4682
|
+
header.jsonMetadataLength,
|
|
4683
|
+
void 0,
|
|
4684
|
+
header.etag
|
|
4586
4685
|
);
|
|
4587
|
-
if (header.etag && header.etag !== resp.etag) {
|
|
4588
|
-
throw new EtagMismatch(resp.etag);
|
|
4589
|
-
}
|
|
4590
4686
|
const decompressed = yield this.decompress(
|
|
4591
4687
|
resp.data,
|
|
4592
4688
|
header.internalCompression
|
|
@@ -4595,27 +4691,28 @@ var __exports__ = (() => {
|
|
|
4595
4691
|
return JSON.parse(dec.decode(decompressed));
|
|
4596
4692
|
});
|
|
4597
4693
|
}
|
|
4694
|
+
/**
|
|
4695
|
+
* Return the arbitrary JSON metadata of the archive.
|
|
4696
|
+
*/
|
|
4598
4697
|
getMetadata() {
|
|
4599
4698
|
return __async(this, null, function* () {
|
|
4600
4699
|
try {
|
|
4601
4700
|
return yield this.getMetadataAttempt();
|
|
4602
4701
|
} catch (e) {
|
|
4603
4702
|
if (e instanceof EtagMismatch) {
|
|
4604
|
-
this.cache.invalidate(this.source
|
|
4703
|
+
this.cache.invalidate(this.source);
|
|
4605
4704
|
return yield this.getMetadataAttempt();
|
|
4606
|
-
} else {
|
|
4607
|
-
throw e;
|
|
4608
4705
|
}
|
|
4706
|
+
throw e;
|
|
4609
4707
|
}
|
|
4610
4708
|
});
|
|
4611
4709
|
}
|
|
4612
4710
|
};
|
|
4613
4711
|
|
|
4614
4712
|
// src/lib/parse-pmtiles.ts
|
|
4615
|
-
var {
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
function parsePMTilesHeader(header, pmtilesMetadata, options, loadOptions) {
|
|
4713
|
+
var { TileType: TileType2 } = dist_exports;
|
|
4714
|
+
function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {
|
|
4715
|
+
const pmtilesMetadata = pmmetadata;
|
|
4619
4716
|
let tilejson = null;
|
|
4620
4717
|
if (pmtilesMetadata) {
|
|
4621
4718
|
try {
|
|
@@ -4640,7 +4737,10 @@ var __exports__ = (() => {
|
|
|
4640
4737
|
tileMIMEType: decodeTileType(header.tileType),
|
|
4641
4738
|
minZoom: header.minZoom,
|
|
4642
4739
|
maxZoom: header.maxZoom,
|
|
4643
|
-
boundingBox: [
|
|
4740
|
+
boundingBox: [
|
|
4741
|
+
[header.minLon, header.minLat],
|
|
4742
|
+
[header.maxLon, header.maxLat]
|
|
4743
|
+
],
|
|
4644
4744
|
center: [header.centerLon, header.centerLat],
|
|
4645
4745
|
centerZoom: header.centerZoom,
|
|
4646
4746
|
etag: header.etag
|
|
@@ -4677,6 +4777,7 @@ var __exports__ = (() => {
|
|
|
4677
4777
|
this.blob = blob;
|
|
4678
4778
|
this.key = key;
|
|
4679
4779
|
}
|
|
4780
|
+
// TODO - how is this used?
|
|
4680
4781
|
getKey() {
|
|
4681
4782
|
return this.blob.url || "";
|
|
4682
4783
|
}
|
|
@@ -4685,18 +4786,19 @@ var __exports__ = (() => {
|
|
|
4685
4786
|
const data = await slice.arrayBuffer();
|
|
4686
4787
|
return {
|
|
4687
4788
|
data
|
|
4789
|
+
// etag: response.headers.get('ETag') || undefined,
|
|
4790
|
+
// cacheControl: response.headers.get('Cache-Control') || undefined,
|
|
4791
|
+
// expires: response.headers.get('Expires') || undefined
|
|
4688
4792
|
};
|
|
4689
4793
|
}
|
|
4690
4794
|
};
|
|
4691
4795
|
|
|
4692
4796
|
// src/pmtiles-source.ts
|
|
4693
|
-
var {
|
|
4694
|
-
PMTiles: PMTiles2
|
|
4695
|
-
} = dist_exports;
|
|
4797
|
+
var { PMTiles: PMTiles2 } = dist_exports;
|
|
4696
4798
|
var PMTilesSource = class extends DataSource {
|
|
4697
|
-
mimeType = null;
|
|
4698
4799
|
constructor(props) {
|
|
4699
4800
|
super(props);
|
|
4801
|
+
this.mimeType = null;
|
|
4700
4802
|
this.props = props;
|
|
4701
4803
|
const url = typeof props.url === "string" ? resolvePath(props.url) : new BlobSource(props.url, "pmtiles");
|
|
4702
4804
|
this.data = props.url;
|
|
@@ -4707,9 +4809,12 @@ var __exports__ = (() => {
|
|
|
4707
4809
|
async getMetadata() {
|
|
4708
4810
|
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
4709
4811
|
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
4710
|
-
const metadata = parsePMTilesHeader(
|
|
4711
|
-
|
|
4712
|
-
|
|
4812
|
+
const metadata = parsePMTilesHeader(
|
|
4813
|
+
pmtilesHeader,
|
|
4814
|
+
pmtilesMetadata,
|
|
4815
|
+
{ includeFormatHeader: false },
|
|
4816
|
+
this.loadOptions
|
|
4817
|
+
);
|
|
4713
4818
|
if (this.props.attributions) {
|
|
4714
4819
|
metadata.attributions = [...this.props.attributions, ...metadata.attributions || []];
|
|
4715
4820
|
}
|
|
@@ -4719,11 +4824,7 @@ var __exports__ = (() => {
|
|
|
4719
4824
|
return metadata;
|
|
4720
4825
|
}
|
|
4721
4826
|
async getTile(tileParams) {
|
|
4722
|
-
const {
|
|
4723
|
-
x: x3,
|
|
4724
|
-
y: y2,
|
|
4725
|
-
zoom: z
|
|
4726
|
-
} = tileParams;
|
|
4827
|
+
const { x: x3, y: y2, zoom: z } = tileParams;
|
|
4727
4828
|
const rangeResponse = await this.pmtiles.getZxy(z, x3, y2);
|
|
4728
4829
|
const arrayBuffer = rangeResponse?.data;
|
|
4729
4830
|
if (!arrayBuffer) {
|
|
@@ -4731,45 +4832,31 @@ var __exports__ = (() => {
|
|
|
4731
4832
|
}
|
|
4732
4833
|
return arrayBuffer;
|
|
4733
4834
|
}
|
|
4835
|
+
// Tile Source interface implementation: deck.gl compatible API
|
|
4836
|
+
// TODO - currently only handles image tiles, not vector tiles
|
|
4734
4837
|
async getTileData(tileParams) {
|
|
4735
|
-
const {
|
|
4736
|
-
x: x3,
|
|
4737
|
-
y: y2,
|
|
4738
|
-
z
|
|
4739
|
-
} = tileParams.index;
|
|
4838
|
+
const { x: x3, y: y2, z } = tileParams.index;
|
|
4740
4839
|
const metadata = await this.metadata;
|
|
4741
4840
|
switch (metadata.tileMIMEType) {
|
|
4742
4841
|
case "application/vnd.mapbox-vector-tile":
|
|
4743
|
-
return await this.getVectorTile({
|
|
4744
|
-
x: x3,
|
|
4745
|
-
y: y2,
|
|
4746
|
-
zoom: z,
|
|
4747
|
-
layers: []
|
|
4748
|
-
});
|
|
4842
|
+
return await this.getVectorTile({ x: x3, y: y2, zoom: z, layers: [] });
|
|
4749
4843
|
default:
|
|
4750
|
-
return await this.getImageTile({
|
|
4751
|
-
x: x3,
|
|
4752
|
-
y: y2,
|
|
4753
|
-
zoom: z,
|
|
4754
|
-
layers: []
|
|
4755
|
-
});
|
|
4844
|
+
return await this.getImageTile({ x: x3, y: y2, zoom: z, layers: [] });
|
|
4756
4845
|
}
|
|
4757
4846
|
}
|
|
4847
|
+
// ImageTileSource interface implementation
|
|
4758
4848
|
async getImageTile(tileParams) {
|
|
4759
4849
|
const arrayBuffer = await this.getTile(tileParams);
|
|
4760
4850
|
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
4761
4851
|
}
|
|
4852
|
+
// VectorTileSource interface implementation
|
|
4762
4853
|
async getVectorTile(tileParams) {
|
|
4763
4854
|
const arrayBuffer = await this.getTile(tileParams);
|
|
4764
4855
|
const loadOptions = {
|
|
4765
4856
|
shape: "geojson-table",
|
|
4766
4857
|
mvt: {
|
|
4767
4858
|
coordinates: "wgs84",
|
|
4768
|
-
tileIndex: {
|
|
4769
|
-
x: tileParams.x,
|
|
4770
|
-
y: tileParams.y,
|
|
4771
|
-
z: tileParams.zoom
|
|
4772
|
-
},
|
|
4859
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
|
|
4773
4860
|
...this.loadOptions?.mvt
|
|
4774
4861
|
},
|
|
4775
4862
|
...this.loadOptions
|
|
@@ -4777,7 +4864,7 @@ var __exports__ = (() => {
|
|
|
4777
4864
|
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
4778
4865
|
}
|
|
4779
4866
|
};
|
|
4780
|
-
return __toCommonJS(
|
|
4867
|
+
return __toCommonJS(bundle_exports);
|
|
4781
4868
|
})();
|
|
4782
4869
|
/*! Bundled license information:
|
|
4783
4870
|
|