@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1289 -807
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +923 -773
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.js +2 -30
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +38 -1
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.js +65 -6
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
- package/dist/lib/{geojsonvt/clip.d.ts → vector-tiler/features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/clip.js → vector-tiler/features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/features/convert-feature.d.ts +18 -0
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/{geojsonvt/simplify.d.ts → vector-tiler/features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/simplify.js → vector-tiler/features/simplify-path.js} +3 -3
- package/dist/lib/{geojsonvt/wrap.d.ts → vector-tiler/features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/wrap.js → vector-tiler/features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +35 -18
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +30 -10
- package/dist/mvt-worker.js +101 -56
- package/dist/table-tile-source.d.ts +148 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +420 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +14 -7
- package/src/lib/parse-mvt.ts +4 -33
- package/src/lib/parse-tilejson.ts +6 -6
- package/src/lib/utils/geometry-utils.ts +66 -1
- package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
- package/src/lib/{geojsonvt/clip.ts → vector-tiler/features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/features/convert-feature.ts +191 -0
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/{geojsonvt/simplify.ts → vector-tiler/features/simplify-path.ts} +8 -3
- package/src/lib/{geojsonvt/wrap.ts → vector-tiler/features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-source.ts +47 -24
- package/src/table-tile-source.ts +553 -0
- package/src/tilejson-loader.ts +2 -2
- package/dist/geojson-tile-source.d.ts +0 -79
- package/dist/geojson-tile-source.d.ts.map +0 -1
- package/dist/geojson-tile-source.js +0 -319
- package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.d.ts +0 -10
- package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.js +0 -132
- package/dist/lib/geojsonvt/feature.d.ts +0 -3
- package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
- package/dist/lib/geojsonvt/feature.js +0 -44
- package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.d.ts +0 -38
- package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.js +0 -123
- package/dist/lib/geojsonvt/transform.d.ts +0 -7
- package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
- package/dist/lib/geojsonvt/transform.js +0 -41
- package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
- package/src/geojson-tile-source.ts +0 -422
- package/src/lib/geojsonvt/convert.ts +0 -160
- package/src/lib/geojsonvt/feature.ts +0 -47
- package/src/lib/geojsonvt/tile.ts +0 -187
- package/src/lib/geojsonvt/transform.ts +0 -57
- /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
package/dist/dist.dev.js
CHANGED
|
@@ -793,14 +793,377 @@ var __exports__ = (() => {
|
|
|
793
793
|
// bundle.ts
|
|
794
794
|
var bundle_exports = {};
|
|
795
795
|
__export(bundle_exports, {
|
|
796
|
-
GeoJSONTileSource: () => GeoJSONTileSource,
|
|
797
796
|
MVTLoader: () => MVTLoader,
|
|
798
797
|
MVTSource: () => MVTSource,
|
|
799
798
|
MVTWorkerLoader: () => MVTWorkerLoader,
|
|
799
|
+
TableTileSource: () => TableTileSource,
|
|
800
800
|
TileJSONLoader: () => TileJSONLoader
|
|
801
801
|
});
|
|
802
802
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
803
803
|
|
|
804
|
+
// src/lib/parse-tilejson.ts
|
|
805
|
+
var isObject = (x) => x !== null && typeof x === "object";
|
|
806
|
+
function parseTileJSON(jsonMetadata, options) {
|
|
807
|
+
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
let tileJSON = {
|
|
811
|
+
name: jsonMetadata.name || "",
|
|
812
|
+
description: jsonMetadata.description || ""
|
|
813
|
+
};
|
|
814
|
+
if (typeof jsonMetadata.generator === "string") {
|
|
815
|
+
tileJSON.generator = jsonMetadata.generator;
|
|
816
|
+
}
|
|
817
|
+
if (typeof jsonMetadata.generator_options === "string") {
|
|
818
|
+
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
819
|
+
}
|
|
820
|
+
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
821
|
+
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
822
|
+
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
823
|
+
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
824
|
+
if (typeof jsonMetadata?.json === "string") {
|
|
825
|
+
try {
|
|
826
|
+
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
827
|
+
} catch (error) {
|
|
828
|
+
console.warn("Failed to parse tilejson.json field", error);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
832
|
+
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
833
|
+
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
834
|
+
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
835
|
+
tileJSON = {
|
|
836
|
+
...tileJSON,
|
|
837
|
+
layers
|
|
838
|
+
};
|
|
839
|
+
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
840
|
+
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
841
|
+
}
|
|
842
|
+
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
843
|
+
tileJSON.minZoom = layers[0].minZoom || null;
|
|
844
|
+
}
|
|
845
|
+
return tileJSON;
|
|
846
|
+
}
|
|
847
|
+
function parseTileJSONLayers(layers) {
|
|
848
|
+
if (!Array.isArray(layers)) {
|
|
849
|
+
return [];
|
|
850
|
+
}
|
|
851
|
+
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
852
|
+
}
|
|
853
|
+
function parseTileJSONLayer(layer) {
|
|
854
|
+
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
855
|
+
name: key,
|
|
856
|
+
...attributeTypeToFieldType(String(datatype))
|
|
857
|
+
}));
|
|
858
|
+
const layer2 = { ...layer };
|
|
859
|
+
delete layer2.fields;
|
|
860
|
+
return {
|
|
861
|
+
name: layer.id || "",
|
|
862
|
+
...layer2,
|
|
863
|
+
fields
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function parseTilestatsLayers(tilestats, options) {
|
|
867
|
+
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
868
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
869
|
+
}
|
|
870
|
+
return [];
|
|
871
|
+
}
|
|
872
|
+
function parseTilestatsForLayer(layer, options) {
|
|
873
|
+
const fields = [];
|
|
874
|
+
const indexedAttributes = {};
|
|
875
|
+
const attributes = layer.attributes || [];
|
|
876
|
+
for (const attribute of attributes) {
|
|
877
|
+
const name = attribute.attribute;
|
|
878
|
+
if (typeof name === "string") {
|
|
879
|
+
if (name.split("|").length > 1) {
|
|
880
|
+
const fname = name.split("|")[0];
|
|
881
|
+
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
882
|
+
indexedAttributes[fname].push(attribute);
|
|
883
|
+
console.warn("ignoring tilestats indexed field", fname);
|
|
884
|
+
} else if (!fields[name]) {
|
|
885
|
+
fields.push(attributeToField(attribute, options));
|
|
886
|
+
} else {
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return {
|
|
891
|
+
name: layer.layer || "",
|
|
892
|
+
dominantGeometry: layer.geometry,
|
|
893
|
+
fields
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function mergeLayers(layers, tilestatsLayers) {
|
|
897
|
+
return layers.map((layer) => {
|
|
898
|
+
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
899
|
+
const fields = tilestatsLayer?.fields || [];
|
|
900
|
+
const layer2 = { ...layer };
|
|
901
|
+
delete layer2.fields;
|
|
902
|
+
return {
|
|
903
|
+
...layer2,
|
|
904
|
+
...tilestatsLayer,
|
|
905
|
+
fields
|
|
906
|
+
};
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
function parseBounds(bounds) {
|
|
910
|
+
const result = fromArrayOrString(bounds);
|
|
911
|
+
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
912
|
+
return [
|
|
913
|
+
[result[0], result[1]],
|
|
914
|
+
[result[2], result[3]]
|
|
915
|
+
];
|
|
916
|
+
}
|
|
917
|
+
return void 0;
|
|
918
|
+
}
|
|
919
|
+
function parseCenter(center) {
|
|
920
|
+
const result = fromArrayOrString(center);
|
|
921
|
+
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
922
|
+
return result;
|
|
923
|
+
}
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
function safeParseFloat(input) {
|
|
927
|
+
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
928
|
+
return result === null || isNaN(result) ? null : result;
|
|
929
|
+
}
|
|
930
|
+
function isLat(num) {
|
|
931
|
+
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
932
|
+
}
|
|
933
|
+
function isLng(num) {
|
|
934
|
+
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
935
|
+
}
|
|
936
|
+
function isZoom(num) {
|
|
937
|
+
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
938
|
+
}
|
|
939
|
+
function fromArrayOrString(data) {
|
|
940
|
+
if (typeof data === "string") {
|
|
941
|
+
return data.split(",").map(parseFloat);
|
|
942
|
+
} else if (Array.isArray(data)) {
|
|
943
|
+
return data;
|
|
944
|
+
}
|
|
945
|
+
return null;
|
|
946
|
+
}
|
|
947
|
+
var attrTypeMap = {
|
|
948
|
+
number: {
|
|
949
|
+
type: "float32"
|
|
950
|
+
},
|
|
951
|
+
numeric: {
|
|
952
|
+
type: "float32"
|
|
953
|
+
},
|
|
954
|
+
string: {
|
|
955
|
+
type: "utf8"
|
|
956
|
+
},
|
|
957
|
+
vachar: {
|
|
958
|
+
type: "utf8"
|
|
959
|
+
},
|
|
960
|
+
float: {
|
|
961
|
+
type: "float32"
|
|
962
|
+
},
|
|
963
|
+
int: {
|
|
964
|
+
type: "int32"
|
|
965
|
+
},
|
|
966
|
+
int4: {
|
|
967
|
+
type: "int32"
|
|
968
|
+
},
|
|
969
|
+
boolean: {
|
|
970
|
+
type: "boolean"
|
|
971
|
+
},
|
|
972
|
+
bool: {
|
|
973
|
+
type: "boolean"
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
function attributeToField(attribute = {}, options) {
|
|
977
|
+
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
978
|
+
const field = {
|
|
979
|
+
name: attribute.attribute,
|
|
980
|
+
// what happens if attribute type is string...
|
|
981
|
+
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
982
|
+
...fieldTypes
|
|
983
|
+
};
|
|
984
|
+
if (typeof attribute.min === "number") {
|
|
985
|
+
field.min = attribute.min;
|
|
986
|
+
}
|
|
987
|
+
if (typeof attribute.max === "number") {
|
|
988
|
+
field.max = attribute.max;
|
|
989
|
+
}
|
|
990
|
+
if (typeof attribute.count === "number") {
|
|
991
|
+
field.uniqueValueCount = attribute.count;
|
|
992
|
+
}
|
|
993
|
+
if (attribute.values) {
|
|
994
|
+
field.values = attribute.values;
|
|
995
|
+
}
|
|
996
|
+
if (field.values && typeof options.maxValues === "number") {
|
|
997
|
+
field.values = field.values?.slice(0, options.maxValues);
|
|
998
|
+
}
|
|
999
|
+
return field;
|
|
1000
|
+
}
|
|
1001
|
+
function attributeTypeToFieldType(aType) {
|
|
1002
|
+
const type = aType.toLowerCase();
|
|
1003
|
+
if (!type || !attrTypeMap[type]) {
|
|
1004
|
+
}
|
|
1005
|
+
return attrTypeMap[type] || { type: "string" };
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/tilejson-loader.ts
|
|
1009
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1010
|
+
var TileJSONLoader = {
|
|
1011
|
+
dataType: null,
|
|
1012
|
+
batchType: null,
|
|
1013
|
+
name: "TileJSON",
|
|
1014
|
+
id: "tilejson",
|
|
1015
|
+
module: "pmtiles",
|
|
1016
|
+
version: VERSION,
|
|
1017
|
+
worker: true,
|
|
1018
|
+
extensions: ["json"],
|
|
1019
|
+
mimeTypes: ["application/json"],
|
|
1020
|
+
text: true,
|
|
1021
|
+
options: {
|
|
1022
|
+
tilejson: {
|
|
1023
|
+
maxValues: void 0
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
parse: async (arrayBuffer, options) => {
|
|
1027
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
1028
|
+
const json = JSON.parse(jsonString);
|
|
1029
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
1030
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
1031
|
+
},
|
|
1032
|
+
parseTextSync: (text, options) => {
|
|
1033
|
+
const json = JSON.parse(text);
|
|
1034
|
+
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
1035
|
+
return parseTileJSON(json, tilejsonOptions);
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
// ../schema/src/lib/table/simple-table/data-type.ts
|
|
1040
|
+
function getDataTypeFromValue(value, defaultNumberType = "float32") {
|
|
1041
|
+
if (value instanceof Date) {
|
|
1042
|
+
return "date-millisecond";
|
|
1043
|
+
}
|
|
1044
|
+
if (value instanceof Number) {
|
|
1045
|
+
return defaultNumberType;
|
|
1046
|
+
}
|
|
1047
|
+
if (typeof value === "string") {
|
|
1048
|
+
return "utf8";
|
|
1049
|
+
}
|
|
1050
|
+
if (value === null || value === "undefined") {
|
|
1051
|
+
return "null";
|
|
1052
|
+
}
|
|
1053
|
+
return "null";
|
|
1054
|
+
}
|
|
1055
|
+
function getDataTypeFromArray(array) {
|
|
1056
|
+
let type = getDataTypeFromTypedArray(array);
|
|
1057
|
+
if (type !== "null") {
|
|
1058
|
+
return { type, nullable: false };
|
|
1059
|
+
}
|
|
1060
|
+
if (array.length > 0) {
|
|
1061
|
+
type = getDataTypeFromValue(array[0]);
|
|
1062
|
+
return { type, nullable: true };
|
|
1063
|
+
}
|
|
1064
|
+
return { type: "null", nullable: true };
|
|
1065
|
+
}
|
|
1066
|
+
function getDataTypeFromTypedArray(array) {
|
|
1067
|
+
switch (array.constructor) {
|
|
1068
|
+
case Int8Array:
|
|
1069
|
+
return "int8";
|
|
1070
|
+
case Uint8Array:
|
|
1071
|
+
case Uint8ClampedArray:
|
|
1072
|
+
return "uint8";
|
|
1073
|
+
case Int16Array:
|
|
1074
|
+
return "int16";
|
|
1075
|
+
case Uint16Array:
|
|
1076
|
+
return "uint16";
|
|
1077
|
+
case Int32Array:
|
|
1078
|
+
return "int32";
|
|
1079
|
+
case Uint32Array:
|
|
1080
|
+
return "uint32";
|
|
1081
|
+
case Float32Array:
|
|
1082
|
+
return "float32";
|
|
1083
|
+
case Float64Array:
|
|
1084
|
+
return "float64";
|
|
1085
|
+
default:
|
|
1086
|
+
return "null";
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// ../schema/src/lib/table/simple-table/table-schema.ts
|
|
1091
|
+
function deduceTableSchema(table) {
|
|
1092
|
+
switch (table.shape) {
|
|
1093
|
+
case "array-row-table":
|
|
1094
|
+
case "object-row-table":
|
|
1095
|
+
return deduceSchemaFromRows(table.data);
|
|
1096
|
+
case "geojson-table":
|
|
1097
|
+
return deduceSchemaFromGeoJSON(table.features);
|
|
1098
|
+
case "columnar-table":
|
|
1099
|
+
return deduceSchemaFromColumns(table.data);
|
|
1100
|
+
case "arrow-table":
|
|
1101
|
+
default:
|
|
1102
|
+
throw new Error("Deduce schema");
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function deduceSchemaFromColumns(columnarTable) {
|
|
1106
|
+
const fields = [];
|
|
1107
|
+
for (const [columnName, column] of Object.entries(columnarTable)) {
|
|
1108
|
+
const field = deduceFieldFromColumn(column, columnName);
|
|
1109
|
+
fields.push(field);
|
|
1110
|
+
}
|
|
1111
|
+
return { fields, metadata: {} };
|
|
1112
|
+
}
|
|
1113
|
+
function deduceSchemaFromRows(rowTable) {
|
|
1114
|
+
if (!rowTable.length) {
|
|
1115
|
+
throw new Error("deduce from empty table");
|
|
1116
|
+
}
|
|
1117
|
+
const fields = [];
|
|
1118
|
+
const row0 = rowTable[0];
|
|
1119
|
+
for (const [columnName, value] of Object.entries(row0)) {
|
|
1120
|
+
fields.push(deduceFieldFromValue(value, columnName));
|
|
1121
|
+
}
|
|
1122
|
+
return { fields, metadata: {} };
|
|
1123
|
+
}
|
|
1124
|
+
function deduceSchemaFromGeoJSON(features2) {
|
|
1125
|
+
if (!features2.length) {
|
|
1126
|
+
throw new Error("deduce from empty table");
|
|
1127
|
+
}
|
|
1128
|
+
const fields = [];
|
|
1129
|
+
const row0 = features2[0].properties || {};
|
|
1130
|
+
for (const [columnName, value] of Object.entries(row0)) {
|
|
1131
|
+
fields.push(deduceFieldFromValue(value, columnName));
|
|
1132
|
+
}
|
|
1133
|
+
return { fields, metadata: {} };
|
|
1134
|
+
}
|
|
1135
|
+
function deduceFieldFromColumn(column, name) {
|
|
1136
|
+
if (ArrayBuffer.isView(column)) {
|
|
1137
|
+
const type = getDataTypeFromArray(column);
|
|
1138
|
+
return {
|
|
1139
|
+
name,
|
|
1140
|
+
type: type.type || "null",
|
|
1141
|
+
nullable: type.nullable
|
|
1142
|
+
// metadata: {}
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
if (Array.isArray(column) && column.length > 0) {
|
|
1146
|
+
const value = column[0];
|
|
1147
|
+
const type = getDataTypeFromValue(value);
|
|
1148
|
+
return {
|
|
1149
|
+
name,
|
|
1150
|
+
type,
|
|
1151
|
+
nullable: true
|
|
1152
|
+
// metadata: {},
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
throw new Error("empty table");
|
|
1156
|
+
}
|
|
1157
|
+
function deduceFieldFromValue(value, name) {
|
|
1158
|
+
const type = getDataTypeFromValue(value);
|
|
1159
|
+
return {
|
|
1160
|
+
name,
|
|
1161
|
+
type,
|
|
1162
|
+
nullable: true
|
|
1163
|
+
// metadata: {}
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
|
|
804
1167
|
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
805
1168
|
function _typeof(obj) {
|
|
806
1169
|
"@babel/helpers - typeof";
|
|
@@ -1361,11 +1724,11 @@ var __exports__ = (() => {
|
|
|
1361
1724
|
};
|
|
1362
1725
|
|
|
1363
1726
|
// ../gis/src/lib/binary-features/flat-geojson-to-binary.ts
|
|
1364
|
-
function flatGeojsonToBinary(
|
|
1365
|
-
const propArrayTypes = extractNumericPropTypes(
|
|
1727
|
+
function flatGeojsonToBinary(features2, geometryInfo, options) {
|
|
1728
|
+
const propArrayTypes = extractNumericPropTypes(features2);
|
|
1366
1729
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1367
1730
|
return fillArrays(
|
|
1368
|
-
|
|
1731
|
+
features2,
|
|
1369
1732
|
{
|
|
1370
1733
|
propArrayTypes,
|
|
1371
1734
|
...geometryInfo
|
|
@@ -1377,9 +1740,9 @@ var __exports__ = (() => {
|
|
|
1377
1740
|
}
|
|
1378
1741
|
);
|
|
1379
1742
|
}
|
|
1380
|
-
function extractNumericPropTypes(
|
|
1743
|
+
function extractNumericPropTypes(features2) {
|
|
1381
1744
|
const propArrayTypes = {};
|
|
1382
|
-
for (const feature of
|
|
1745
|
+
for (const feature of features2) {
|
|
1383
1746
|
if (feature.properties) {
|
|
1384
1747
|
for (const key in feature.properties) {
|
|
1385
1748
|
const val = feature.properties[key];
|
|
@@ -1389,7 +1752,7 @@ var __exports__ = (() => {
|
|
|
1389
1752
|
}
|
|
1390
1753
|
return propArrayTypes;
|
|
1391
1754
|
}
|
|
1392
|
-
function fillArrays(
|
|
1755
|
+
function fillArrays(features2, geometryInfo, options) {
|
|
1393
1756
|
const {
|
|
1394
1757
|
pointPositionsCount,
|
|
1395
1758
|
pointFeaturesCount,
|
|
@@ -1404,8 +1767,8 @@ var __exports__ = (() => {
|
|
|
1404
1767
|
coordLength
|
|
1405
1768
|
} = geometryInfo;
|
|
1406
1769
|
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
1407
|
-
const hasGlobalId =
|
|
1408
|
-
const GlobalFeatureIdsDataType =
|
|
1770
|
+
const hasGlobalId = features2[0] && "id" in features2[0];
|
|
1771
|
+
const GlobalFeatureIdsDataType = features2.length > 65535 ? Uint32Array : Uint16Array;
|
|
1409
1772
|
const points = {
|
|
1410
1773
|
type: "Point",
|
|
1411
1774
|
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
@@ -1460,7 +1823,7 @@ var __exports__ = (() => {
|
|
|
1460
1823
|
polygonFeature: 0,
|
|
1461
1824
|
feature: 0
|
|
1462
1825
|
};
|
|
1463
|
-
for (const feature of
|
|
1826
|
+
for (const feature of features2) {
|
|
1464
1827
|
const geometry = feature.geometry;
|
|
1465
1828
|
const properties = feature.properties || {};
|
|
1466
1829
|
switch (geometry.type) {
|
|
@@ -1704,7 +2067,7 @@ var __exports__ = (() => {
|
|
|
1704
2067
|
var navigator_ = globalThis.navigator || {};
|
|
1705
2068
|
|
|
1706
2069
|
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
|
|
1707
|
-
var
|
|
2070
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
|
|
1708
2071
|
var isBrowser3 = isBrowser2();
|
|
1709
2072
|
|
|
1710
2073
|
// ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
|
|
@@ -1889,7 +2252,7 @@ var __exports__ = (() => {
|
|
|
1889
2252
|
id: ""
|
|
1890
2253
|
};
|
|
1891
2254
|
_defineProperty(this, "id", void 0);
|
|
1892
|
-
_defineProperty(this, "VERSION",
|
|
2255
|
+
_defineProperty(this, "VERSION", VERSION2);
|
|
1893
2256
|
_defineProperty(this, "_startTs", getHiResTimestamp());
|
|
1894
2257
|
_defineProperty(this, "_deltaTs", getHiResTimestamp());
|
|
1895
2258
|
_defineProperty(this, "_storage", void 0);
|
|
@@ -2092,7 +2455,7 @@ var __exports__ = (() => {
|
|
|
2092
2455
|
return noop;
|
|
2093
2456
|
}
|
|
2094
2457
|
};
|
|
2095
|
-
_defineProperty(Log, "VERSION",
|
|
2458
|
+
_defineProperty(Log, "VERSION", VERSION2);
|
|
2096
2459
|
function normalizeLogLevel(logLevel) {
|
|
2097
2460
|
if (!logLevel) {
|
|
2098
2461
|
return 0;
|
|
@@ -2202,9 +2565,18 @@ var __exports__ = (() => {
|
|
|
2202
2565
|
});
|
|
2203
2566
|
|
|
2204
2567
|
// ../loader-utils/src/lib/log-utils/log.ts
|
|
2205
|
-
var
|
|
2206
|
-
var version =
|
|
2207
|
-
|
|
2568
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2569
|
+
var version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
|
|
2570
|
+
function createLog() {
|
|
2571
|
+
const log2 = new Log({ id: "loaders.gl" });
|
|
2572
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2573
|
+
globalThis.loaders.log = log2;
|
|
2574
|
+
globalThis.loaders.version = version;
|
|
2575
|
+
globalThis.probe = globalThis.probe || {};
|
|
2576
|
+
globalThis.probe.loaders = log2;
|
|
2577
|
+
return log2;
|
|
2578
|
+
}
|
|
2579
|
+
var log = createLog();
|
|
2208
2580
|
|
|
2209
2581
|
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
2210
2582
|
var pathPrefix = "";
|
|
@@ -2280,6 +2652,39 @@ var __exports__ = (() => {
|
|
|
2280
2652
|
}
|
|
2281
2653
|
return sum;
|
|
2282
2654
|
}
|
|
2655
|
+
function convertToLocalCoordinates(coordinates, extent) {
|
|
2656
|
+
if (Array.isArray(coordinates[0])) {
|
|
2657
|
+
for (const subcoords of coordinates) {
|
|
2658
|
+
convertToLocalCoordinates(subcoords, extent);
|
|
2659
|
+
}
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
const p = coordinates;
|
|
2663
|
+
p[0] /= extent;
|
|
2664
|
+
p[1] /= extent;
|
|
2665
|
+
}
|
|
2666
|
+
function convertToLocalCoordinatesFlat(data, extent) {
|
|
2667
|
+
for (let i = 0; i < data.length; ++i) {
|
|
2668
|
+
data[i] /= extent;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
function projectToLngLat(line, tileIndex, extent) {
|
|
2672
|
+
if (typeof line[0][0] !== "number") {
|
|
2673
|
+
for (const point of line) {
|
|
2674
|
+
projectToLngLat(point, tileIndex, extent);
|
|
2675
|
+
}
|
|
2676
|
+
return;
|
|
2677
|
+
}
|
|
2678
|
+
const size = extent * Math.pow(2, tileIndex.z);
|
|
2679
|
+
const x0 = extent * tileIndex.x;
|
|
2680
|
+
const y0 = extent * tileIndex.y;
|
|
2681
|
+
for (let j = 0; j < line.length; j++) {
|
|
2682
|
+
const p = line[j];
|
|
2683
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
2684
|
+
const y2 = 180 - (p[1] + y0) * 360 / size;
|
|
2685
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2283
2688
|
function projectToLngLatFlat(data, tileIndex, extent) {
|
|
2284
2689
|
const { x, y, z } = tileIndex;
|
|
2285
2690
|
const size = extent * Math.pow(2, z);
|
|
@@ -2389,39 +2794,37 @@ var __exports__ = (() => {
|
|
|
2389
2794
|
this._geometryInfo = geometryInfo;
|
|
2390
2795
|
pbf.readFields(readFeature, this, end);
|
|
2391
2796
|
}
|
|
2392
|
-
|
|
2797
|
+
toGeoJSONFeature(coordinates, tileIndex) {
|
|
2393
2798
|
const coords = this.loadGeometry();
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
const p = line[j];
|
|
2404
|
-
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
2405
|
-
const y2 = 180 - (p[1] + y0) * 360 / size;
|
|
2406
|
-
p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
2407
|
-
}
|
|
2799
|
+
switch (coordinates) {
|
|
2800
|
+
case "wgs84":
|
|
2801
|
+
return _toGeoJSONFeature(
|
|
2802
|
+
this,
|
|
2803
|
+
coords,
|
|
2804
|
+
(line) => projectToLngLat(line, tileIndex, this.extent)
|
|
2805
|
+
);
|
|
2806
|
+
default:
|
|
2807
|
+
return _toGeoJSONFeature(this, coords, convertToLocalCoordinates);
|
|
2408
2808
|
}
|
|
2409
|
-
return _toGeoJSON(this, coords, project);
|
|
2410
2809
|
}
|
|
2411
2810
|
/**
|
|
2412
2811
|
*
|
|
2413
2812
|
* @param options
|
|
2414
2813
|
* @returns
|
|
2415
2814
|
*/
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2815
|
+
toBinaryFeature(coordinates, tileIndex) {
|
|
2816
|
+
const geom = this.loadFlatGeometry();
|
|
2817
|
+
switch (coordinates) {
|
|
2818
|
+
case "wgs84":
|
|
2819
|
+
return this._toBinaryCoordinates(
|
|
2820
|
+
geom,
|
|
2821
|
+
(coords) => projectToLngLatFlat(coords, tileIndex, this.extent)
|
|
2822
|
+
);
|
|
2823
|
+
default:
|
|
2824
|
+
return this._toBinaryCoordinates(geom, convertToLocalCoordinatesFlat);
|
|
2419
2825
|
}
|
|
2420
|
-
const tileIndex = options;
|
|
2421
|
-
return this._toBinaryCoordinates(
|
|
2422
|
-
(data) => projectToLngLatFlat(data, tileIndex, this.extent)
|
|
2423
|
-
);
|
|
2424
2826
|
}
|
|
2827
|
+
/** Read a bounding box from the feature */
|
|
2425
2828
|
// eslint-disable-next-line max-statements
|
|
2426
2829
|
bbox() {
|
|
2427
2830
|
const pbf = this._pbf;
|
|
@@ -2465,10 +2868,9 @@ var __exports__ = (() => {
|
|
|
2465
2868
|
* @param transform
|
|
2466
2869
|
* @returns result
|
|
2467
2870
|
*/
|
|
2468
|
-
_toBinaryCoordinates(transform) {
|
|
2469
|
-
const geom = this.loadFlatGeometry();
|
|
2871
|
+
_toBinaryCoordinates(geom, transform) {
|
|
2470
2872
|
let geometry;
|
|
2471
|
-
transform(geom.data, this);
|
|
2873
|
+
transform(geom.data, this.extent);
|
|
2472
2874
|
const coordLength = 2;
|
|
2473
2875
|
switch (this.type) {
|
|
2474
2876
|
case 1:
|
|
@@ -2545,6 +2947,28 @@ var __exports__ = (() => {
|
|
|
2545
2947
|
lines.push(line);
|
|
2546
2948
|
return lines;
|
|
2547
2949
|
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Expands the protobuf data to an intermediate Flat GeoJSON
|
|
2952
|
+
* data format, which maps closely to the binary data buffers.
|
|
2953
|
+
* It is similar to GeoJSON, but rather than storing the coordinates
|
|
2954
|
+
* in multidimensional arrays, we have a 1D `data` with all the
|
|
2955
|
+
* coordinates, and then index into this using the `indices`
|
|
2956
|
+
* parameter, e.g.
|
|
2957
|
+
*
|
|
2958
|
+
* geometry: {
|
|
2959
|
+
* type: 'Point', data: [1,2], indices: [0]
|
|
2960
|
+
* }
|
|
2961
|
+
* geometry: {
|
|
2962
|
+
* type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
2963
|
+
* }
|
|
2964
|
+
* geometry: {
|
|
2965
|
+
* type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
2966
|
+
* }
|
|
2967
|
+
* Thus the indices member lets us look up the relevant range
|
|
2968
|
+
* from the data array.
|
|
2969
|
+
* The Multi* versions of the above types share the same data
|
|
2970
|
+
* structure, just with multiple elements in the indices array
|
|
2971
|
+
*/
|
|
2548
2972
|
// eslint-disable-next-line complexity, max-statements
|
|
2549
2973
|
loadFlatGeometry() {
|
|
2550
2974
|
const pbf = this._pbf;
|
|
@@ -2587,7 +3011,7 @@ var __exports__ = (() => {
|
|
|
2587
3011
|
}
|
|
2588
3012
|
};
|
|
2589
3013
|
__publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
|
|
2590
|
-
function
|
|
3014
|
+
function _toGeoJSONFeature(vtFeature, coords, transform) {
|
|
2591
3015
|
let type = VectorTileFeature.types[vtFeature.type];
|
|
2592
3016
|
let i;
|
|
2593
3017
|
let j;
|
|
@@ -2599,19 +3023,19 @@ var __exports__ = (() => {
|
|
|
2599
3023
|
points[i] = coords[i][0];
|
|
2600
3024
|
}
|
|
2601
3025
|
coordinates = points;
|
|
2602
|
-
transform(coordinates, vtFeature);
|
|
3026
|
+
transform(coordinates, vtFeature.extent);
|
|
2603
3027
|
break;
|
|
2604
3028
|
case 2:
|
|
2605
3029
|
coordinates = coords;
|
|
2606
3030
|
for (i = 0; i < coordinates.length; i++) {
|
|
2607
|
-
transform(coordinates[i], vtFeature);
|
|
3031
|
+
transform(coordinates[i], vtFeature.extent);
|
|
2608
3032
|
}
|
|
2609
3033
|
break;
|
|
2610
3034
|
case 3:
|
|
2611
3035
|
coordinates = classifyRings(coords);
|
|
2612
3036
|
for (i = 0; i < coordinates.length; i++) {
|
|
2613
3037
|
for (j = 0; j < coordinates[i].length; j++) {
|
|
2614
|
-
transform(coordinates[i][j], vtFeature);
|
|
3038
|
+
transform(coordinates[i][j], vtFeature.extent);
|
|
2615
3039
|
}
|
|
2616
3040
|
}
|
|
2617
3041
|
break;
|
|
@@ -2632,7 +3056,8 @@ var __exports__ = (() => {
|
|
|
2632
3056
|
properties: vtFeature.properties
|
|
2633
3057
|
};
|
|
2634
3058
|
if (vtFeature.id !== null) {
|
|
2635
|
-
result.
|
|
3059
|
+
result.properties ||= {};
|
|
3060
|
+
result.properties.id = vtFeature.id;
|
|
2636
3061
|
}
|
|
2637
3062
|
return result;
|
|
2638
3063
|
}
|
|
@@ -2791,7 +3216,7 @@ var __exports__ = (() => {
|
|
|
2791
3216
|
return binaryData;
|
|
2792
3217
|
}
|
|
2793
3218
|
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2794
|
-
const
|
|
3219
|
+
const features2 = [];
|
|
2795
3220
|
const geometryInfo = {
|
|
2796
3221
|
coordLength: 2,
|
|
2797
3222
|
pointPositionsCount: 0,
|
|
@@ -2805,7 +3230,7 @@ var __exports__ = (() => {
|
|
|
2805
3230
|
polygonFeaturesCount: 0
|
|
2806
3231
|
};
|
|
2807
3232
|
if (arrayBuffer.byteLength <= 0) {
|
|
2808
|
-
return [
|
|
3233
|
+
return [features2, geometryInfo];
|
|
2809
3234
|
}
|
|
2810
3235
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2811
3236
|
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
@@ -2817,16 +3242,16 @@ var __exports__ = (() => {
|
|
|
2817
3242
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
2818
3243
|
const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
|
|
2819
3244
|
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
2820
|
-
|
|
3245
|
+
features2.push(decodedFeature);
|
|
2821
3246
|
}
|
|
2822
3247
|
});
|
|
2823
|
-
return [
|
|
3248
|
+
return [features2, geometryInfo];
|
|
2824
3249
|
}
|
|
2825
3250
|
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
2826
3251
|
if (arrayBuffer.byteLength <= 0) {
|
|
2827
3252
|
return [];
|
|
2828
3253
|
}
|
|
2829
|
-
const
|
|
3254
|
+
const features2 = [];
|
|
2830
3255
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2831
3256
|
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2832
3257
|
selectedLayers.forEach((layerName) => {
|
|
@@ -2837,10 +3262,10 @@ var __exports__ = (() => {
|
|
|
2837
3262
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
2838
3263
|
const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
|
|
2839
3264
|
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
2840
|
-
|
|
3265
|
+
features2.push(decodedFeature);
|
|
2841
3266
|
}
|
|
2842
3267
|
});
|
|
2843
|
-
return
|
|
3268
|
+
return features2;
|
|
2844
3269
|
}
|
|
2845
3270
|
function checkOptions(options) {
|
|
2846
3271
|
if (!options?.mvt) {
|
|
@@ -2855,9 +3280,9 @@ var __exports__ = (() => {
|
|
|
2855
3280
|
return options.mvt;
|
|
2856
3281
|
}
|
|
2857
3282
|
function getDecodedFeature(feature, options, layerName) {
|
|
2858
|
-
const decodedFeature = feature.
|
|
2859
|
-
|
|
2860
|
-
options.
|
|
3283
|
+
const decodedFeature = feature.toGeoJSONFeature(
|
|
3284
|
+
options.coordinates || "local",
|
|
3285
|
+
options.tileIndex
|
|
2861
3286
|
);
|
|
2862
3287
|
if (options.layerProperty) {
|
|
2863
3288
|
decodedFeature.properties ||= {};
|
|
@@ -2866,39 +3291,22 @@ var __exports__ = (() => {
|
|
|
2866
3291
|
return decodedFeature;
|
|
2867
3292
|
}
|
|
2868
3293
|
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2869
|
-
const decodedFeature = feature.
|
|
2870
|
-
// @ts-expect-error
|
|
2871
|
-
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
2872
|
-
);
|
|
3294
|
+
const decodedFeature = feature.toBinaryFeature(options.coordinates || "local", options.tileIndex);
|
|
2873
3295
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2874
3296
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2875
3297
|
}
|
|
2876
3298
|
return decodedFeature;
|
|
2877
3299
|
}
|
|
2878
|
-
function transformToLocalCoordinates(line, feature) {
|
|
2879
|
-
const { extent } = feature;
|
|
2880
|
-
for (let i = 0; i < line.length; i++) {
|
|
2881
|
-
const p = line[i];
|
|
2882
|
-
p[0] /= extent;
|
|
2883
|
-
p[1] /= extent;
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2887
|
-
const { extent } = feature;
|
|
2888
|
-
for (let i = 0, il = data.length; i < il; ++i) {
|
|
2889
|
-
data[i] /= extent;
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
3300
|
|
|
2893
3301
|
// src/mvt-loader.ts
|
|
2894
|
-
var
|
|
3302
|
+
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2895
3303
|
var MVTWorkerLoader = {
|
|
2896
3304
|
dataType: null,
|
|
2897
3305
|
batchType: null,
|
|
2898
3306
|
name: "Mapbox Vector Tile",
|
|
2899
3307
|
id: "mvt",
|
|
2900
3308
|
module: "mvt",
|
|
2901
|
-
version:
|
|
3309
|
+
version: VERSION4,
|
|
2902
3310
|
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
2903
3311
|
extensions: ["mvt", "pbf"],
|
|
2904
3312
|
mimeTypes: [
|
|
@@ -2926,241 +3334,6 @@ var __exports__ = (() => {
|
|
|
2926
3334
|
binary: true
|
|
2927
3335
|
};
|
|
2928
3336
|
|
|
2929
|
-
// src/lib/parse-tilejson.ts
|
|
2930
|
-
var isObject = (x) => x !== null && typeof x === "object";
|
|
2931
|
-
function parseTileJSON(jsonMetadata, options) {
|
|
2932
|
-
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
2933
|
-
return null;
|
|
2934
|
-
}
|
|
2935
|
-
let tileJSON = {
|
|
2936
|
-
name: jsonMetadata.name || "",
|
|
2937
|
-
description: jsonMetadata.description || ""
|
|
2938
|
-
};
|
|
2939
|
-
if (typeof jsonMetadata.generator === "string") {
|
|
2940
|
-
tileJSON.generator = jsonMetadata.generator;
|
|
2941
|
-
}
|
|
2942
|
-
if (typeof jsonMetadata.generator_options === "string") {
|
|
2943
|
-
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
2944
|
-
}
|
|
2945
|
-
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
2946
|
-
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
2947
|
-
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
2948
|
-
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
2949
|
-
if (typeof jsonMetadata?.json === "string") {
|
|
2950
|
-
try {
|
|
2951
|
-
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
2952
|
-
} catch (error) {
|
|
2953
|
-
console.warn("Failed to parse tilejson.json field", error);
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
2957
|
-
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
2958
|
-
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
2959
|
-
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
2960
|
-
tileJSON = {
|
|
2961
|
-
...tileJSON,
|
|
2962
|
-
layers
|
|
2963
|
-
};
|
|
2964
|
-
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
2965
|
-
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
2966
|
-
}
|
|
2967
|
-
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
2968
|
-
tileJSON.minZoom = layers[0].minZoom || null;
|
|
2969
|
-
}
|
|
2970
|
-
return tileJSON;
|
|
2971
|
-
}
|
|
2972
|
-
function parseTileJSONLayers(layers) {
|
|
2973
|
-
if (!Array.isArray(layers)) {
|
|
2974
|
-
return [];
|
|
2975
|
-
}
|
|
2976
|
-
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
2977
|
-
}
|
|
2978
|
-
function parseTileJSONLayer(layer) {
|
|
2979
|
-
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
2980
|
-
name: key,
|
|
2981
|
-
...attributeTypeToFieldType(String(datatype))
|
|
2982
|
-
}));
|
|
2983
|
-
const layer2 = { ...layer };
|
|
2984
|
-
delete layer2.fields;
|
|
2985
|
-
return {
|
|
2986
|
-
name: layer.id || "",
|
|
2987
|
-
...layer2,
|
|
2988
|
-
fields
|
|
2989
|
-
};
|
|
2990
|
-
}
|
|
2991
|
-
function parseTilestatsLayers(tilestats, options) {
|
|
2992
|
-
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
2993
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
2994
|
-
}
|
|
2995
|
-
return [];
|
|
2996
|
-
}
|
|
2997
|
-
function parseTilestatsForLayer(layer, options) {
|
|
2998
|
-
const fields = [];
|
|
2999
|
-
const indexedAttributes = {};
|
|
3000
|
-
const attributes = layer.attributes || [];
|
|
3001
|
-
for (const attribute of attributes) {
|
|
3002
|
-
const name = attribute.attribute;
|
|
3003
|
-
if (typeof name === "string") {
|
|
3004
|
-
if (name.split("|").length > 1) {
|
|
3005
|
-
const fname = name.split("|")[0];
|
|
3006
|
-
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
3007
|
-
indexedAttributes[fname].push(attribute);
|
|
3008
|
-
console.warn("ignoring tilestats indexed field", fname);
|
|
3009
|
-
} else if (!fields[name]) {
|
|
3010
|
-
fields.push(attributeToField(attribute, options));
|
|
3011
|
-
} else {
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
}
|
|
3015
|
-
return {
|
|
3016
|
-
name: layer.layer || "",
|
|
3017
|
-
dominantGeometry: layer.geometry,
|
|
3018
|
-
fields
|
|
3019
|
-
};
|
|
3020
|
-
}
|
|
3021
|
-
function mergeLayers(layers, tilestatsLayers) {
|
|
3022
|
-
return layers.map((layer) => {
|
|
3023
|
-
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
3024
|
-
const fields = tilestatsLayer?.fields || [];
|
|
3025
|
-
const layer2 = { ...layer };
|
|
3026
|
-
delete layer2.fields;
|
|
3027
|
-
return {
|
|
3028
|
-
...layer2,
|
|
3029
|
-
...tilestatsLayer,
|
|
3030
|
-
fields
|
|
3031
|
-
};
|
|
3032
|
-
});
|
|
3033
|
-
}
|
|
3034
|
-
function parseBounds(bounds) {
|
|
3035
|
-
const result = fromArrayOrString(bounds);
|
|
3036
|
-
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
3037
|
-
return [
|
|
3038
|
-
[result[0], result[1]],
|
|
3039
|
-
[result[2], result[3]]
|
|
3040
|
-
];
|
|
3041
|
-
}
|
|
3042
|
-
return void 0;
|
|
3043
|
-
}
|
|
3044
|
-
function parseCenter(center) {
|
|
3045
|
-
const result = fromArrayOrString(center);
|
|
3046
|
-
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
3047
|
-
return result;
|
|
3048
|
-
}
|
|
3049
|
-
return null;
|
|
3050
|
-
}
|
|
3051
|
-
function safeParseFloat(input) {
|
|
3052
|
-
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
3053
|
-
return result === null || isNaN(result) ? null : result;
|
|
3054
|
-
}
|
|
3055
|
-
function isLat(num) {
|
|
3056
|
-
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
3057
|
-
}
|
|
3058
|
-
function isLng(num) {
|
|
3059
|
-
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
3060
|
-
}
|
|
3061
|
-
function isZoom(num) {
|
|
3062
|
-
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
3063
|
-
}
|
|
3064
|
-
function fromArrayOrString(data) {
|
|
3065
|
-
if (typeof data === "string") {
|
|
3066
|
-
return data.split(",").map(parseFloat);
|
|
3067
|
-
} else if (Array.isArray(data)) {
|
|
3068
|
-
return data;
|
|
3069
|
-
}
|
|
3070
|
-
return null;
|
|
3071
|
-
}
|
|
3072
|
-
var attrTypeMap = {
|
|
3073
|
-
number: {
|
|
3074
|
-
type: "float32"
|
|
3075
|
-
},
|
|
3076
|
-
numeric: {
|
|
3077
|
-
type: "float32"
|
|
3078
|
-
},
|
|
3079
|
-
string: {
|
|
3080
|
-
type: "utf8"
|
|
3081
|
-
},
|
|
3082
|
-
vachar: {
|
|
3083
|
-
type: "utf8"
|
|
3084
|
-
},
|
|
3085
|
-
float: {
|
|
3086
|
-
type: "float32"
|
|
3087
|
-
},
|
|
3088
|
-
int: {
|
|
3089
|
-
type: "int32"
|
|
3090
|
-
},
|
|
3091
|
-
int4: {
|
|
3092
|
-
type: "int32"
|
|
3093
|
-
},
|
|
3094
|
-
boolean: {
|
|
3095
|
-
type: "boolean"
|
|
3096
|
-
},
|
|
3097
|
-
bool: {
|
|
3098
|
-
type: "boolean"
|
|
3099
|
-
}
|
|
3100
|
-
};
|
|
3101
|
-
function attributeToField(attribute = {}, options) {
|
|
3102
|
-
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
3103
|
-
const field = {
|
|
3104
|
-
name: attribute.attribute,
|
|
3105
|
-
// what happens if attribute type is string...
|
|
3106
|
-
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
3107
|
-
...fieldTypes
|
|
3108
|
-
};
|
|
3109
|
-
if (typeof attribute.min === "number") {
|
|
3110
|
-
field.min = attribute.min;
|
|
3111
|
-
}
|
|
3112
|
-
if (typeof attribute.max === "number") {
|
|
3113
|
-
field.max = attribute.max;
|
|
3114
|
-
}
|
|
3115
|
-
if (typeof attribute.count === "number") {
|
|
3116
|
-
field.uniqueValueCount = attribute.count;
|
|
3117
|
-
}
|
|
3118
|
-
if (attribute.values) {
|
|
3119
|
-
field.values = attribute.values;
|
|
3120
|
-
}
|
|
3121
|
-
if (field.values && typeof options.maxValues === "number") {
|
|
3122
|
-
field.values = field.values?.slice(0, options.maxValues);
|
|
3123
|
-
}
|
|
3124
|
-
return field;
|
|
3125
|
-
}
|
|
3126
|
-
function attributeTypeToFieldType(aType) {
|
|
3127
|
-
const type = aType.toLowerCase();
|
|
3128
|
-
if (!type || !attrTypeMap[type]) {
|
|
3129
|
-
}
|
|
3130
|
-
return attrTypeMap[type] || { type: "string" };
|
|
3131
|
-
}
|
|
3132
|
-
|
|
3133
|
-
// src/tilejson-loader.ts
|
|
3134
|
-
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3135
|
-
var TileJSONLoader = {
|
|
3136
|
-
dataType: null,
|
|
3137
|
-
batchType: null,
|
|
3138
|
-
name: "TileJSON",
|
|
3139
|
-
id: "tilejson",
|
|
3140
|
-
module: "pmtiles",
|
|
3141
|
-
version: VERSION4,
|
|
3142
|
-
worker: true,
|
|
3143
|
-
extensions: ["json"],
|
|
3144
|
-
mimeTypes: ["application/json"],
|
|
3145
|
-
text: true,
|
|
3146
|
-
options: {
|
|
3147
|
-
tilejson: {
|
|
3148
|
-
maxValues: void 0
|
|
3149
|
-
}
|
|
3150
|
-
},
|
|
3151
|
-
parse: async (arrayBuffer, options) => {
|
|
3152
|
-
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
3153
|
-
const json = JSON.parse(jsonString);
|
|
3154
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3155
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3156
|
-
},
|
|
3157
|
-
parseTextSync: (text, options) => {
|
|
3158
|
-
const json = JSON.parse(text);
|
|
3159
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3160
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3161
|
-
}
|
|
3162
|
-
};
|
|
3163
|
-
|
|
3164
3337
|
// ../images/src/lib/utils/version.ts
|
|
3165
3338
|
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3166
3339
|
|
|
@@ -3568,9 +3741,29 @@ var __exports__ = (() => {
|
|
|
3568
3741
|
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
3569
3742
|
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
3570
3743
|
};
|
|
3571
|
-
|
|
3572
|
-
// src/mvt-source.ts
|
|
3573
|
-
var MVTSource =
|
|
3744
|
+
|
|
3745
|
+
// src/mvt-source.ts
|
|
3746
|
+
var MVTSource = {
|
|
3747
|
+
name: "MVT",
|
|
3748
|
+
id: "mvt",
|
|
3749
|
+
module: "mvt",
|
|
3750
|
+
version: "0.0.0",
|
|
3751
|
+
extensions: ["mvt"],
|
|
3752
|
+
mimeTypes: ["application/octet-stream"],
|
|
3753
|
+
options: {
|
|
3754
|
+
mvt: {
|
|
3755
|
+
// TODO - add options here
|
|
3756
|
+
}
|
|
3757
|
+
},
|
|
3758
|
+
type: "mvt",
|
|
3759
|
+
fromUrl: true,
|
|
3760
|
+
fromBlob: false,
|
|
3761
|
+
testURL: (url) => true,
|
|
3762
|
+
createDataSource(url, props) {
|
|
3763
|
+
return new MVTTileSource(url, props);
|
|
3764
|
+
}
|
|
3765
|
+
};
|
|
3766
|
+
var MVTTileSource = class extends DataSource {
|
|
3574
3767
|
props;
|
|
3575
3768
|
url;
|
|
3576
3769
|
metadataUrl = null;
|
|
@@ -3579,12 +3772,12 @@ var __exports__ = (() => {
|
|
|
3579
3772
|
metadata;
|
|
3580
3773
|
extension;
|
|
3581
3774
|
mimeType = null;
|
|
3582
|
-
constructor(props) {
|
|
3775
|
+
constructor(url, props) {
|
|
3583
3776
|
super(props);
|
|
3584
3777
|
this.props = props;
|
|
3585
|
-
this.url = resolvePath(
|
|
3586
|
-
this.metadataUrl = props.metadataUrl
|
|
3587
|
-
this.extension = props.extension || ".png";
|
|
3778
|
+
this.url = resolvePath(url);
|
|
3779
|
+
this.metadataUrl = props.mvt?.metadataUrl || `${this.url}/tilejson.json`;
|
|
3780
|
+
this.extension = props.mvt?.extension || ".png";
|
|
3588
3781
|
this.data = this.url;
|
|
3589
3782
|
this.getTileData = this.getTileData.bind(this);
|
|
3590
3783
|
this.metadata = this.getMetadata();
|
|
@@ -3615,8 +3808,8 @@ var __exports__ = (() => {
|
|
|
3615
3808
|
getTileMIMEType() {
|
|
3616
3809
|
return this.mimeType;
|
|
3617
3810
|
}
|
|
3618
|
-
async getTile(
|
|
3619
|
-
const { x, y, z } =
|
|
3811
|
+
async getTile(parameters) {
|
|
3812
|
+
const { x, y, z } = parameters;
|
|
3620
3813
|
const tileUrl = this.getTileURL(x, y, z);
|
|
3621
3814
|
const response = await this.fetch(tileUrl);
|
|
3622
3815
|
if (!response.ok) {
|
|
@@ -3627,8 +3820,8 @@ var __exports__ = (() => {
|
|
|
3627
3820
|
}
|
|
3628
3821
|
// Tile Source interface implementation: deck.gl compatible API
|
|
3629
3822
|
// TODO - currently only handles image tiles, not vector tiles
|
|
3630
|
-
async getTileData(
|
|
3631
|
-
const { x, y, z } =
|
|
3823
|
+
async getTileData(parameters) {
|
|
3824
|
+
const { x, y, z } = parameters.index;
|
|
3632
3825
|
const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
|
|
3633
3826
|
if (arrayBuffer === null) {
|
|
3634
3827
|
return null;
|
|
@@ -3682,33 +3875,505 @@ var __exports__ = (() => {
|
|
|
3682
3875
|
throw new Error(this.schema);
|
|
3683
3876
|
}
|
|
3684
3877
|
}
|
|
3685
|
-
};
|
|
3686
|
-
function isURLTemplate(s) {
|
|
3687
|
-
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
3878
|
+
};
|
|
3879
|
+
function isURLTemplate(s) {
|
|
3880
|
+
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
3881
|
+
}
|
|
3882
|
+
var xRegex = new RegExp("{x}", "g");
|
|
3883
|
+
var yRegex = new RegExp("{y}", "g");
|
|
3884
|
+
var zRegex = new RegExp("{z}", "g");
|
|
3885
|
+
function getURLFromTemplate(template, x, y, z, id = "0") {
|
|
3886
|
+
if (Array.isArray(template)) {
|
|
3887
|
+
const i = stringHash(id) % template.length;
|
|
3888
|
+
template = template[i];
|
|
3889
|
+
}
|
|
3890
|
+
let url = template;
|
|
3891
|
+
url = url.replace(xRegex, String(x));
|
|
3892
|
+
url = url.replace(yRegex, String(y));
|
|
3893
|
+
url = url.replace(zRegex, String(z));
|
|
3894
|
+
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
3895
|
+
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
3896
|
+
}
|
|
3897
|
+
return url;
|
|
3898
|
+
}
|
|
3899
|
+
function stringHash(s) {
|
|
3900
|
+
return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
|
|
3901
|
+
}
|
|
3902
|
+
|
|
3903
|
+
// node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
|
|
3904
|
+
function getHiResTimestamp2() {
|
|
3905
|
+
let timestamp;
|
|
3906
|
+
if (typeof window !== "undefined" && window.performance) {
|
|
3907
|
+
timestamp = window.performance.now();
|
|
3908
|
+
} else if (typeof process !== "undefined" && process.hrtime) {
|
|
3909
|
+
const timeParts = process.hrtime();
|
|
3910
|
+
timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
|
|
3911
|
+
} else {
|
|
3912
|
+
timestamp = Date.now();
|
|
3913
|
+
}
|
|
3914
|
+
return timestamp;
|
|
3915
|
+
}
|
|
3916
|
+
|
|
3917
|
+
// node_modules/@probe.gl/stats/dist/lib/stat.js
|
|
3918
|
+
var Stat = class {
|
|
3919
|
+
constructor(name, type) {
|
|
3920
|
+
this.sampleSize = 1;
|
|
3921
|
+
this.time = 0;
|
|
3922
|
+
this.count = 0;
|
|
3923
|
+
this.samples = 0;
|
|
3924
|
+
this.lastTiming = 0;
|
|
3925
|
+
this.lastSampleTime = 0;
|
|
3926
|
+
this.lastSampleCount = 0;
|
|
3927
|
+
this._count = 0;
|
|
3928
|
+
this._time = 0;
|
|
3929
|
+
this._samples = 0;
|
|
3930
|
+
this._startTime = 0;
|
|
3931
|
+
this._timerPending = false;
|
|
3932
|
+
this.name = name;
|
|
3933
|
+
this.type = type;
|
|
3934
|
+
this.reset();
|
|
3935
|
+
}
|
|
3936
|
+
reset() {
|
|
3937
|
+
this.time = 0;
|
|
3938
|
+
this.count = 0;
|
|
3939
|
+
this.samples = 0;
|
|
3940
|
+
this.lastTiming = 0;
|
|
3941
|
+
this.lastSampleTime = 0;
|
|
3942
|
+
this.lastSampleCount = 0;
|
|
3943
|
+
this._count = 0;
|
|
3944
|
+
this._time = 0;
|
|
3945
|
+
this._samples = 0;
|
|
3946
|
+
this._startTime = 0;
|
|
3947
|
+
this._timerPending = false;
|
|
3948
|
+
return this;
|
|
3949
|
+
}
|
|
3950
|
+
setSampleSize(samples) {
|
|
3951
|
+
this.sampleSize = samples;
|
|
3952
|
+
return this;
|
|
3953
|
+
}
|
|
3954
|
+
/** Call to increment count (+1) */
|
|
3955
|
+
incrementCount() {
|
|
3956
|
+
this.addCount(1);
|
|
3957
|
+
return this;
|
|
3958
|
+
}
|
|
3959
|
+
/** Call to decrement count (-1) */
|
|
3960
|
+
decrementCount() {
|
|
3961
|
+
this.subtractCount(1);
|
|
3962
|
+
return this;
|
|
3963
|
+
}
|
|
3964
|
+
/** Increase count */
|
|
3965
|
+
addCount(value) {
|
|
3966
|
+
this._count += value;
|
|
3967
|
+
this._samples++;
|
|
3968
|
+
this._checkSampling();
|
|
3969
|
+
return this;
|
|
3970
|
+
}
|
|
3971
|
+
/** Decrease count */
|
|
3972
|
+
subtractCount(value) {
|
|
3973
|
+
this._count -= value;
|
|
3974
|
+
this._samples++;
|
|
3975
|
+
this._checkSampling();
|
|
3976
|
+
return this;
|
|
3977
|
+
}
|
|
3978
|
+
/** Add an arbitrary timing and bump the count */
|
|
3979
|
+
addTime(time) {
|
|
3980
|
+
this._time += time;
|
|
3981
|
+
this.lastTiming = time;
|
|
3982
|
+
this._samples++;
|
|
3983
|
+
this._checkSampling();
|
|
3984
|
+
return this;
|
|
3985
|
+
}
|
|
3986
|
+
/** Start a timer */
|
|
3987
|
+
timeStart() {
|
|
3988
|
+
this._startTime = getHiResTimestamp2();
|
|
3989
|
+
this._timerPending = true;
|
|
3990
|
+
return this;
|
|
3991
|
+
}
|
|
3992
|
+
/** End a timer. Adds to time and bumps the timing count. */
|
|
3993
|
+
timeEnd() {
|
|
3994
|
+
if (!this._timerPending) {
|
|
3995
|
+
return this;
|
|
3996
|
+
}
|
|
3997
|
+
this.addTime(getHiResTimestamp2() - this._startTime);
|
|
3998
|
+
this._timerPending = false;
|
|
3999
|
+
this._checkSampling();
|
|
4000
|
+
return this;
|
|
4001
|
+
}
|
|
4002
|
+
getSampleAverageCount() {
|
|
4003
|
+
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
|
|
4004
|
+
}
|
|
4005
|
+
/** Calculate average time / count for the previous window */
|
|
4006
|
+
getSampleAverageTime() {
|
|
4007
|
+
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
|
|
4008
|
+
}
|
|
4009
|
+
/** Calculate counts per second for the previous window */
|
|
4010
|
+
getSampleHz() {
|
|
4011
|
+
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
|
|
4012
|
+
}
|
|
4013
|
+
getAverageCount() {
|
|
4014
|
+
return this.samples > 0 ? this.count / this.samples : 0;
|
|
4015
|
+
}
|
|
4016
|
+
/** Calculate average time / count */
|
|
4017
|
+
getAverageTime() {
|
|
4018
|
+
return this.samples > 0 ? this.time / this.samples : 0;
|
|
4019
|
+
}
|
|
4020
|
+
/** Calculate counts per second */
|
|
4021
|
+
getHz() {
|
|
4022
|
+
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
|
|
4023
|
+
}
|
|
4024
|
+
_checkSampling() {
|
|
4025
|
+
if (this._samples === this.sampleSize) {
|
|
4026
|
+
this.lastSampleTime = this._time;
|
|
4027
|
+
this.lastSampleCount = this._count;
|
|
4028
|
+
this.count += this._count;
|
|
4029
|
+
this.time += this._time;
|
|
4030
|
+
this.samples += this._samples;
|
|
4031
|
+
this._time = 0;
|
|
4032
|
+
this._count = 0;
|
|
4033
|
+
this._samples = 0;
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
};
|
|
4037
|
+
|
|
4038
|
+
// node_modules/@probe.gl/stats/dist/lib/stats.js
|
|
4039
|
+
var Stats = class {
|
|
4040
|
+
constructor(options) {
|
|
4041
|
+
this.stats = {};
|
|
4042
|
+
this.id = options.id;
|
|
4043
|
+
this.stats = {};
|
|
4044
|
+
this._initializeStats(options.stats);
|
|
4045
|
+
Object.seal(this);
|
|
4046
|
+
}
|
|
4047
|
+
/** Acquire a stat. Create if it doesn't exist. */
|
|
4048
|
+
get(name, type = "count") {
|
|
4049
|
+
return this._getOrCreate({ name, type });
|
|
4050
|
+
}
|
|
4051
|
+
get size() {
|
|
4052
|
+
return Object.keys(this.stats).length;
|
|
4053
|
+
}
|
|
4054
|
+
/** Reset all stats */
|
|
4055
|
+
reset() {
|
|
4056
|
+
for (const stat of Object.values(this.stats)) {
|
|
4057
|
+
stat.reset();
|
|
4058
|
+
}
|
|
4059
|
+
return this;
|
|
4060
|
+
}
|
|
4061
|
+
forEach(fn) {
|
|
4062
|
+
for (const stat of Object.values(this.stats)) {
|
|
4063
|
+
fn(stat);
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
getTable() {
|
|
4067
|
+
const table = {};
|
|
4068
|
+
this.forEach((stat) => {
|
|
4069
|
+
table[stat.name] = {
|
|
4070
|
+
time: stat.time || 0,
|
|
4071
|
+
count: stat.count || 0,
|
|
4072
|
+
average: stat.getAverageTime() || 0,
|
|
4073
|
+
hz: stat.getHz() || 0
|
|
4074
|
+
};
|
|
4075
|
+
});
|
|
4076
|
+
return table;
|
|
4077
|
+
}
|
|
4078
|
+
_initializeStats(stats = []) {
|
|
4079
|
+
stats.forEach((stat) => this._getOrCreate(stat));
|
|
4080
|
+
}
|
|
4081
|
+
_getOrCreate(stat) {
|
|
4082
|
+
const { name, type } = stat;
|
|
4083
|
+
let result = this.stats[name];
|
|
4084
|
+
if (!result) {
|
|
4085
|
+
if (stat instanceof Stat) {
|
|
4086
|
+
result = stat;
|
|
4087
|
+
} else {
|
|
4088
|
+
result = new Stat(name, type);
|
|
4089
|
+
}
|
|
4090
|
+
this.stats[name] = result;
|
|
4091
|
+
}
|
|
4092
|
+
return result;
|
|
4093
|
+
}
|
|
4094
|
+
};
|
|
4095
|
+
|
|
4096
|
+
// src/lib/vector-tiler/proto-tile.ts
|
|
4097
|
+
function createProtoTile(features2, z, tx, ty, options) {
|
|
4098
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
4099
|
+
const tile = {
|
|
4100
|
+
protoFeatures: [],
|
|
4101
|
+
sourceFeatures: null,
|
|
4102
|
+
numPoints: 0,
|
|
4103
|
+
numSimplified: 0,
|
|
4104
|
+
numFeatures: features2.length,
|
|
4105
|
+
x: tx,
|
|
4106
|
+
y: ty,
|
|
4107
|
+
z,
|
|
4108
|
+
transformed: false,
|
|
4109
|
+
minX: 2,
|
|
4110
|
+
minY: 1,
|
|
4111
|
+
maxX: -1,
|
|
4112
|
+
maxY: 0
|
|
4113
|
+
};
|
|
4114
|
+
for (const feature of features2) {
|
|
4115
|
+
addProtoFeature(tile, feature, tolerance, options);
|
|
4116
|
+
}
|
|
4117
|
+
return tile;
|
|
4118
|
+
}
|
|
4119
|
+
function addProtoFeature(tile, feature, tolerance, options) {
|
|
4120
|
+
const geometry = feature.geometry;
|
|
4121
|
+
const type = feature.type;
|
|
4122
|
+
const simplifiedGeometry = [];
|
|
4123
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
4124
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
4125
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
4126
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
4127
|
+
let simplifiedType;
|
|
4128
|
+
switch (type) {
|
|
4129
|
+
case "Point":
|
|
4130
|
+
case "MultiPoint":
|
|
4131
|
+
simplifiedType = 1;
|
|
4132
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
4133
|
+
simplifiedGeometry.push(geometry[i], geometry[i + 1]);
|
|
4134
|
+
tile.numPoints++;
|
|
4135
|
+
tile.numSimplified++;
|
|
4136
|
+
}
|
|
4137
|
+
break;
|
|
4138
|
+
case "LineString":
|
|
4139
|
+
simplifiedType = 2;
|
|
4140
|
+
addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
|
|
4141
|
+
break;
|
|
4142
|
+
case "MultiLineString":
|
|
4143
|
+
simplifiedType = 2;
|
|
4144
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
4145
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
|
|
4146
|
+
}
|
|
4147
|
+
break;
|
|
4148
|
+
case "Polygon":
|
|
4149
|
+
simplifiedType = 3;
|
|
4150
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
4151
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
|
|
4152
|
+
}
|
|
4153
|
+
break;
|
|
4154
|
+
case "MultiPolygon":
|
|
4155
|
+
simplifiedType = 3;
|
|
4156
|
+
for (let k = 0; k < geometry.length; k++) {
|
|
4157
|
+
const polygon = geometry[k];
|
|
4158
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
4159
|
+
addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4162
|
+
break;
|
|
4163
|
+
default:
|
|
4164
|
+
throw new Error(`Unknown geometry type: ${type}`);
|
|
4165
|
+
}
|
|
4166
|
+
if (simplifiedGeometry.length) {
|
|
4167
|
+
let tags = feature.tags || null;
|
|
4168
|
+
if (type === "LineString" && options.lineMetrics) {
|
|
4169
|
+
tags = {};
|
|
4170
|
+
for (const key in feature.tags) {
|
|
4171
|
+
tags[key] = feature.tags[key];
|
|
4172
|
+
}
|
|
4173
|
+
tags.mapbox_clip_start = geometry.start / geometry.size;
|
|
4174
|
+
tags.mapbox_clip_end = geometry.end / geometry.size;
|
|
4175
|
+
}
|
|
4176
|
+
const tileFeature = {
|
|
4177
|
+
geometry: simplifiedGeometry,
|
|
4178
|
+
simplifiedType,
|
|
4179
|
+
// @ts-expect-error
|
|
4180
|
+
tags
|
|
4181
|
+
};
|
|
4182
|
+
if (feature.id !== null) {
|
|
4183
|
+
tileFeature.id = feature.id;
|
|
4184
|
+
}
|
|
4185
|
+
tile.protoFeatures.push(tileFeature);
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
|
|
4189
|
+
const sqTolerance = tolerance * tolerance;
|
|
4190
|
+
if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
4191
|
+
tile.numPoints += geometry.length / 3;
|
|
4192
|
+
return;
|
|
4193
|
+
}
|
|
4194
|
+
const ring = [];
|
|
4195
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
4196
|
+
if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
|
|
4197
|
+
tile.numSimplified++;
|
|
4198
|
+
ring.push(geometry[i], geometry[i + 1]);
|
|
4199
|
+
}
|
|
4200
|
+
tile.numPoints++;
|
|
4201
|
+
}
|
|
4202
|
+
if (isPolygon)
|
|
4203
|
+
rewind(ring, isOuter);
|
|
4204
|
+
result.push(ring);
|
|
4205
|
+
}
|
|
4206
|
+
function rewind(ring, clockwise) {
|
|
4207
|
+
let area2 = 0;
|
|
4208
|
+
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
4209
|
+
area2 += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
4210
|
+
}
|
|
4211
|
+
if (area2 > 0 === clockwise) {
|
|
4212
|
+
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
4213
|
+
const x = ring[i];
|
|
4214
|
+
const y = ring[i + 1];
|
|
4215
|
+
ring[i] = ring[len - 2 - i];
|
|
4216
|
+
ring[i + 1] = ring[len - 1 - i];
|
|
4217
|
+
ring[len - 2 - i] = x;
|
|
4218
|
+
ring[len - 1 - i] = y;
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
|
|
4223
|
+
// src/lib/vector-tiler/transform-tile.ts
|
|
4224
|
+
function transformTile(protoTile, extent) {
|
|
4225
|
+
if (protoTile.transformed) {
|
|
4226
|
+
return protoTile;
|
|
4227
|
+
}
|
|
4228
|
+
const z2 = 1 << protoTile.z;
|
|
4229
|
+
const tx = protoTile.x;
|
|
4230
|
+
const ty = protoTile.y;
|
|
4231
|
+
for (const protoFeature of protoTile.protoFeatures) {
|
|
4232
|
+
const geom = protoFeature.geometry;
|
|
4233
|
+
const simplifiedType = protoFeature.simplifiedType;
|
|
4234
|
+
protoFeature.geometry = [];
|
|
4235
|
+
if (simplifiedType === 1) {
|
|
4236
|
+
for (let j = 0; j < geom.length; j += 2) {
|
|
4237
|
+
protoFeature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
4238
|
+
}
|
|
4239
|
+
} else {
|
|
4240
|
+
for (let j = 0; j < geom.length; j++) {
|
|
4241
|
+
const ring = [];
|
|
4242
|
+
for (let k = 0; k < geom[j].length; k += 2) {
|
|
4243
|
+
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
4244
|
+
}
|
|
4245
|
+
protoFeature.geometry.push(ring);
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
protoTile.transformed = true;
|
|
4250
|
+
return protoTile;
|
|
4251
|
+
}
|
|
4252
|
+
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
4253
|
+
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4256
|
+
// src/lib/vector-tiler/tile-to-geojson.ts
|
|
4257
|
+
function convertTileToGeoJSON(protoTile, props) {
|
|
4258
|
+
const features2 = [];
|
|
4259
|
+
for (const rawFeature of protoTile.protoFeatures) {
|
|
4260
|
+
if (!rawFeature || !rawFeature.geometry) {
|
|
4261
|
+
continue;
|
|
4262
|
+
}
|
|
4263
|
+
let type;
|
|
4264
|
+
let coordinates;
|
|
4265
|
+
switch (rawFeature.simplifiedType) {
|
|
4266
|
+
case 1:
|
|
4267
|
+
if (rawFeature.geometry.length === 1) {
|
|
4268
|
+
type = "Point";
|
|
4269
|
+
coordinates = rawFeature.geometry[0];
|
|
4270
|
+
} else {
|
|
4271
|
+
type = "MultiPoint";
|
|
4272
|
+
coordinates = rawFeature.geometry;
|
|
4273
|
+
}
|
|
4274
|
+
break;
|
|
4275
|
+
case 2:
|
|
4276
|
+
if (rawFeature.geometry.length === 1) {
|
|
4277
|
+
type = "LineString";
|
|
4278
|
+
coordinates = rawFeature.geometry[0];
|
|
4279
|
+
} else {
|
|
4280
|
+
type = "MultiLineString";
|
|
4281
|
+
coordinates = rawFeature.geometry;
|
|
4282
|
+
}
|
|
4283
|
+
break;
|
|
4284
|
+
case 3:
|
|
4285
|
+
if (rawFeature.geometry.length > 1) {
|
|
4286
|
+
type = "MultiPolygon";
|
|
4287
|
+
coordinates = [rawFeature.geometry];
|
|
4288
|
+
} else {
|
|
4289
|
+
type = "Polygon";
|
|
4290
|
+
coordinates = rawFeature.geometry;
|
|
4291
|
+
}
|
|
4292
|
+
break;
|
|
4293
|
+
default:
|
|
4294
|
+
throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
|
|
4295
|
+
}
|
|
4296
|
+
switch (props.coordinates) {
|
|
4297
|
+
case "EPSG:4326":
|
|
4298
|
+
case "wgs84":
|
|
4299
|
+
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
4300
|
+
break;
|
|
4301
|
+
default:
|
|
4302
|
+
convertToLocalCoordinates(coordinates, props.extent);
|
|
4303
|
+
break;
|
|
4304
|
+
}
|
|
4305
|
+
const feature = {
|
|
4306
|
+
type: "Feature",
|
|
4307
|
+
geometry: {
|
|
4308
|
+
type,
|
|
4309
|
+
coordinates
|
|
4310
|
+
},
|
|
4311
|
+
properties: rawFeature.tags || {},
|
|
4312
|
+
id: rawFeature.id
|
|
4313
|
+
};
|
|
4314
|
+
features2.push(feature);
|
|
4315
|
+
}
|
|
4316
|
+
if (features2.length === 0) {
|
|
4317
|
+
return null;
|
|
4318
|
+
}
|
|
4319
|
+
const table = {
|
|
4320
|
+
shape: "geojson-table",
|
|
4321
|
+
type: "FeatureCollection",
|
|
4322
|
+
features: features2
|
|
4323
|
+
};
|
|
4324
|
+
return table;
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4327
|
+
// src/lib/vector-tiler/features/proto-feature.ts
|
|
4328
|
+
function createProtoFeature(id, type, geometry, tags) {
|
|
4329
|
+
const feature = {
|
|
4330
|
+
// eslint-disable-next-line
|
|
4331
|
+
id: id == null ? null : id,
|
|
4332
|
+
type,
|
|
4333
|
+
simplifiedType: void 0,
|
|
4334
|
+
// TODO
|
|
4335
|
+
geometry,
|
|
4336
|
+
tags,
|
|
4337
|
+
minX: Infinity,
|
|
4338
|
+
minY: Infinity,
|
|
4339
|
+
maxX: -Infinity,
|
|
4340
|
+
maxY: -Infinity
|
|
4341
|
+
};
|
|
4342
|
+
switch (type) {
|
|
4343
|
+
case "Point":
|
|
4344
|
+
case "MultiPoint":
|
|
4345
|
+
case "LineString":
|
|
4346
|
+
calcLineBBox(feature, geometry);
|
|
4347
|
+
break;
|
|
4348
|
+
case "MultiLineString":
|
|
4349
|
+
for (const line of geometry) {
|
|
4350
|
+
calcLineBBox(feature, line);
|
|
4351
|
+
}
|
|
4352
|
+
break;
|
|
4353
|
+
case "Polygon":
|
|
4354
|
+
calcLineBBox(feature, geometry[0]);
|
|
4355
|
+
break;
|
|
4356
|
+
case "MultiPolygon":
|
|
4357
|
+
for (const polygon of geometry) {
|
|
4358
|
+
calcLineBBox(feature, polygon[0]);
|
|
4359
|
+
}
|
|
4360
|
+
break;
|
|
4361
|
+
default:
|
|
4362
|
+
throw new Error(String(type));
|
|
4363
|
+
}
|
|
4364
|
+
return feature;
|
|
3688
4365
|
}
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
template = template[i];
|
|
3696
|
-
}
|
|
3697
|
-
let url = template;
|
|
3698
|
-
url = url.replace(xRegex, String(x));
|
|
3699
|
-
url = url.replace(yRegex, String(y));
|
|
3700
|
-
url = url.replace(zRegex, String(z));
|
|
3701
|
-
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
3702
|
-
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
4366
|
+
function calcLineBBox(feature, geometry) {
|
|
4367
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
4368
|
+
feature.minX = Math.min(feature.minX, geometry[i]);
|
|
4369
|
+
feature.minY = Math.min(feature.minY, geometry[i + 1]);
|
|
4370
|
+
feature.maxX = Math.max(feature.maxX, geometry[i]);
|
|
4371
|
+
feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
|
|
3703
4372
|
}
|
|
3704
|
-
return url;
|
|
3705
|
-
}
|
|
3706
|
-
function stringHash(s) {
|
|
3707
|
-
return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
|
|
3708
4373
|
}
|
|
3709
4374
|
|
|
3710
|
-
// src/lib/
|
|
3711
|
-
function
|
|
4375
|
+
// src/lib/vector-tiler/features/simplify-path.ts
|
|
4376
|
+
function simplifyPath(coords, first, last, sqTolerance) {
|
|
3712
4377
|
let maxSqDist = sqTolerance;
|
|
3713
4378
|
const mid = last - first >> 1;
|
|
3714
4379
|
let minPosToMid = last - first;
|
|
@@ -3732,10 +4397,10 @@ var __exports__ = (() => {
|
|
|
3732
4397
|
}
|
|
3733
4398
|
if (maxSqDist > sqTolerance) {
|
|
3734
4399
|
if (index - first > 3)
|
|
3735
|
-
|
|
4400
|
+
simplifyPath(coords, first, index, sqTolerance);
|
|
3736
4401
|
coords[index + 2] = maxSqDist;
|
|
3737
4402
|
if (last - index > 3)
|
|
3738
|
-
|
|
4403
|
+
simplifyPath(coords, index, last, sqTolerance);
|
|
3739
4404
|
}
|
|
3740
4405
|
}
|
|
3741
4406
|
function getSqSegDist(px, py, x, y, bx, by) {
|
|
@@ -3756,58 +4421,25 @@ var __exports__ = (() => {
|
|
|
3756
4421
|
return dx * dx + dy * dy;
|
|
3757
4422
|
}
|
|
3758
4423
|
|
|
3759
|
-
// src/lib/
|
|
3760
|
-
function
|
|
3761
|
-
const
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
} else if (type === "Polygon") {
|
|
3775
|
-
calcLineBBox(feature, geom[0]);
|
|
3776
|
-
} else if (type === "MultiLineString") {
|
|
3777
|
-
for (const line of geom) {
|
|
3778
|
-
calcLineBBox(feature, line);
|
|
3779
|
-
}
|
|
3780
|
-
} else if (type === "MultiPolygon") {
|
|
3781
|
-
for (const polygon of geom) {
|
|
3782
|
-
calcLineBBox(feature, polygon[0]);
|
|
3783
|
-
}
|
|
3784
|
-
}
|
|
3785
|
-
return feature;
|
|
3786
|
-
}
|
|
3787
|
-
function calcLineBBox(feature, geom) {
|
|
3788
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
3789
|
-
feature.minX = Math.min(feature.minX, geom[i]);
|
|
3790
|
-
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
3791
|
-
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
3792
|
-
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
|
|
3796
|
-
// src/lib/geojsonvt/convert.ts
|
|
3797
|
-
function convert(data, options) {
|
|
3798
|
-
const features = [];
|
|
3799
|
-
if (data.type === "FeatureCollection") {
|
|
3800
|
-
for (let i = 0; i < data.features.length; i++) {
|
|
3801
|
-
convertFeature(features, data.features[i], options, i);
|
|
3802
|
-
}
|
|
3803
|
-
} else if (data.type === "Feature") {
|
|
3804
|
-
convertFeature(features, data, options);
|
|
3805
|
-
} else {
|
|
3806
|
-
convertFeature(features, { geometry: data }, options);
|
|
4424
|
+
// src/lib/vector-tiler/features/convert-feature.ts
|
|
4425
|
+
function convertFeaturesToProtoFeature(data, options) {
|
|
4426
|
+
const protoFeatures = [];
|
|
4427
|
+
switch (data.type) {
|
|
4428
|
+
case "FeatureCollection":
|
|
4429
|
+
let i = 0;
|
|
4430
|
+
for (const feature of data.features) {
|
|
4431
|
+
protoFeatures.push(convertFeature(feature, options, i++));
|
|
4432
|
+
}
|
|
4433
|
+
break;
|
|
4434
|
+
case "Feature":
|
|
4435
|
+
protoFeatures.push(convertFeature(data, options));
|
|
4436
|
+
break;
|
|
4437
|
+
default:
|
|
4438
|
+
protoFeatures.push(convertFeature({ geometry: data }, options));
|
|
3807
4439
|
}
|
|
3808
|
-
return
|
|
4440
|
+
return protoFeatures;
|
|
3809
4441
|
}
|
|
3810
|
-
function convertFeature(
|
|
4442
|
+
function convertFeature(geojson, options, index) {
|
|
3811
4443
|
if (!geojson.geometry) {
|
|
3812
4444
|
return;
|
|
3813
4445
|
}
|
|
@@ -3821,51 +4453,57 @@ var __exports__ = (() => {
|
|
|
3821
4453
|
} else if (options.generateId) {
|
|
3822
4454
|
id = index || 0;
|
|
3823
4455
|
}
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
convertLine(coords, geometry, tolerance, false);
|
|
3832
|
-
} else if (type === "MultiLineString") {
|
|
3833
|
-
if (options.lineMetrics) {
|
|
3834
|
-
for (const line of coords) {
|
|
3835
|
-
geometry = [];
|
|
3836
|
-
convertLine(line, geometry, tolerance, false);
|
|
3837
|
-
features.push(createFeature(id, "LineString", geometry, geojson.properties));
|
|
4456
|
+
switch (type) {
|
|
4457
|
+
case "Point":
|
|
4458
|
+
convertPoint(coords, geometry);
|
|
4459
|
+
break;
|
|
4460
|
+
case "MultiPoint":
|
|
4461
|
+
for (const p of coords) {
|
|
4462
|
+
convertPoint(p, geometry);
|
|
3838
4463
|
}
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
4464
|
+
break;
|
|
4465
|
+
case "LineString":
|
|
4466
|
+
convertLine(coords, geometry, tolerance, false);
|
|
4467
|
+
break;
|
|
4468
|
+
case "MultiLineString":
|
|
4469
|
+
if (options.lineMetrics) {
|
|
4470
|
+
for (const line of coords) {
|
|
4471
|
+
geometry = [];
|
|
4472
|
+
convertLine(line, geometry, tolerance, false);
|
|
4473
|
+
features.push(createProtoFeature(id, "LineString", geometry, geojson.properties));
|
|
4474
|
+
}
|
|
4475
|
+
return;
|
|
4476
|
+
convertLines(coords, geometry, tolerance, false);
|
|
4477
|
+
}
|
|
4478
|
+
break;
|
|
4479
|
+
case "Polygon":
|
|
4480
|
+
convertLines(coords, geometry, tolerance, true);
|
|
4481
|
+
break;
|
|
4482
|
+
case "MultiPolygon":
|
|
4483
|
+
for (const polygon of coords) {
|
|
4484
|
+
const newPolygon = [];
|
|
4485
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
4486
|
+
geometry.push(newPolygon);
|
|
4487
|
+
}
|
|
4488
|
+
break;
|
|
4489
|
+
case "GeometryCollection":
|
|
4490
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
4491
|
+
convertFeature(
|
|
4492
|
+
features,
|
|
4493
|
+
{
|
|
4494
|
+
id,
|
|
4495
|
+
geometry: singleGeometry,
|
|
4496
|
+
properties: geojson.properties
|
|
4497
|
+
},
|
|
4498
|
+
options,
|
|
4499
|
+
index
|
|
4500
|
+
);
|
|
4501
|
+
}
|
|
4502
|
+
break;
|
|
4503
|
+
default:
|
|
4504
|
+
throw new Error("Input data is not a valid GeoJSON object.");
|
|
3867
4505
|
}
|
|
3868
|
-
|
|
4506
|
+
return createProtoFeature(id, type, geometry, geojson.properties);
|
|
3869
4507
|
}
|
|
3870
4508
|
function convertPoint(coords, out) {
|
|
3871
4509
|
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
@@ -3889,7 +4527,7 @@ var __exports__ = (() => {
|
|
|
3889
4527
|
}
|
|
3890
4528
|
const last = out.length - 3;
|
|
3891
4529
|
out[2] = 1;
|
|
3892
|
-
|
|
4530
|
+
simplifyPath(out, 0, last, tolerance);
|
|
3893
4531
|
out[last + 2] = 1;
|
|
3894
4532
|
out.size = Math.abs(size);
|
|
3895
4533
|
out.start = 0;
|
|
@@ -3911,17 +4549,17 @@ var __exports__ = (() => {
|
|
|
3911
4549
|
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
3912
4550
|
}
|
|
3913
4551
|
|
|
3914
|
-
// src/lib/
|
|
3915
|
-
function
|
|
4552
|
+
// src/lib/vector-tiler/features/clip-features.ts
|
|
4553
|
+
function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
3916
4554
|
k1 /= scale;
|
|
3917
4555
|
k2 /= scale;
|
|
3918
4556
|
if (minAll >= k1 && maxAll < k2) {
|
|
3919
|
-
return
|
|
4557
|
+
return features2;
|
|
3920
4558
|
} else if (maxAll < k1 || minAll >= k2) {
|
|
3921
4559
|
return null;
|
|
3922
4560
|
}
|
|
3923
4561
|
const clipped = [];
|
|
3924
|
-
for (const feature of
|
|
4562
|
+
for (const feature of features2) {
|
|
3925
4563
|
const geometry = feature.geometry;
|
|
3926
4564
|
let type = feature.type;
|
|
3927
4565
|
const min = axis === 0 ? feature.minX : feature.minY;
|
|
@@ -3953,7 +4591,7 @@ var __exports__ = (() => {
|
|
|
3953
4591
|
if (newGeometry.length) {
|
|
3954
4592
|
if (options.lineMetrics && type === "LineString") {
|
|
3955
4593
|
for (const line of newGeometry) {
|
|
3956
|
-
clipped.push(
|
|
4594
|
+
clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
|
|
3957
4595
|
}
|
|
3958
4596
|
continue;
|
|
3959
4597
|
}
|
|
@@ -3968,7 +4606,7 @@ var __exports__ = (() => {
|
|
|
3968
4606
|
if (type === "Point" || type === "MultiPoint") {
|
|
3969
4607
|
type = newGeometry.length === 3 ? "Point" : "MultiPoint";
|
|
3970
4608
|
}
|
|
3971
|
-
clipped.push(
|
|
4609
|
+
clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
3972
4610
|
}
|
|
3973
4611
|
}
|
|
3974
4612
|
return clipped.length ? clipped : null;
|
|
@@ -4076,14 +4714,14 @@ var __exports__ = (() => {
|
|
|
4076
4714
|
return t;
|
|
4077
4715
|
}
|
|
4078
4716
|
|
|
4079
|
-
// src/lib/
|
|
4080
|
-
function
|
|
4717
|
+
// src/lib/vector-tiler/features/wrap-features.ts
|
|
4718
|
+
function wrapFeatures(features2, options) {
|
|
4081
4719
|
const buffer = options.buffer / options.extent;
|
|
4082
|
-
let merged =
|
|
4083
|
-
const left =
|
|
4084
|
-
const right =
|
|
4720
|
+
let merged = features2;
|
|
4721
|
+
const left = clipFeatures(features2, 1, -1 - buffer, buffer, 0, -1, 2, options);
|
|
4722
|
+
const right = clipFeatures(features2, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
|
|
4085
4723
|
if (left || right) {
|
|
4086
|
-
merged =
|
|
4724
|
+
merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
|
|
4087
4725
|
if (left) {
|
|
4088
4726
|
merged = shiftFeatureCoords(left, 1).concat(merged);
|
|
4089
4727
|
}
|
|
@@ -4093,30 +4731,39 @@ var __exports__ = (() => {
|
|
|
4093
4731
|
}
|
|
4094
4732
|
return merged;
|
|
4095
4733
|
}
|
|
4096
|
-
function shiftFeatureCoords(
|
|
4734
|
+
function shiftFeatureCoords(features2, offset) {
|
|
4097
4735
|
const newFeatures = [];
|
|
4098
|
-
for (let i = 0; i <
|
|
4099
|
-
const feature =
|
|
4736
|
+
for (let i = 0; i < features2.length; i++) {
|
|
4737
|
+
const feature = features2[i];
|
|
4100
4738
|
const type = feature.type;
|
|
4101
4739
|
let newGeometry;
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
for (const line of polygon) {
|
|
4114
|
-
newPolygon.push(shiftCoords(line, offset));
|
|
4740
|
+
switch (type) {
|
|
4741
|
+
case "Point":
|
|
4742
|
+
case "MultiPoint":
|
|
4743
|
+
case "LineString":
|
|
4744
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
4745
|
+
break;
|
|
4746
|
+
case "MultiLineString":
|
|
4747
|
+
case "Polygon":
|
|
4748
|
+
newGeometry = [];
|
|
4749
|
+
for (const line of feature.geometry) {
|
|
4750
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
4115
4751
|
}
|
|
4116
|
-
|
|
4117
|
-
|
|
4752
|
+
break;
|
|
4753
|
+
case "MultiPolygon":
|
|
4754
|
+
newGeometry = [];
|
|
4755
|
+
for (const polygon of feature.geometry) {
|
|
4756
|
+
const newPolygon = [];
|
|
4757
|
+
for (const line of polygon) {
|
|
4758
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
4759
|
+
}
|
|
4760
|
+
newGeometry.push(newPolygon);
|
|
4761
|
+
}
|
|
4762
|
+
break;
|
|
4763
|
+
default:
|
|
4764
|
+
throw new Error(String(type));
|
|
4118
4765
|
}
|
|
4119
|
-
newFeatures.push(
|
|
4766
|
+
newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
4120
4767
|
}
|
|
4121
4768
|
return newFeatures;
|
|
4122
4769
|
}
|
|
@@ -4133,200 +4780,85 @@ var __exports__ = (() => {
|
|
|
4133
4780
|
return newPoints;
|
|
4134
4781
|
}
|
|
4135
4782
|
|
|
4136
|
-
// src/
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
const ring = [];
|
|
4155
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
4156
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
4157
|
-
}
|
|
4158
|
-
feature.geometry.push(ring);
|
|
4159
|
-
}
|
|
4160
|
-
}
|
|
4161
|
-
}
|
|
4162
|
-
tile.transformed = true;
|
|
4163
|
-
return tile;
|
|
4164
|
-
}
|
|
4165
|
-
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
4166
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
4167
|
-
}
|
|
4168
|
-
|
|
4169
|
-
// src/lib/geojsonvt/tile.ts
|
|
4170
|
-
function createTile(features, z, tx, ty, options) {
|
|
4171
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
4172
|
-
const tile = {
|
|
4173
|
-
features: [],
|
|
4174
|
-
numPoints: 0,
|
|
4175
|
-
numSimplified: 0,
|
|
4176
|
-
numFeatures: features.length,
|
|
4177
|
-
source: null,
|
|
4178
|
-
x: tx,
|
|
4179
|
-
y: ty,
|
|
4180
|
-
z,
|
|
4181
|
-
transformed: false,
|
|
4182
|
-
minX: 2,
|
|
4183
|
-
minY: 1,
|
|
4184
|
-
maxX: -1,
|
|
4185
|
-
maxY: 0
|
|
4186
|
-
};
|
|
4187
|
-
for (const feature of features) {
|
|
4188
|
-
addFeature(tile, feature, tolerance, options);
|
|
4189
|
-
}
|
|
4190
|
-
return tile;
|
|
4191
|
-
}
|
|
4192
|
-
function addFeature(tile, feature, tolerance, options) {
|
|
4193
|
-
const geom = feature.geometry;
|
|
4194
|
-
const type = feature.type;
|
|
4195
|
-
const simplified = [];
|
|
4196
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
4197
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
4198
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
4199
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
4200
|
-
if (type === "Point" || type === "MultiPoint") {
|
|
4201
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
4202
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
4203
|
-
tile.numPoints++;
|
|
4204
|
-
tile.numSimplified++;
|
|
4205
|
-
}
|
|
4206
|
-
} else if (type === "LineString") {
|
|
4207
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
4208
|
-
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
4209
|
-
for (let i = 0; i < geom.length; i++) {
|
|
4210
|
-
addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
|
|
4211
|
-
}
|
|
4212
|
-
} else if (type === "MultiPolygon") {
|
|
4213
|
-
for (let k = 0; k < geom.length; k++) {
|
|
4214
|
-
const polygon = geom[k];
|
|
4215
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
4216
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
4217
|
-
}
|
|
4218
|
-
}
|
|
4219
|
-
}
|
|
4220
|
-
if (simplified.length) {
|
|
4221
|
-
let tags = feature.tags || null;
|
|
4222
|
-
if (type === "LineString" && options.lineMetrics) {
|
|
4223
|
-
tags = {};
|
|
4224
|
-
for (const key in feature.tags)
|
|
4225
|
-
tags[key] = feature.tags[key];
|
|
4226
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
4227
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
4228
|
-
}
|
|
4229
|
-
const tileFeature = {
|
|
4230
|
-
geometry: simplified,
|
|
4231
|
-
type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
|
|
4232
|
-
tags
|
|
4233
|
-
};
|
|
4234
|
-
if (feature.id !== null) {
|
|
4235
|
-
tileFeature.id = feature.id;
|
|
4236
|
-
}
|
|
4237
|
-
tile.features.push(tileFeature);
|
|
4238
|
-
}
|
|
4239
|
-
}
|
|
4240
|
-
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
4241
|
-
const sqTolerance = tolerance * tolerance;
|
|
4242
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
4243
|
-
tile.numPoints += geom.length / 3;
|
|
4244
|
-
return;
|
|
4245
|
-
}
|
|
4246
|
-
const ring = [];
|
|
4247
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
4248
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
4249
|
-
tile.numSimplified++;
|
|
4250
|
-
ring.push(geom[i], geom[i + 1]);
|
|
4251
|
-
}
|
|
4252
|
-
tile.numPoints++;
|
|
4253
|
-
}
|
|
4254
|
-
if (isPolygon)
|
|
4255
|
-
rewind(ring, isOuter);
|
|
4256
|
-
result.push(ring);
|
|
4257
|
-
}
|
|
4258
|
-
function rewind(ring, clockwise) {
|
|
4259
|
-
let area2 = 0;
|
|
4260
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
4261
|
-
area2 += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
4262
|
-
}
|
|
4263
|
-
if (area2 > 0 === clockwise) {
|
|
4264
|
-
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
4265
|
-
const x = ring[i];
|
|
4266
|
-
const y = ring[i + 1];
|
|
4267
|
-
ring[i] = ring[len - 2 - i];
|
|
4268
|
-
ring[i + 1] = ring[len - 1 - i];
|
|
4269
|
-
ring[len - 2 - i] = x;
|
|
4270
|
-
ring[len - 1 - i] = y;
|
|
4783
|
+
// src/table-tile-source.ts
|
|
4784
|
+
var TableTileSource = {
|
|
4785
|
+
name: "TableTiler",
|
|
4786
|
+
id: "table-tiler",
|
|
4787
|
+
version: "0.0.0",
|
|
4788
|
+
extensions: ["mvt"],
|
|
4789
|
+
mimeTypes: ["application/octet-stream"],
|
|
4790
|
+
options: {
|
|
4791
|
+
table: {
|
|
4792
|
+
coordinates: "local",
|
|
4793
|
+
promoteId: void 0,
|
|
4794
|
+
maxZoom: 14,
|
|
4795
|
+
indexMaxZoom: 5,
|
|
4796
|
+
maxPointsPerTile: 1e4,
|
|
4797
|
+
tolerance: 3,
|
|
4798
|
+
extent: 4096,
|
|
4799
|
+
buffer: 64,
|
|
4800
|
+
generateId: void 0
|
|
4271
4801
|
}
|
|
4802
|
+
},
|
|
4803
|
+
type: "table",
|
|
4804
|
+
testURL: (url) => url.endsWith(".geojson"),
|
|
4805
|
+
createDataSource(url, options) {
|
|
4806
|
+
const needsLoading = typeof url === "string" || url instanceof Blob;
|
|
4807
|
+
const loader = options?.table?.loaders?.[0];
|
|
4808
|
+
const tablePromise = needsLoading ? loadTable(url, loader) : url;
|
|
4809
|
+
return new DynamicVectorTileSource(tablePromise, options);
|
|
4272
4810
|
}
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4811
|
+
// @ts-expect-error
|
|
4812
|
+
};
|
|
4813
|
+
async function loadTable(url, loader) {
|
|
4814
|
+
if (typeof url === "string") {
|
|
4815
|
+
const response = await fetch(url);
|
|
4816
|
+
const data2 = await response.arrayBuffer();
|
|
4817
|
+
return await loader.parse(data2);
|
|
4818
|
+
}
|
|
4819
|
+
const data = await url.arrayBuffer();
|
|
4820
|
+
return await loader.parse(data);
|
|
4821
|
+
}
|
|
4822
|
+
var _DynamicVectorTileSource = class {
|
|
4823
|
+
/** Stats for this DynamicVectorTileSource */
|
|
4824
|
+
stats = new Stats({
|
|
4825
|
+
id: "table-tile-source",
|
|
4826
|
+
stats: [new Stat("tiles", "count"), new Stat("features", "count")]
|
|
4827
|
+
});
|
|
4828
|
+
/** MIME type of the tiles emitted by this tile source */
|
|
4277
4829
|
mimeType = "application/vnd.mapbox-vector-tile";
|
|
4278
|
-
|
|
4279
|
-
|
|
4830
|
+
localCoordinates = true;
|
|
4831
|
+
/** The props that this tile source was created with */
|
|
4832
|
+
// @ts-expect-error
|
|
4833
|
+
props;
|
|
4834
|
+
/* Schema of the data */
|
|
4835
|
+
schema = null;
|
|
4836
|
+
/** Map of generated tiles, indexed by stringified tile coordinates */
|
|
4280
4837
|
tiles = {};
|
|
4838
|
+
/** Array of tile coordinates */
|
|
4281
4839
|
tileCoords = [];
|
|
4282
|
-
|
|
4283
|
-
total = 0;
|
|
4284
|
-
/** Sync methods can be called: the input data promise has been resolved and initial top-level tiling is done */
|
|
4840
|
+
/** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
|
|
4285
4841
|
ready;
|
|
4286
|
-
|
|
4287
|
-
|
|
4842
|
+
/** Metadata for the tile source (generated TileJSON/tilestats */
|
|
4843
|
+
metadata;
|
|
4844
|
+
constructor(table, props) {
|
|
4845
|
+
this.props = { ...TableTileSource.options.table, ...props?.table };
|
|
4288
4846
|
this.getTileData = this.getTileData.bind(this);
|
|
4289
|
-
this.ready = this.initializeTilesAsync(
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
const options = this.options;
|
|
4297
|
-
const debug = options.debug;
|
|
4298
|
-
if (debug)
|
|
4299
|
-
console.time("preprocess data");
|
|
4300
|
-
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
4301
|
-
throw new Error("maxZoom should be in the 0-24 range");
|
|
4302
|
-
}
|
|
4303
|
-
if (options.promoteId && this.options.generateId) {
|
|
4304
|
-
throw new Error("promoteId and generateId cannot be used together.");
|
|
4305
|
-
}
|
|
4306
|
-
let features = convert(data, options);
|
|
4307
|
-
if (debug) {
|
|
4308
|
-
console.timeEnd("preprocess data");
|
|
4309
|
-
console.log(
|
|
4310
|
-
"index: maxZoom: %d, maxPoints: %d",
|
|
4311
|
-
options.indexMaxZoom,
|
|
4312
|
-
options.indexMaxPoints
|
|
4313
|
-
);
|
|
4314
|
-
console.time("generate tiles");
|
|
4315
|
-
}
|
|
4316
|
-
features = wrap(features, this.options);
|
|
4317
|
-
if (features.length) {
|
|
4318
|
-
this.splitTile(features, 0, 0, 0);
|
|
4319
|
-
}
|
|
4320
|
-
if (debug) {
|
|
4321
|
-
if (features.length) {
|
|
4322
|
-
console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
4323
|
-
}
|
|
4324
|
-
console.timeEnd("generate tiles");
|
|
4325
|
-
console.log("tiles generated:", this.total, JSON.stringify(this.stats));
|
|
4326
|
-
}
|
|
4847
|
+
this.ready = this.initializeTilesAsync(table);
|
|
4848
|
+
this.metadata = this.getMetadata();
|
|
4849
|
+
}
|
|
4850
|
+
async initializeTilesAsync(tablePromise) {
|
|
4851
|
+
const table = await tablePromise;
|
|
4852
|
+
this.schema = deduceTableSchema(table);
|
|
4853
|
+
this.createRootTiles(table);
|
|
4327
4854
|
}
|
|
4328
4855
|
async getMetadata() {
|
|
4329
|
-
|
|
4856
|
+
await this.ready;
|
|
4857
|
+
return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
|
|
4858
|
+
}
|
|
4859
|
+
async getSchema() {
|
|
4860
|
+
await this.ready;
|
|
4861
|
+
return this.schema;
|
|
4330
4862
|
}
|
|
4331
4863
|
/**
|
|
4332
4864
|
* Get a tile at the specified index
|
|
@@ -4336,6 +4868,7 @@ var __exports__ = (() => {
|
|
|
4336
4868
|
async getVectorTile(tileIndex) {
|
|
4337
4869
|
await this.ready;
|
|
4338
4870
|
const table = this.getTileSync(tileIndex);
|
|
4871
|
+
log.info(2, "getVectorTile", tileIndex, table)();
|
|
4339
4872
|
return table;
|
|
4340
4873
|
}
|
|
4341
4874
|
async getTile(tileIndex) {
|
|
@@ -4344,7 +4877,8 @@ var __exports__ = (() => {
|
|
|
4344
4877
|
}
|
|
4345
4878
|
async getTileData(tileParams) {
|
|
4346
4879
|
const { x, y, z } = tileParams.index;
|
|
4347
|
-
|
|
4880
|
+
const tile = await this.getVectorTile({ x, y, z });
|
|
4881
|
+
return tile?.features || [];
|
|
4348
4882
|
}
|
|
4349
4883
|
// Implementation
|
|
4350
4884
|
/**
|
|
@@ -4352,21 +4886,56 @@ var __exports__ = (() => {
|
|
|
4352
4886
|
* @note Application must await `source.ready` before calling sync methods.
|
|
4353
4887
|
*/
|
|
4354
4888
|
getTileSync(tileIndex) {
|
|
4355
|
-
const
|
|
4356
|
-
if (!
|
|
4889
|
+
const protoTile = this.getProtoTile(tileIndex);
|
|
4890
|
+
if (!protoTile) {
|
|
4357
4891
|
return null;
|
|
4358
4892
|
}
|
|
4359
|
-
return
|
|
4893
|
+
return convertTileToGeoJSON(protoTile, {
|
|
4894
|
+
coordinates: this.props.coordinates,
|
|
4895
|
+
tileIndex,
|
|
4896
|
+
extent: this.props.extent
|
|
4897
|
+
});
|
|
4898
|
+
}
|
|
4899
|
+
/**
|
|
4900
|
+
* Create the initial tiles
|
|
4901
|
+
* @note the tiles stores all the features together with additional data
|
|
4902
|
+
*/
|
|
4903
|
+
createRootTiles(table) {
|
|
4904
|
+
if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
|
|
4905
|
+
throw new Error("maxZoom should be in the 0-24 range");
|
|
4906
|
+
}
|
|
4907
|
+
if (this.props.promoteId && this.props.generateId) {
|
|
4908
|
+
throw new Error("promoteId and generateId cannot be used together.");
|
|
4909
|
+
}
|
|
4910
|
+
log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
|
|
4911
|
+
log.time(1, "preprocess table")();
|
|
4912
|
+
let features2 = convertFeaturesToProtoFeature(table, this.props);
|
|
4913
|
+
log.timeEnd(1, "preprocess table")();
|
|
4914
|
+
log.time(1, "generate tiles")();
|
|
4915
|
+
features2 = wrapFeatures(features2, this.props);
|
|
4916
|
+
if (features2.length === 0) {
|
|
4917
|
+
log.log(1, "DynamicVectorTileSource: no features generated")();
|
|
4918
|
+
return;
|
|
4919
|
+
}
|
|
4920
|
+
this.splitTile(features2, 0, 0, 0);
|
|
4921
|
+
const rootTile = this.tiles[0];
|
|
4922
|
+
log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
|
|
4923
|
+
log.timeEnd(1, "generate tiles")();
|
|
4924
|
+
log.log(
|
|
4925
|
+
1,
|
|
4926
|
+
`DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`,
|
|
4927
|
+
this.stats
|
|
4928
|
+
)();
|
|
4360
4929
|
}
|
|
4361
4930
|
/**
|
|
4362
4931
|
* Return geojsonvt-style "half formed" vector tile
|
|
4363
4932
|
* @note Application must await `source.ready` before calling sync methods.
|
|
4364
4933
|
*/
|
|
4365
4934
|
// eslint-disable-next-line complexity, max-statements
|
|
4366
|
-
|
|
4935
|
+
getProtoTile(tileIndex) {
|
|
4367
4936
|
const { z, y } = tileIndex;
|
|
4368
4937
|
let { x } = tileIndex;
|
|
4369
|
-
const { extent
|
|
4938
|
+
const { extent } = this.props;
|
|
4370
4939
|
if (z < 0 || z > 24) {
|
|
4371
4940
|
return null;
|
|
4372
4941
|
}
|
|
@@ -4376,8 +4945,7 @@ var __exports__ = (() => {
|
|
|
4376
4945
|
if (this.tiles[id]) {
|
|
4377
4946
|
return transformTile(this.tiles[id], extent);
|
|
4378
4947
|
}
|
|
4379
|
-
|
|
4380
|
-
console.log("drilling down to z%d-%d-%d", z, x, y);
|
|
4948
|
+
log.log(log, "drilling down to z%d-%d-%d", z, x, y)();
|
|
4381
4949
|
let z0 = z;
|
|
4382
4950
|
let x0 = x;
|
|
4383
4951
|
let y0 = y;
|
|
@@ -4388,17 +4956,13 @@ var __exports__ = (() => {
|
|
|
4388
4956
|
y0 = y0 >> 1;
|
|
4389
4957
|
parent = this.tiles[toID(z0, x0, y0)];
|
|
4390
4958
|
}
|
|
4391
|
-
if (!parent || !parent.
|
|
4959
|
+
if (!parent || !parent.sourceFeatures) {
|
|
4392
4960
|
return null;
|
|
4393
4961
|
}
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
this.splitTile(parent.source, z0, x0, y0, z, x, y);
|
|
4399
|
-
if (debug > 1) {
|
|
4400
|
-
console.timeEnd("drilling down");
|
|
4401
|
-
}
|
|
4962
|
+
log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
|
|
4963
|
+
log.time(1, "drilling down")();
|
|
4964
|
+
this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
|
|
4965
|
+
log.timeEnd(1, "drilling down")();
|
|
4402
4966
|
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
4403
4967
|
}
|
|
4404
4968
|
/**
|
|
@@ -4407,62 +4971,62 @@ var __exports__ = (() => {
|
|
|
4407
4971
|
* @param cz, cx, and cy are the coordinates of the target tile
|
|
4408
4972
|
*
|
|
4409
4973
|
* If no target tile is specified, splitting stops when we reach the maximum
|
|
4410
|
-
* zoom or the number of points is low as specified in the
|
|
4974
|
+
* zoom or the number of points is low as specified in the props.
|
|
4411
4975
|
*/
|
|
4412
4976
|
// eslint-disable-next-line max-params, max-statements, complexity
|
|
4413
|
-
splitTile(
|
|
4414
|
-
const stack = [
|
|
4415
|
-
const options = this.options;
|
|
4416
|
-
const debug = options.debug;
|
|
4977
|
+
splitTile(features2, z, x, y, cz, cx, cy) {
|
|
4978
|
+
const stack = [features2, z, x, y];
|
|
4417
4979
|
while (stack.length) {
|
|
4418
4980
|
y = stack.pop();
|
|
4419
4981
|
x = stack.pop();
|
|
4420
4982
|
z = stack.pop();
|
|
4421
|
-
|
|
4983
|
+
features2 = stack.pop();
|
|
4422
4984
|
const z2 = 1 << z;
|
|
4423
4985
|
const id = toID(z, x, y);
|
|
4424
4986
|
let tile = this.tiles[id];
|
|
4425
4987
|
if (!tile) {
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
}
|
|
4429
|
-
tile = this.tiles[id] = createTile(features, z, x, y, options);
|
|
4988
|
+
log.time(2, "tile creation")();
|
|
4989
|
+
tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
|
|
4430
4990
|
this.tileCoords.push({ z, x, y });
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4991
|
+
const key = `z${z}`;
|
|
4992
|
+
let stat = this.stats.get(key, "count");
|
|
4993
|
+
stat.incrementCount();
|
|
4994
|
+
stat = this.stats.get("total");
|
|
4995
|
+
stat.incrementCount();
|
|
4996
|
+
stat = _DynamicVectorTileSource.stats.get(key, "count");
|
|
4997
|
+
stat.incrementCount();
|
|
4998
|
+
stat = _DynamicVectorTileSource.stats.get("total");
|
|
4999
|
+
stat.incrementCount();
|
|
5000
|
+
log.log(
|
|
5001
|
+
2,
|
|
5002
|
+
"tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",
|
|
5003
|
+
z,
|
|
5004
|
+
x,
|
|
5005
|
+
y,
|
|
5006
|
+
tile.numFeatures,
|
|
5007
|
+
tile.numPoints,
|
|
5008
|
+
tile.numSimplified
|
|
5009
|
+
)();
|
|
5010
|
+
log.timeEnd(2, "tile creation")();
|
|
4448
5011
|
}
|
|
4449
|
-
tile.
|
|
5012
|
+
tile.sourceFeatures = features2;
|
|
4450
5013
|
if (cz === void 0) {
|
|
4451
|
-
if (z ===
|
|
5014
|
+
if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
|
|
4452
5015
|
continue;
|
|
4453
|
-
|
|
5016
|
+
}
|
|
5017
|
+
} else if (z === this.props.maxZoom || z === cz) {
|
|
4454
5018
|
continue;
|
|
4455
5019
|
} else if (cz !== void 0) {
|
|
4456
5020
|
const zoomSteps = cz - z;
|
|
4457
|
-
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
|
|
5021
|
+
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
|
|
4458
5022
|
continue;
|
|
5023
|
+
}
|
|
4459
5024
|
}
|
|
4460
|
-
tile.
|
|
4461
|
-
if (
|
|
5025
|
+
tile.sourceFeatures = null;
|
|
5026
|
+
if (features2.length === 0)
|
|
4462
5027
|
continue;
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
const k1 = 0.5 * options.buffer / options.extent;
|
|
5028
|
+
log.time(2, "clipping tile")();
|
|
5029
|
+
const k1 = 0.5 * this.props.buffer / this.props.extent;
|
|
4466
5030
|
const k2 = 0.5 - k1;
|
|
4467
5031
|
const k3 = 0.5 + k1;
|
|
4468
5032
|
const k4 = 1 + k1;
|
|
@@ -4470,21 +5034,20 @@ var __exports__ = (() => {
|
|
|
4470
5034
|
let bl = null;
|
|
4471
5035
|
let tr = null;
|
|
4472
5036
|
let br = null;
|
|
4473
|
-
let left =
|
|
4474
|
-
let right =
|
|
4475
|
-
|
|
5037
|
+
let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
|
|
5038
|
+
let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
|
|
5039
|
+
features2 = null;
|
|
4476
5040
|
if (left) {
|
|
4477
|
-
tl =
|
|
4478
|
-
bl =
|
|
5041
|
+
tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
5042
|
+
bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
4479
5043
|
left = null;
|
|
4480
5044
|
}
|
|
4481
5045
|
if (right) {
|
|
4482
|
-
tr =
|
|
4483
|
-
br =
|
|
5046
|
+
tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
5047
|
+
br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
4484
5048
|
right = null;
|
|
4485
5049
|
}
|
|
4486
|
-
|
|
4487
|
-
console.timeEnd("clipping");
|
|
5050
|
+
log.timeEnd(2, "clipping tile")();
|
|
4488
5051
|
stack.push(tl || [], z + 1, x * 2, y * 2);
|
|
4489
5052
|
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
|
|
4490
5053
|
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
|
|
@@ -4492,96 +5055,15 @@ var __exports__ = (() => {
|
|
|
4492
5055
|
}
|
|
4493
5056
|
}
|
|
4494
5057
|
};
|
|
4495
|
-
var
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
indexMaxPoints: 1e5,
|
|
4502
|
-
// max number of points per tile in the tile index
|
|
4503
|
-
tolerance: 3,
|
|
4504
|
-
// simplification tolerance (higher means simpler)
|
|
4505
|
-
extent: 4096,
|
|
4506
|
-
// tile extent
|
|
4507
|
-
buffer: 64,
|
|
4508
|
-
// tile buffer on each side
|
|
4509
|
-
lineMetrics: false,
|
|
4510
|
-
// whether to calculate line metrics
|
|
4511
|
-
// @ts-expect-error
|
|
4512
|
-
promoteId: void 0,
|
|
4513
|
-
// name of a feature property to be promoted to feature.id
|
|
4514
|
-
generateId: false,
|
|
4515
|
-
// whether to generate feature ids. Cannot be used with promoteId
|
|
4516
|
-
debug: 0
|
|
4517
|
-
// logging level (0, 1 or 2)
|
|
4518
|
-
});
|
|
5058
|
+
var DynamicVectorTileSource = _DynamicVectorTileSource;
|
|
5059
|
+
/** Global stats for all DynamicVectorTileSources */
|
|
5060
|
+
__publicField(DynamicVectorTileSource, "stats", new Stats({
|
|
5061
|
+
id: "table-tile-source-all",
|
|
5062
|
+
stats: [new Stat("count", "tiles"), new Stat("count", "features")]
|
|
5063
|
+
}));
|
|
4519
5064
|
function toID(z, x, y) {
|
|
4520
5065
|
return ((1 << z) * y + x) * 32 + z;
|
|
4521
5066
|
}
|
|
4522
|
-
function convertToGeoJSONTable(vtTile, extent) {
|
|
4523
|
-
const features = [];
|
|
4524
|
-
for (const rawFeature of vtTile.features) {
|
|
4525
|
-
if (!rawFeature || !rawFeature.geometry) {
|
|
4526
|
-
continue;
|
|
4527
|
-
}
|
|
4528
|
-
let type;
|
|
4529
|
-
let coordinates;
|
|
4530
|
-
switch (rawFeature.type) {
|
|
4531
|
-
case 1:
|
|
4532
|
-
if (rawFeature.geometry.length === 1) {
|
|
4533
|
-
type = "Point";
|
|
4534
|
-
coordinates = rawFeature.geometry[0];
|
|
4535
|
-
} else {
|
|
4536
|
-
type = "MultiPoint";
|
|
4537
|
-
coordinates = rawFeature.geometry;
|
|
4538
|
-
}
|
|
4539
|
-
break;
|
|
4540
|
-
case 2:
|
|
4541
|
-
if (rawFeature.geometry.length === 1) {
|
|
4542
|
-
type = "LineString";
|
|
4543
|
-
coordinates = rawFeature.geometry[0];
|
|
4544
|
-
} else {
|
|
4545
|
-
type = "MultiLineString";
|
|
4546
|
-
coordinates = rawFeature.geometry;
|
|
4547
|
-
}
|
|
4548
|
-
break;
|
|
4549
|
-
case 3:
|
|
4550
|
-
if (rawFeature.geometry.length > 1) {
|
|
4551
|
-
type = "MultiPolygon";
|
|
4552
|
-
coordinates = [rawFeature.geometry];
|
|
4553
|
-
} else {
|
|
4554
|
-
type = "Polygon";
|
|
4555
|
-
coordinates = rawFeature.geometry;
|
|
4556
|
-
}
|
|
4557
|
-
break;
|
|
4558
|
-
default:
|
|
4559
|
-
continue;
|
|
4560
|
-
}
|
|
4561
|
-
coordinates = toLngLat(coordinates, extent);
|
|
4562
|
-
const feature = {
|
|
4563
|
-
type: "Feature",
|
|
4564
|
-
geometry: {
|
|
4565
|
-
type,
|
|
4566
|
-
coordinates
|
|
4567
|
-
},
|
|
4568
|
-
properties: rawFeature.tags || {}
|
|
4569
|
-
};
|
|
4570
|
-
features.push(feature);
|
|
4571
|
-
}
|
|
4572
|
-
const table = {
|
|
4573
|
-
shape: "geojson-table",
|
|
4574
|
-
type: "FeatureCollection",
|
|
4575
|
-
features
|
|
4576
|
-
};
|
|
4577
|
-
return table;
|
|
4578
|
-
}
|
|
4579
|
-
function toLngLat(coords, extent) {
|
|
4580
|
-
if (Array.isArray(coords[0])) {
|
|
4581
|
-
return coords.map((c) => toLngLat(c, extent));
|
|
4582
|
-
}
|
|
4583
|
-
return [coords[0] / extent, coords[1] / extent];
|
|
4584
|
-
}
|
|
4585
5067
|
return __toCommonJS(bundle_exports);
|
|
4586
5068
|
})();
|
|
4587
5069
|
/*! Bundled license information:
|