@loaders.gl/pmtiles 4.3.0-alpha.2 → 4.3.0-alpha.4
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 +382 -246
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +68 -8
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- 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 +1 -2
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +7 -0
- package/dist/pmtiles-loader.d.ts +28 -0
- package/dist/pmtiles-loader.d.ts.map +1 -0
- package/dist/pmtiles-loader.js +47 -0
- package/dist/pmtiles-source.d.ts +29 -24
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/pmtiles-source.js +15 -10
- package/dist/source-info.d.ts +25 -0
- package/dist/source-info.d.ts.map +1 -0
- package/dist/source-info.js +4 -0
- package/package.json +6 -6
- package/src/index.ts +7 -2
- package/src/lib/parse-pmtiles.ts +2 -4
- package/src/lib/version.ts +8 -0
- package/src/pmtiles-loader.ts +65 -0
- package/src/pmtiles-source.ts +32 -36
- package/src/source-info.ts +25 -0
package/dist/dist.dev.js
CHANGED
|
@@ -793,7 +793,9 @@ var __exports__ = (() => {
|
|
|
793
793
|
// bundle.ts
|
|
794
794
|
var bundle_exports = {};
|
|
795
795
|
__export(bundle_exports, {
|
|
796
|
-
PMTilesSource: () => PMTilesSource
|
|
796
|
+
PMTilesSource: () => PMTilesSource,
|
|
797
|
+
PMTilesTileSource: () => PMTilesTileSource,
|
|
798
|
+
_PMTilesLoader: () => PMTilesLoader
|
|
797
799
|
});
|
|
798
800
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
799
801
|
|
|
@@ -1426,6 +1428,33 @@ var __exports__ = (() => {
|
|
|
1426
1428
|
return filename;
|
|
1427
1429
|
}
|
|
1428
1430
|
|
|
1431
|
+
// ../loader-utils/src/lib/files/blob-file.ts
|
|
1432
|
+
var BlobFile = class {
|
|
1433
|
+
handle;
|
|
1434
|
+
size;
|
|
1435
|
+
bigsize;
|
|
1436
|
+
url;
|
|
1437
|
+
constructor(blob) {
|
|
1438
|
+
this.handle = blob instanceof ArrayBuffer ? new Blob([blob]) : blob;
|
|
1439
|
+
this.size = blob instanceof ArrayBuffer ? blob.byteLength : blob.size;
|
|
1440
|
+
this.bigsize = BigInt(this.size);
|
|
1441
|
+
this.url = blob instanceof File ? blob.name : "";
|
|
1442
|
+
}
|
|
1443
|
+
async close() {
|
|
1444
|
+
}
|
|
1445
|
+
async stat() {
|
|
1446
|
+
return {
|
|
1447
|
+
size: this.handle.size,
|
|
1448
|
+
bigsize: BigInt(this.handle.size),
|
|
1449
|
+
isDirectory: false
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
async read(start, length) {
|
|
1453
|
+
const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
|
|
1454
|
+
return arrayBuffer;
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
|
|
1429
1458
|
// ../loader-utils/src/lib/sources/data-source.ts
|
|
1430
1459
|
var DataSource = class {
|
|
1431
1460
|
/** A resolved fetch function extracted from loadOptions prop */
|
|
@@ -1879,6 +1908,293 @@ var __exports__ = (() => {
|
|
|
1879
1908
|
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
1880
1909
|
};
|
|
1881
1910
|
|
|
1911
|
+
// ../mvt/src/lib/get-schemas-from-tilejson.ts
|
|
1912
|
+
function getSchemaFromTileJSONLayer(layer) {
|
|
1913
|
+
const fields = [];
|
|
1914
|
+
if (layer.fields) {
|
|
1915
|
+
for (const field of layer.fields) {
|
|
1916
|
+
fields.push({
|
|
1917
|
+
name: field.name,
|
|
1918
|
+
type: getDataTypeFromTileJSONField(field),
|
|
1919
|
+
metadata: getMetadataFromTileJSONField(field)
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return {
|
|
1924
|
+
metadata: getMetadataFromTileJSONLayer(layer),
|
|
1925
|
+
fields
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
function getMetadataFromTileJSONLayer(layer) {
|
|
1929
|
+
const metadata = {};
|
|
1930
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
1931
|
+
if (key !== "fields" && value) {
|
|
1932
|
+
metadata[key] = JSON.stringify(value);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
return metadata;
|
|
1936
|
+
}
|
|
1937
|
+
function getDataTypeFromTileJSONField(field) {
|
|
1938
|
+
switch (field.type.toLowerCase()) {
|
|
1939
|
+
case "float32":
|
|
1940
|
+
return "float32";
|
|
1941
|
+
case "number":
|
|
1942
|
+
case "float64":
|
|
1943
|
+
return "float64";
|
|
1944
|
+
case "string":
|
|
1945
|
+
case "utf8":
|
|
1946
|
+
return "utf8";
|
|
1947
|
+
case "boolean":
|
|
1948
|
+
return "bool";
|
|
1949
|
+
default:
|
|
1950
|
+
return "null";
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
function getMetadataFromTileJSONField(field) {
|
|
1954
|
+
const metadata = {};
|
|
1955
|
+
for (const [key, value] of Object.entries(field)) {
|
|
1956
|
+
if (key !== "name" && value) {
|
|
1957
|
+
metadata[key] = JSON.stringify(value);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
return metadata;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// ../mvt/src/lib/parse-tilejson.ts
|
|
1964
|
+
var isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
1965
|
+
function parseTileJSON(jsonMetadata, options) {
|
|
1966
|
+
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
1967
|
+
return null;
|
|
1968
|
+
}
|
|
1969
|
+
let tileJSON = {
|
|
1970
|
+
name: jsonMetadata.name || "",
|
|
1971
|
+
description: jsonMetadata.description || ""
|
|
1972
|
+
};
|
|
1973
|
+
if (typeof jsonMetadata.generator === "string") {
|
|
1974
|
+
tileJSON.generator = jsonMetadata.generator;
|
|
1975
|
+
}
|
|
1976
|
+
if (typeof jsonMetadata.generator_options === "string") {
|
|
1977
|
+
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
1978
|
+
}
|
|
1979
|
+
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
1980
|
+
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
1981
|
+
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
1982
|
+
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
1983
|
+
if (typeof jsonMetadata?.json === "string") {
|
|
1984
|
+
try {
|
|
1985
|
+
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
1986
|
+
} catch (error) {
|
|
1987
|
+
console.warn("Failed to parse tilejson.json field", error);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
1991
|
+
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
1992
|
+
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
1993
|
+
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
1994
|
+
tileJSON = {
|
|
1995
|
+
...tileJSON,
|
|
1996
|
+
layers
|
|
1997
|
+
};
|
|
1998
|
+
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
1999
|
+
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
2000
|
+
}
|
|
2001
|
+
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
2002
|
+
tileJSON.minZoom = layers[0].minZoom || null;
|
|
2003
|
+
}
|
|
2004
|
+
return tileJSON;
|
|
2005
|
+
}
|
|
2006
|
+
function parseTileJSONLayers(layers) {
|
|
2007
|
+
if (!Array.isArray(layers)) {
|
|
2008
|
+
return [];
|
|
2009
|
+
}
|
|
2010
|
+
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
2011
|
+
}
|
|
2012
|
+
function parseTileJSONLayer(layer) {
|
|
2013
|
+
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
2014
|
+
name: key,
|
|
2015
|
+
...attributeTypeToFieldType(String(datatype))
|
|
2016
|
+
}));
|
|
2017
|
+
const layer2 = { ...layer };
|
|
2018
|
+
delete layer2.fields;
|
|
2019
|
+
return {
|
|
2020
|
+
name: layer.id || "",
|
|
2021
|
+
...layer2,
|
|
2022
|
+
fields
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
function parseTilestatsLayers(tilestats, options) {
|
|
2026
|
+
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
2027
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
2028
|
+
}
|
|
2029
|
+
return [];
|
|
2030
|
+
}
|
|
2031
|
+
function parseTilestatsForLayer(layer, options) {
|
|
2032
|
+
const fields = [];
|
|
2033
|
+
const indexedAttributes = {};
|
|
2034
|
+
const attributes = layer.attributes || [];
|
|
2035
|
+
for (const attribute of attributes) {
|
|
2036
|
+
const name = attribute.attribute;
|
|
2037
|
+
if (typeof name === "string") {
|
|
2038
|
+
if (name.split("|").length > 1) {
|
|
2039
|
+
const fname = name.split("|")[0];
|
|
2040
|
+
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
2041
|
+
indexedAttributes[fname].push(attribute);
|
|
2042
|
+
console.warn("ignoring tilestats indexed field", fname);
|
|
2043
|
+
} else if (!fields[name]) {
|
|
2044
|
+
fields.push(attributeToField(attribute, options));
|
|
2045
|
+
} else {
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
return {
|
|
2050
|
+
name: layer.layer || "",
|
|
2051
|
+
dominantGeometry: layer.geometry,
|
|
2052
|
+
fields
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
function mergeLayers(layers, tilestatsLayers) {
|
|
2056
|
+
return layers.map((layer) => {
|
|
2057
|
+
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
2058
|
+
const fields = tilestatsLayer?.fields || layer.fields || [];
|
|
2059
|
+
const mergedLayer = {
|
|
2060
|
+
...layer,
|
|
2061
|
+
...tilestatsLayer,
|
|
2062
|
+
fields
|
|
2063
|
+
};
|
|
2064
|
+
mergedLayer.schema = getSchemaFromTileJSONLayer(mergedLayer);
|
|
2065
|
+
return mergedLayer;
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
function parseBounds(bounds) {
|
|
2069
|
+
const result = fromArrayOrString(bounds);
|
|
2070
|
+
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
2071
|
+
return [
|
|
2072
|
+
[result[0], result[1]],
|
|
2073
|
+
[result[2], result[3]]
|
|
2074
|
+
];
|
|
2075
|
+
}
|
|
2076
|
+
return void 0;
|
|
2077
|
+
}
|
|
2078
|
+
function parseCenter(center) {
|
|
2079
|
+
const result = fromArrayOrString(center);
|
|
2080
|
+
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
2081
|
+
return result;
|
|
2082
|
+
}
|
|
2083
|
+
return null;
|
|
2084
|
+
}
|
|
2085
|
+
function safeParseFloat(input) {
|
|
2086
|
+
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
2087
|
+
return result === null || isNaN(result) ? null : result;
|
|
2088
|
+
}
|
|
2089
|
+
function isLat(num) {
|
|
2090
|
+
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
2091
|
+
}
|
|
2092
|
+
function isLng(num) {
|
|
2093
|
+
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
2094
|
+
}
|
|
2095
|
+
function isZoom(num) {
|
|
2096
|
+
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
2097
|
+
}
|
|
2098
|
+
function fromArrayOrString(data) {
|
|
2099
|
+
if (typeof data === "string") {
|
|
2100
|
+
return data.split(",").map(parseFloat);
|
|
2101
|
+
} else if (Array.isArray(data)) {
|
|
2102
|
+
return data;
|
|
2103
|
+
}
|
|
2104
|
+
return null;
|
|
2105
|
+
}
|
|
2106
|
+
var attrTypeMap = {
|
|
2107
|
+
number: {
|
|
2108
|
+
type: "float32"
|
|
2109
|
+
},
|
|
2110
|
+
numeric: {
|
|
2111
|
+
type: "float32"
|
|
2112
|
+
},
|
|
2113
|
+
string: {
|
|
2114
|
+
type: "utf8"
|
|
2115
|
+
},
|
|
2116
|
+
vachar: {
|
|
2117
|
+
type: "utf8"
|
|
2118
|
+
},
|
|
2119
|
+
float: {
|
|
2120
|
+
type: "float32"
|
|
2121
|
+
},
|
|
2122
|
+
int: {
|
|
2123
|
+
type: "int32"
|
|
2124
|
+
},
|
|
2125
|
+
int4: {
|
|
2126
|
+
type: "int32"
|
|
2127
|
+
},
|
|
2128
|
+
boolean: {
|
|
2129
|
+
type: "boolean"
|
|
2130
|
+
},
|
|
2131
|
+
bool: {
|
|
2132
|
+
type: "boolean"
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
function attributeToField(attribute = {}, options) {
|
|
2136
|
+
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
2137
|
+
const field = {
|
|
2138
|
+
name: attribute.attribute,
|
|
2139
|
+
// what happens if attribute type is string...
|
|
2140
|
+
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
2141
|
+
...fieldTypes
|
|
2142
|
+
};
|
|
2143
|
+
if (typeof attribute.min === "number") {
|
|
2144
|
+
field.min = attribute.min;
|
|
2145
|
+
}
|
|
2146
|
+
if (typeof attribute.max === "number") {
|
|
2147
|
+
field.max = attribute.max;
|
|
2148
|
+
}
|
|
2149
|
+
if (typeof attribute.count === "number") {
|
|
2150
|
+
field.uniqueValueCount = attribute.count;
|
|
2151
|
+
}
|
|
2152
|
+
if (attribute.values) {
|
|
2153
|
+
field.values = attribute.values;
|
|
2154
|
+
}
|
|
2155
|
+
if (field.values && typeof options.maxValues === "number") {
|
|
2156
|
+
field.values = field.values?.slice(0, options.maxValues);
|
|
2157
|
+
}
|
|
2158
|
+
return field;
|
|
2159
|
+
}
|
|
2160
|
+
function attributeTypeToFieldType(aType) {
|
|
2161
|
+
const type = aType.toLowerCase();
|
|
2162
|
+
if (!type || !attrTypeMap[type]) {
|
|
2163
|
+
}
|
|
2164
|
+
return attrTypeMap[type] || { type: "string" };
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// ../mvt/src/tilejson-loader.ts
|
|
2168
|
+
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2169
|
+
var TileJSONLoader = {
|
|
2170
|
+
dataType: null,
|
|
2171
|
+
batchType: null,
|
|
2172
|
+
name: "TileJSON",
|
|
2173
|
+
id: "tilejson",
|
|
2174
|
+
module: "pmtiles",
|
|
2175
|
+
version: VERSION4,
|
|
2176
|
+
worker: true,
|
|
2177
|
+
extensions: ["json"],
|
|
2178
|
+
mimeTypes: ["application/json"],
|
|
2179
|
+
text: true,
|
|
2180
|
+
options: {
|
|
2181
|
+
tilejson: {
|
|
2182
|
+
maxValues: void 0
|
|
2183
|
+
}
|
|
2184
|
+
},
|
|
2185
|
+
parse: async (arrayBuffer, options) => {
|
|
2186
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
2187
|
+
const json = JSON.parse(jsonString);
|
|
2188
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
2189
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
2190
|
+
},
|
|
2191
|
+
parseTextSync: (text, options) => {
|
|
2192
|
+
const json = JSON.parse(text);
|
|
2193
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
2194
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
|
|
1882
2198
|
// ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
|
|
1883
2199
|
var DimIndex = {
|
|
1884
2200
|
x: 0,
|
|
@@ -2705,7 +3021,7 @@ var __exports__ = (() => {
|
|
|
2705
3021
|
p[1] /= extent;
|
|
2706
3022
|
}
|
|
2707
3023
|
function convertToLocalCoordinatesFlat(data, extent) {
|
|
2708
|
-
for (let i2 = 0
|
|
3024
|
+
for (let i2 = 0; i2 < data.length; ++i2) {
|
|
2709
3025
|
data[i2] /= extent;
|
|
2710
3026
|
}
|
|
2711
3027
|
}
|
|
@@ -3340,14 +3656,14 @@ var __exports__ = (() => {
|
|
|
3340
3656
|
}
|
|
3341
3657
|
|
|
3342
3658
|
// ../mvt/src/mvt-loader.ts
|
|
3343
|
-
var
|
|
3659
|
+
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3344
3660
|
var MVTWorkerLoader = {
|
|
3345
3661
|
dataType: null,
|
|
3346
3662
|
batchType: null,
|
|
3347
3663
|
name: "Mapbox Vector Tile",
|
|
3348
3664
|
id: "mvt",
|
|
3349
3665
|
module: "mvt",
|
|
3350
|
-
version:
|
|
3666
|
+
version: VERSION5,
|
|
3351
3667
|
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
3352
3668
|
extensions: ["mvt", "pbf"],
|
|
3353
3669
|
mimeTypes: [
|
|
@@ -3375,241 +3691,6 @@ var __exports__ = (() => {
|
|
|
3375
3691
|
binary: true
|
|
3376
3692
|
};
|
|
3377
3693
|
|
|
3378
|
-
// ../mvt/src/lib/parse-tilejson.ts
|
|
3379
|
-
var isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
3380
|
-
function parseTileJSON(jsonMetadata, options) {
|
|
3381
|
-
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
3382
|
-
return null;
|
|
3383
|
-
}
|
|
3384
|
-
let tileJSON = {
|
|
3385
|
-
name: jsonMetadata.name || "",
|
|
3386
|
-
description: jsonMetadata.description || ""
|
|
3387
|
-
};
|
|
3388
|
-
if (typeof jsonMetadata.generator === "string") {
|
|
3389
|
-
tileJSON.generator = jsonMetadata.generator;
|
|
3390
|
-
}
|
|
3391
|
-
if (typeof jsonMetadata.generator_options === "string") {
|
|
3392
|
-
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
3393
|
-
}
|
|
3394
|
-
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
3395
|
-
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
3396
|
-
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
3397
|
-
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
3398
|
-
if (typeof jsonMetadata?.json === "string") {
|
|
3399
|
-
try {
|
|
3400
|
-
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
3401
|
-
} catch (error) {
|
|
3402
|
-
console.warn("Failed to parse tilejson.json field", error);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
3406
|
-
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
3407
|
-
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
3408
|
-
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
3409
|
-
tileJSON = {
|
|
3410
|
-
...tileJSON,
|
|
3411
|
-
layers
|
|
3412
|
-
};
|
|
3413
|
-
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
3414
|
-
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
3415
|
-
}
|
|
3416
|
-
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
3417
|
-
tileJSON.minZoom = layers[0].minZoom || null;
|
|
3418
|
-
}
|
|
3419
|
-
return tileJSON;
|
|
3420
|
-
}
|
|
3421
|
-
function parseTileJSONLayers(layers) {
|
|
3422
|
-
if (!Array.isArray(layers)) {
|
|
3423
|
-
return [];
|
|
3424
|
-
}
|
|
3425
|
-
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
3426
|
-
}
|
|
3427
|
-
function parseTileJSONLayer(layer) {
|
|
3428
|
-
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
3429
|
-
name: key,
|
|
3430
|
-
...attributeTypeToFieldType(String(datatype))
|
|
3431
|
-
}));
|
|
3432
|
-
const layer2 = { ...layer };
|
|
3433
|
-
delete layer2.fields;
|
|
3434
|
-
return {
|
|
3435
|
-
name: layer.id || "",
|
|
3436
|
-
...layer2,
|
|
3437
|
-
fields
|
|
3438
|
-
};
|
|
3439
|
-
}
|
|
3440
|
-
function parseTilestatsLayers(tilestats, options) {
|
|
3441
|
-
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
3442
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
3443
|
-
}
|
|
3444
|
-
return [];
|
|
3445
|
-
}
|
|
3446
|
-
function parseTilestatsForLayer(layer, options) {
|
|
3447
|
-
const fields = [];
|
|
3448
|
-
const indexedAttributes = {};
|
|
3449
|
-
const attributes = layer.attributes || [];
|
|
3450
|
-
for (const attribute of attributes) {
|
|
3451
|
-
const name = attribute.attribute;
|
|
3452
|
-
if (typeof name === "string") {
|
|
3453
|
-
if (name.split("|").length > 1) {
|
|
3454
|
-
const fname = name.split("|")[0];
|
|
3455
|
-
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
3456
|
-
indexedAttributes[fname].push(attribute);
|
|
3457
|
-
console.warn("ignoring tilestats indexed field", fname);
|
|
3458
|
-
} else if (!fields[name]) {
|
|
3459
|
-
fields.push(attributeToField(attribute, options));
|
|
3460
|
-
} else {
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
3464
|
-
return {
|
|
3465
|
-
name: layer.layer || "",
|
|
3466
|
-
dominantGeometry: layer.geometry,
|
|
3467
|
-
fields
|
|
3468
|
-
};
|
|
3469
|
-
}
|
|
3470
|
-
function mergeLayers(layers, tilestatsLayers) {
|
|
3471
|
-
return layers.map((layer) => {
|
|
3472
|
-
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
3473
|
-
const fields = tilestatsLayer?.fields || [];
|
|
3474
|
-
const layer2 = { ...layer };
|
|
3475
|
-
delete layer2.fields;
|
|
3476
|
-
return {
|
|
3477
|
-
...layer2,
|
|
3478
|
-
...tilestatsLayer,
|
|
3479
|
-
fields
|
|
3480
|
-
};
|
|
3481
|
-
});
|
|
3482
|
-
}
|
|
3483
|
-
function parseBounds(bounds) {
|
|
3484
|
-
const result = fromArrayOrString(bounds);
|
|
3485
|
-
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
3486
|
-
return [
|
|
3487
|
-
[result[0], result[1]],
|
|
3488
|
-
[result[2], result[3]]
|
|
3489
|
-
];
|
|
3490
|
-
}
|
|
3491
|
-
return void 0;
|
|
3492
|
-
}
|
|
3493
|
-
function parseCenter(center) {
|
|
3494
|
-
const result = fromArrayOrString(center);
|
|
3495
|
-
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
3496
|
-
return result;
|
|
3497
|
-
}
|
|
3498
|
-
return null;
|
|
3499
|
-
}
|
|
3500
|
-
function safeParseFloat(input) {
|
|
3501
|
-
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
3502
|
-
return result === null || isNaN(result) ? null : result;
|
|
3503
|
-
}
|
|
3504
|
-
function isLat(num) {
|
|
3505
|
-
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
3506
|
-
}
|
|
3507
|
-
function isLng(num) {
|
|
3508
|
-
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
3509
|
-
}
|
|
3510
|
-
function isZoom(num) {
|
|
3511
|
-
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
3512
|
-
}
|
|
3513
|
-
function fromArrayOrString(data) {
|
|
3514
|
-
if (typeof data === "string") {
|
|
3515
|
-
return data.split(",").map(parseFloat);
|
|
3516
|
-
} else if (Array.isArray(data)) {
|
|
3517
|
-
return data;
|
|
3518
|
-
}
|
|
3519
|
-
return null;
|
|
3520
|
-
}
|
|
3521
|
-
var attrTypeMap = {
|
|
3522
|
-
number: {
|
|
3523
|
-
type: "float32"
|
|
3524
|
-
},
|
|
3525
|
-
numeric: {
|
|
3526
|
-
type: "float32"
|
|
3527
|
-
},
|
|
3528
|
-
string: {
|
|
3529
|
-
type: "utf8"
|
|
3530
|
-
},
|
|
3531
|
-
vachar: {
|
|
3532
|
-
type: "utf8"
|
|
3533
|
-
},
|
|
3534
|
-
float: {
|
|
3535
|
-
type: "float32"
|
|
3536
|
-
},
|
|
3537
|
-
int: {
|
|
3538
|
-
type: "int32"
|
|
3539
|
-
},
|
|
3540
|
-
int4: {
|
|
3541
|
-
type: "int32"
|
|
3542
|
-
},
|
|
3543
|
-
boolean: {
|
|
3544
|
-
type: "boolean"
|
|
3545
|
-
},
|
|
3546
|
-
bool: {
|
|
3547
|
-
type: "boolean"
|
|
3548
|
-
}
|
|
3549
|
-
};
|
|
3550
|
-
function attributeToField(attribute = {}, options) {
|
|
3551
|
-
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
3552
|
-
const field = {
|
|
3553
|
-
name: attribute.attribute,
|
|
3554
|
-
// what happens if attribute type is string...
|
|
3555
|
-
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
3556
|
-
...fieldTypes
|
|
3557
|
-
};
|
|
3558
|
-
if (typeof attribute.min === "number") {
|
|
3559
|
-
field.min = attribute.min;
|
|
3560
|
-
}
|
|
3561
|
-
if (typeof attribute.max === "number") {
|
|
3562
|
-
field.max = attribute.max;
|
|
3563
|
-
}
|
|
3564
|
-
if (typeof attribute.count === "number") {
|
|
3565
|
-
field.uniqueValueCount = attribute.count;
|
|
3566
|
-
}
|
|
3567
|
-
if (attribute.values) {
|
|
3568
|
-
field.values = attribute.values;
|
|
3569
|
-
}
|
|
3570
|
-
if (field.values && typeof options.maxValues === "number") {
|
|
3571
|
-
field.values = field.values?.slice(0, options.maxValues);
|
|
3572
|
-
}
|
|
3573
|
-
return field;
|
|
3574
|
-
}
|
|
3575
|
-
function attributeTypeToFieldType(aType) {
|
|
3576
|
-
const type = aType.toLowerCase();
|
|
3577
|
-
if (!type || !attrTypeMap[type]) {
|
|
3578
|
-
}
|
|
3579
|
-
return attrTypeMap[type] || { type: "string" };
|
|
3580
|
-
}
|
|
3581
|
-
|
|
3582
|
-
// ../mvt/src/tilejson-loader.ts
|
|
3583
|
-
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3584
|
-
var TileJSONLoader = {
|
|
3585
|
-
dataType: null,
|
|
3586
|
-
batchType: null,
|
|
3587
|
-
name: "TileJSON",
|
|
3588
|
-
id: "tilejson",
|
|
3589
|
-
module: "pmtiles",
|
|
3590
|
-
version: VERSION5,
|
|
3591
|
-
worker: true,
|
|
3592
|
-
extensions: ["json"],
|
|
3593
|
-
mimeTypes: ["application/json"],
|
|
3594
|
-
text: true,
|
|
3595
|
-
options: {
|
|
3596
|
-
tilejson: {
|
|
3597
|
-
maxValues: void 0
|
|
3598
|
-
}
|
|
3599
|
-
},
|
|
3600
|
-
parse: async (arrayBuffer, options) => {
|
|
3601
|
-
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
3602
|
-
const json = JSON.parse(jsonString);
|
|
3603
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3604
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3605
|
-
},
|
|
3606
|
-
parseTextSync: (text, options) => {
|
|
3607
|
-
const json = JSON.parse(text);
|
|
3608
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3609
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3610
|
-
}
|
|
3611
|
-
};
|
|
3612
|
-
|
|
3613
3694
|
// ../../node_modules/pmtiles/dist/index.js
|
|
3614
3695
|
var dist_exports = {};
|
|
3615
3696
|
__export(dist_exports, {
|
|
@@ -5239,8 +5320,7 @@ var __exports__ = (() => {
|
|
|
5239
5320
|
|
|
5240
5321
|
// src/lib/parse-pmtiles.ts
|
|
5241
5322
|
var { TileType: TileType2 } = dist_exports;
|
|
5242
|
-
function parsePMTilesHeader(header,
|
|
5243
|
-
const pmtilesMetadata = pmmetadata;
|
|
5323
|
+
function parsePMTilesHeader(header, pmtilesMetadata, options, loadOptions) {
|
|
5244
5324
|
let tilejson = null;
|
|
5245
5325
|
if (pmtilesMetadata) {
|
|
5246
5326
|
try {
|
|
@@ -5325,17 +5405,32 @@ var __exports__ = (() => {
|
|
|
5325
5405
|
|
|
5326
5406
|
// src/pmtiles-source.ts
|
|
5327
5407
|
var { PMTiles: PMTiles2 } = dist_exports;
|
|
5328
|
-
var
|
|
5408
|
+
var VERSION6 = "1.0.0";
|
|
5409
|
+
var PMTilesSource = {
|
|
5410
|
+
name: "PMTiles",
|
|
5411
|
+
id: "pmtiles",
|
|
5412
|
+
module: "pmtiles",
|
|
5413
|
+
version: VERSION6,
|
|
5414
|
+
extensions: ["pmtiles"],
|
|
5415
|
+
mimeTypes: ["application/octet-stream"],
|
|
5416
|
+
options: { url: void 0, pmtiles: {} },
|
|
5417
|
+
type: "pmtiles",
|
|
5418
|
+
fromUrl: true,
|
|
5419
|
+
fromBlob: true,
|
|
5420
|
+
testURL: (url) => url.endsWith(".pmtiles"),
|
|
5421
|
+
createDataSource: (url, props) => new PMTilesTileSource(url, props)
|
|
5422
|
+
};
|
|
5423
|
+
var PMTilesTileSource = class extends DataSource {
|
|
5329
5424
|
data;
|
|
5330
5425
|
props;
|
|
5331
5426
|
mimeType = null;
|
|
5332
5427
|
pmtiles;
|
|
5333
5428
|
metadata;
|
|
5334
|
-
constructor(props) {
|
|
5429
|
+
constructor(data, props) {
|
|
5335
5430
|
super(props);
|
|
5336
5431
|
this.props = props;
|
|
5337
|
-
const url = typeof
|
|
5338
|
-
this.data =
|
|
5432
|
+
const url = typeof data === "string" ? resolvePath(data) : new BlobSource(data, "pmtiles");
|
|
5433
|
+
this.data = data;
|
|
5339
5434
|
this.pmtiles = new PMTiles2(url);
|
|
5340
5435
|
this.getTileData = this.getTileData.bind(this);
|
|
5341
5436
|
this.metadata = this.getMetadata();
|
|
@@ -5345,7 +5440,7 @@ var __exports__ = (() => {
|
|
|
5345
5440
|
}
|
|
5346
5441
|
async getMetadata() {
|
|
5347
5442
|
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
5348
|
-
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
5443
|
+
const pmtilesMetadata = await this.pmtiles.getMetadata() || {};
|
|
5349
5444
|
const metadata = parsePMTilesHeader(
|
|
5350
5445
|
pmtilesHeader,
|
|
5351
5446
|
pmtilesMetadata,
|
|
@@ -5401,6 +5496,47 @@ var __exports__ = (() => {
|
|
|
5401
5496
|
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
5402
5497
|
}
|
|
5403
5498
|
};
|
|
5499
|
+
|
|
5500
|
+
// src/lib/version.ts
|
|
5501
|
+
var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
5502
|
+
|
|
5503
|
+
// src/pmtiles-loader.ts
|
|
5504
|
+
var PMTilesLoader = {
|
|
5505
|
+
name: "PMTiles",
|
|
5506
|
+
id: "pmtiles",
|
|
5507
|
+
module: "pmtiles",
|
|
5508
|
+
version: VERSION7,
|
|
5509
|
+
extensions: ["pmtiles"],
|
|
5510
|
+
mimeTypes: ["application/octet-stream"],
|
|
5511
|
+
tests: ["PMTiles"],
|
|
5512
|
+
options: {
|
|
5513
|
+
pmtiles: {}
|
|
5514
|
+
},
|
|
5515
|
+
parse: async (arrayBuffer, options) => parseFileAsPMTiles(new BlobFile(new Blob([arrayBuffer])), options),
|
|
5516
|
+
parseFile: parseFileAsPMTiles
|
|
5517
|
+
};
|
|
5518
|
+
async function parseFileAsPMTiles(file, options) {
|
|
5519
|
+
const source = new PMTilesTileSource(file.handle, {
|
|
5520
|
+
pmtiles: options?.pmtiles || {}
|
|
5521
|
+
});
|
|
5522
|
+
const formatSpecificMetadata = await source.getMetadata();
|
|
5523
|
+
const { tileMIMEType, tilejson = {} } = formatSpecificMetadata;
|
|
5524
|
+
const { layers = [] } = tilejson;
|
|
5525
|
+
switch (tileMIMEType) {
|
|
5526
|
+
case "application/vnd.mapbox-vector-tile":
|
|
5527
|
+
return {
|
|
5528
|
+
shape: "vector-source",
|
|
5529
|
+
layers: layers.map((layer) => ({ name: layer.name, schema: layer.schema })),
|
|
5530
|
+
tables: [],
|
|
5531
|
+
formatSpecificMetadata
|
|
5532
|
+
};
|
|
5533
|
+
case "image/png":
|
|
5534
|
+
case "image/jpeg":
|
|
5535
|
+
return { shape: "image-source", formatSpecificMetadata };
|
|
5536
|
+
default:
|
|
5537
|
+
throw new Error(`PMTilesLoader: Unsupported tile MIME type ${tileMIMEType}`);
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5404
5540
|
return __toCommonJS(bundle_exports);
|
|
5405
5541
|
})();
|
|
5406
5542
|
/*! Bundled license information:
|