@loaders.gl/mvt 4.3.0-alpha.2 → 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 +777 -688
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +746 -659
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.js +1 -1
- package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
- 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/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
- package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{wrap.js → 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.js +1 -1
- package/dist/mvt-source.d.ts +31 -14
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +26 -6
- package/dist/mvt-worker.js +4 -4
- package/dist/table-tile-source.d.ts +66 -36
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +167 -117
- package/dist/tilejson-loader.js +1 -1
- package/package.json +6 -6
- package/src/index.ts +13 -6
- package/src/lib/parse-tilejson.ts +1 -1
- package/src/lib/utils/geometry-utils.ts +1 -1
- package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
- package/src/lib/vector-tiler/{wrap.ts → 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 +42 -18
- package/src/table-tile-source.ts +130 -85
- package/src/tilejson-loader.ts +2 -2
- package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.js +0 -139
- package/dist/lib/vector-tiler/feature.d.ts +0 -3
- package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
- package/dist/lib/vector-tiler/feature.js +0 -44
- package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.d.ts +0 -38
- package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.js +0 -123
- package/dist/lib/vector-tiler/transform.d.ts +0 -7
- package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
- package/dist/lib/vector-tiler/transform.js +0 -41
- package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
- package/src/lib/vector-tiler/feature.ts +0 -47
- package/src/lib/vector-tiler/tile.ts +0 -187
- package/src/lib/vector-tiler/transform.ts +0 -57
package/dist/dist.dev.js
CHANGED
|
@@ -801,6 +801,241 @@ var __exports__ = (() => {
|
|
|
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
|
+
|
|
804
1039
|
// ../schema/src/lib/table/simple-table/data-type.ts
|
|
805
1040
|
function getDataTypeFromValue(value, defaultNumberType = "float32") {
|
|
806
1041
|
if (value instanceof Date) {
|
|
@@ -886,12 +1121,12 @@ var __exports__ = (() => {
|
|
|
886
1121
|
}
|
|
887
1122
|
return { fields, metadata: {} };
|
|
888
1123
|
}
|
|
889
|
-
function deduceSchemaFromGeoJSON(
|
|
890
|
-
if (!
|
|
1124
|
+
function deduceSchemaFromGeoJSON(features2) {
|
|
1125
|
+
if (!features2.length) {
|
|
891
1126
|
throw new Error("deduce from empty table");
|
|
892
1127
|
}
|
|
893
1128
|
const fields = [];
|
|
894
|
-
const row0 =
|
|
1129
|
+
const row0 = features2[0].properties || {};
|
|
895
1130
|
for (const [columnName, value] of Object.entries(row0)) {
|
|
896
1131
|
fields.push(deduceFieldFromValue(value, columnName));
|
|
897
1132
|
}
|
|
@@ -1489,11 +1724,11 @@ var __exports__ = (() => {
|
|
|
1489
1724
|
};
|
|
1490
1725
|
|
|
1491
1726
|
// ../gis/src/lib/binary-features/flat-geojson-to-binary.ts
|
|
1492
|
-
function flatGeojsonToBinary(
|
|
1493
|
-
const propArrayTypes = extractNumericPropTypes(
|
|
1727
|
+
function flatGeojsonToBinary(features2, geometryInfo, options) {
|
|
1728
|
+
const propArrayTypes = extractNumericPropTypes(features2);
|
|
1494
1729
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1495
1730
|
return fillArrays(
|
|
1496
|
-
|
|
1731
|
+
features2,
|
|
1497
1732
|
{
|
|
1498
1733
|
propArrayTypes,
|
|
1499
1734
|
...geometryInfo
|
|
@@ -1505,9 +1740,9 @@ var __exports__ = (() => {
|
|
|
1505
1740
|
}
|
|
1506
1741
|
);
|
|
1507
1742
|
}
|
|
1508
|
-
function extractNumericPropTypes(
|
|
1743
|
+
function extractNumericPropTypes(features2) {
|
|
1509
1744
|
const propArrayTypes = {};
|
|
1510
|
-
for (const feature of
|
|
1745
|
+
for (const feature of features2) {
|
|
1511
1746
|
if (feature.properties) {
|
|
1512
1747
|
for (const key in feature.properties) {
|
|
1513
1748
|
const val = feature.properties[key];
|
|
@@ -1517,7 +1752,7 @@ var __exports__ = (() => {
|
|
|
1517
1752
|
}
|
|
1518
1753
|
return propArrayTypes;
|
|
1519
1754
|
}
|
|
1520
|
-
function fillArrays(
|
|
1755
|
+
function fillArrays(features2, geometryInfo, options) {
|
|
1521
1756
|
const {
|
|
1522
1757
|
pointPositionsCount,
|
|
1523
1758
|
pointFeaturesCount,
|
|
@@ -1532,8 +1767,8 @@ var __exports__ = (() => {
|
|
|
1532
1767
|
coordLength
|
|
1533
1768
|
} = geometryInfo;
|
|
1534
1769
|
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
1535
|
-
const hasGlobalId =
|
|
1536
|
-
const GlobalFeatureIdsDataType =
|
|
1770
|
+
const hasGlobalId = features2[0] && "id" in features2[0];
|
|
1771
|
+
const GlobalFeatureIdsDataType = features2.length > 65535 ? Uint32Array : Uint16Array;
|
|
1537
1772
|
const points = {
|
|
1538
1773
|
type: "Point",
|
|
1539
1774
|
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
@@ -1588,7 +1823,7 @@ var __exports__ = (() => {
|
|
|
1588
1823
|
polygonFeature: 0,
|
|
1589
1824
|
feature: 0
|
|
1590
1825
|
};
|
|
1591
|
-
for (const feature of
|
|
1826
|
+
for (const feature of features2) {
|
|
1592
1827
|
const geometry = feature.geometry;
|
|
1593
1828
|
const properties = feature.properties || {};
|
|
1594
1829
|
switch (geometry.type) {
|
|
@@ -1832,7 +2067,7 @@ var __exports__ = (() => {
|
|
|
1832
2067
|
var navigator_ = globalThis.navigator || {};
|
|
1833
2068
|
|
|
1834
2069
|
// ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
|
|
1835
|
-
var
|
|
2070
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
|
|
1836
2071
|
var isBrowser3 = isBrowser2();
|
|
1837
2072
|
|
|
1838
2073
|
// ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
|
|
@@ -2017,7 +2252,7 @@ var __exports__ = (() => {
|
|
|
2017
2252
|
id: ""
|
|
2018
2253
|
};
|
|
2019
2254
|
_defineProperty(this, "id", void 0);
|
|
2020
|
-
_defineProperty(this, "VERSION",
|
|
2255
|
+
_defineProperty(this, "VERSION", VERSION2);
|
|
2021
2256
|
_defineProperty(this, "_startTs", getHiResTimestamp());
|
|
2022
2257
|
_defineProperty(this, "_deltaTs", getHiResTimestamp());
|
|
2023
2258
|
_defineProperty(this, "_storage", void 0);
|
|
@@ -2220,7 +2455,7 @@ var __exports__ = (() => {
|
|
|
2220
2455
|
return noop;
|
|
2221
2456
|
}
|
|
2222
2457
|
};
|
|
2223
|
-
_defineProperty(Log, "VERSION",
|
|
2458
|
+
_defineProperty(Log, "VERSION", VERSION2);
|
|
2224
2459
|
function normalizeLogLevel(logLevel) {
|
|
2225
2460
|
if (!logLevel) {
|
|
2226
2461
|
return 0;
|
|
@@ -2330,8 +2565,8 @@ var __exports__ = (() => {
|
|
|
2330
2565
|
});
|
|
2331
2566
|
|
|
2332
2567
|
// ../loader-utils/src/lib/log-utils/log.ts
|
|
2333
|
-
var
|
|
2334
|
-
var version =
|
|
2568
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2569
|
+
var version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
|
|
2335
2570
|
function createLog() {
|
|
2336
2571
|
const log2 = new Log({ id: "loaders.gl" });
|
|
2337
2572
|
globalThis.loaders = globalThis.loaders || {};
|
|
@@ -2429,7 +2664,7 @@ var __exports__ = (() => {
|
|
|
2429
2664
|
p[1] /= extent;
|
|
2430
2665
|
}
|
|
2431
2666
|
function convertToLocalCoordinatesFlat(data, extent) {
|
|
2432
|
-
for (let i = 0
|
|
2667
|
+
for (let i = 0; i < data.length; ++i) {
|
|
2433
2668
|
data[i] /= extent;
|
|
2434
2669
|
}
|
|
2435
2670
|
}
|
|
@@ -2981,7 +3216,7 @@ var __exports__ = (() => {
|
|
|
2981
3216
|
return binaryData;
|
|
2982
3217
|
}
|
|
2983
3218
|
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2984
|
-
const
|
|
3219
|
+
const features2 = [];
|
|
2985
3220
|
const geometryInfo = {
|
|
2986
3221
|
coordLength: 2,
|
|
2987
3222
|
pointPositionsCount: 0,
|
|
@@ -2995,7 +3230,7 @@ var __exports__ = (() => {
|
|
|
2995
3230
|
polygonFeaturesCount: 0
|
|
2996
3231
|
};
|
|
2997
3232
|
if (arrayBuffer.byteLength <= 0) {
|
|
2998
|
-
return [
|
|
3233
|
+
return [features2, geometryInfo];
|
|
2999
3234
|
}
|
|
3000
3235
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
3001
3236
|
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
@@ -3007,16 +3242,16 @@ var __exports__ = (() => {
|
|
|
3007
3242
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
3008
3243
|
const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
|
|
3009
3244
|
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
3010
|
-
|
|
3245
|
+
features2.push(decodedFeature);
|
|
3011
3246
|
}
|
|
3012
3247
|
});
|
|
3013
|
-
return [
|
|
3248
|
+
return [features2, geometryInfo];
|
|
3014
3249
|
}
|
|
3015
3250
|
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
3016
3251
|
if (arrayBuffer.byteLength <= 0) {
|
|
3017
3252
|
return [];
|
|
3018
3253
|
}
|
|
3019
|
-
const
|
|
3254
|
+
const features2 = [];
|
|
3020
3255
|
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
3021
3256
|
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
3022
3257
|
selectedLayers.forEach((layerName) => {
|
|
@@ -3027,10 +3262,10 @@ var __exports__ = (() => {
|
|
|
3027
3262
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
3028
3263
|
const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
|
|
3029
3264
|
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
3030
|
-
|
|
3265
|
+
features2.push(decodedFeature);
|
|
3031
3266
|
}
|
|
3032
3267
|
});
|
|
3033
|
-
return
|
|
3268
|
+
return features2;
|
|
3034
3269
|
}
|
|
3035
3270
|
function checkOptions(options) {
|
|
3036
3271
|
if (!options?.mvt) {
|
|
@@ -3064,14 +3299,14 @@ var __exports__ = (() => {
|
|
|
3064
3299
|
}
|
|
3065
3300
|
|
|
3066
3301
|
// src/mvt-loader.ts
|
|
3067
|
-
var
|
|
3302
|
+
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3068
3303
|
var MVTWorkerLoader = {
|
|
3069
3304
|
dataType: null,
|
|
3070
3305
|
batchType: null,
|
|
3071
3306
|
name: "Mapbox Vector Tile",
|
|
3072
3307
|
id: "mvt",
|
|
3073
3308
|
module: "mvt",
|
|
3074
|
-
version:
|
|
3309
|
+
version: VERSION4,
|
|
3075
3310
|
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
3076
3311
|
extensions: ["mvt", "pbf"],
|
|
3077
3312
|
mimeTypes: [
|
|
@@ -3099,241 +3334,6 @@ var __exports__ = (() => {
|
|
|
3099
3334
|
binary: true
|
|
3100
3335
|
};
|
|
3101
3336
|
|
|
3102
|
-
// src/lib/parse-tilejson.ts
|
|
3103
|
-
var isObject = (x) => x !== null && typeof x === "object";
|
|
3104
|
-
function parseTileJSON(jsonMetadata, options) {
|
|
3105
|
-
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
3106
|
-
return null;
|
|
3107
|
-
}
|
|
3108
|
-
let tileJSON = {
|
|
3109
|
-
name: jsonMetadata.name || "",
|
|
3110
|
-
description: jsonMetadata.description || ""
|
|
3111
|
-
};
|
|
3112
|
-
if (typeof jsonMetadata.generator === "string") {
|
|
3113
|
-
tileJSON.generator = jsonMetadata.generator;
|
|
3114
|
-
}
|
|
3115
|
-
if (typeof jsonMetadata.generator_options === "string") {
|
|
3116
|
-
tileJSON.generatorOptions = jsonMetadata.generator_options;
|
|
3117
|
-
}
|
|
3118
|
-
tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
|
|
3119
|
-
tileJSON.center = parseCenter(jsonMetadata.center);
|
|
3120
|
-
tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
3121
|
-
tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
3122
|
-
if (typeof jsonMetadata?.json === "string") {
|
|
3123
|
-
try {
|
|
3124
|
-
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
3125
|
-
} catch (error) {
|
|
3126
|
-
console.warn("Failed to parse tilejson.json field", error);
|
|
3127
|
-
}
|
|
3128
|
-
}
|
|
3129
|
-
const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
|
|
3130
|
-
const tileStatsLayers = parseTilestatsLayers(tilestats, options);
|
|
3131
|
-
const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
3132
|
-
const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
|
|
3133
|
-
tileJSON = {
|
|
3134
|
-
...tileJSON,
|
|
3135
|
-
layers
|
|
3136
|
-
};
|
|
3137
|
-
if (tileJSON.maxZoom === null && layers.length > 0) {
|
|
3138
|
-
tileJSON.maxZoom = layers[0].maxZoom || null;
|
|
3139
|
-
}
|
|
3140
|
-
if (tileJSON.minZoom === null && layers.length > 0) {
|
|
3141
|
-
tileJSON.minZoom = layers[0].minZoom || null;
|
|
3142
|
-
}
|
|
3143
|
-
return tileJSON;
|
|
3144
|
-
}
|
|
3145
|
-
function parseTileJSONLayers(layers) {
|
|
3146
|
-
if (!Array.isArray(layers)) {
|
|
3147
|
-
return [];
|
|
3148
|
-
}
|
|
3149
|
-
return layers.map((layer) => parseTileJSONLayer(layer));
|
|
3150
|
-
}
|
|
3151
|
-
function parseTileJSONLayer(layer) {
|
|
3152
|
-
const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
3153
|
-
name: key,
|
|
3154
|
-
...attributeTypeToFieldType(String(datatype))
|
|
3155
|
-
}));
|
|
3156
|
-
const layer2 = { ...layer };
|
|
3157
|
-
delete layer2.fields;
|
|
3158
|
-
return {
|
|
3159
|
-
name: layer.id || "",
|
|
3160
|
-
...layer2,
|
|
3161
|
-
fields
|
|
3162
|
-
};
|
|
3163
|
-
}
|
|
3164
|
-
function parseTilestatsLayers(tilestats, options) {
|
|
3165
|
-
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
3166
|
-
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
|
|
3167
|
-
}
|
|
3168
|
-
return [];
|
|
3169
|
-
}
|
|
3170
|
-
function parseTilestatsForLayer(layer, options) {
|
|
3171
|
-
const fields = [];
|
|
3172
|
-
const indexedAttributes = {};
|
|
3173
|
-
const attributes = layer.attributes || [];
|
|
3174
|
-
for (const attribute of attributes) {
|
|
3175
|
-
const name = attribute.attribute;
|
|
3176
|
-
if (typeof name === "string") {
|
|
3177
|
-
if (name.split("|").length > 1) {
|
|
3178
|
-
const fname = name.split("|")[0];
|
|
3179
|
-
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
3180
|
-
indexedAttributes[fname].push(attribute);
|
|
3181
|
-
console.warn("ignoring tilestats indexed field", fname);
|
|
3182
|
-
} else if (!fields[name]) {
|
|
3183
|
-
fields.push(attributeToField(attribute, options));
|
|
3184
|
-
} else {
|
|
3185
|
-
}
|
|
3186
|
-
}
|
|
3187
|
-
}
|
|
3188
|
-
return {
|
|
3189
|
-
name: layer.layer || "",
|
|
3190
|
-
dominantGeometry: layer.geometry,
|
|
3191
|
-
fields
|
|
3192
|
-
};
|
|
3193
|
-
}
|
|
3194
|
-
function mergeLayers(layers, tilestatsLayers) {
|
|
3195
|
-
return layers.map((layer) => {
|
|
3196
|
-
const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
|
|
3197
|
-
const fields = tilestatsLayer?.fields || [];
|
|
3198
|
-
const layer2 = { ...layer };
|
|
3199
|
-
delete layer2.fields;
|
|
3200
|
-
return {
|
|
3201
|
-
...layer2,
|
|
3202
|
-
...tilestatsLayer,
|
|
3203
|
-
fields
|
|
3204
|
-
};
|
|
3205
|
-
});
|
|
3206
|
-
}
|
|
3207
|
-
function parseBounds(bounds) {
|
|
3208
|
-
const result = fromArrayOrString(bounds);
|
|
3209
|
-
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
3210
|
-
return [
|
|
3211
|
-
[result[0], result[1]],
|
|
3212
|
-
[result[2], result[3]]
|
|
3213
|
-
];
|
|
3214
|
-
}
|
|
3215
|
-
return void 0;
|
|
3216
|
-
}
|
|
3217
|
-
function parseCenter(center) {
|
|
3218
|
-
const result = fromArrayOrString(center);
|
|
3219
|
-
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
3220
|
-
return result;
|
|
3221
|
-
}
|
|
3222
|
-
return null;
|
|
3223
|
-
}
|
|
3224
|
-
function safeParseFloat(input) {
|
|
3225
|
-
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
3226
|
-
return result === null || isNaN(result) ? null : result;
|
|
3227
|
-
}
|
|
3228
|
-
function isLat(num) {
|
|
3229
|
-
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
3230
|
-
}
|
|
3231
|
-
function isLng(num) {
|
|
3232
|
-
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
3233
|
-
}
|
|
3234
|
-
function isZoom(num) {
|
|
3235
|
-
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
3236
|
-
}
|
|
3237
|
-
function fromArrayOrString(data) {
|
|
3238
|
-
if (typeof data === "string") {
|
|
3239
|
-
return data.split(",").map(parseFloat);
|
|
3240
|
-
} else if (Array.isArray(data)) {
|
|
3241
|
-
return data;
|
|
3242
|
-
}
|
|
3243
|
-
return null;
|
|
3244
|
-
}
|
|
3245
|
-
var attrTypeMap = {
|
|
3246
|
-
number: {
|
|
3247
|
-
type: "float32"
|
|
3248
|
-
},
|
|
3249
|
-
numeric: {
|
|
3250
|
-
type: "float32"
|
|
3251
|
-
},
|
|
3252
|
-
string: {
|
|
3253
|
-
type: "utf8"
|
|
3254
|
-
},
|
|
3255
|
-
vachar: {
|
|
3256
|
-
type: "utf8"
|
|
3257
|
-
},
|
|
3258
|
-
float: {
|
|
3259
|
-
type: "float32"
|
|
3260
|
-
},
|
|
3261
|
-
int: {
|
|
3262
|
-
type: "int32"
|
|
3263
|
-
},
|
|
3264
|
-
int4: {
|
|
3265
|
-
type: "int32"
|
|
3266
|
-
},
|
|
3267
|
-
boolean: {
|
|
3268
|
-
type: "boolean"
|
|
3269
|
-
},
|
|
3270
|
-
bool: {
|
|
3271
|
-
type: "boolean"
|
|
3272
|
-
}
|
|
3273
|
-
};
|
|
3274
|
-
function attributeToField(attribute = {}, options) {
|
|
3275
|
-
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
3276
|
-
const field = {
|
|
3277
|
-
name: attribute.attribute,
|
|
3278
|
-
// what happens if attribute type is string...
|
|
3279
|
-
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
3280
|
-
...fieldTypes
|
|
3281
|
-
};
|
|
3282
|
-
if (typeof attribute.min === "number") {
|
|
3283
|
-
field.min = attribute.min;
|
|
3284
|
-
}
|
|
3285
|
-
if (typeof attribute.max === "number") {
|
|
3286
|
-
field.max = attribute.max;
|
|
3287
|
-
}
|
|
3288
|
-
if (typeof attribute.count === "number") {
|
|
3289
|
-
field.uniqueValueCount = attribute.count;
|
|
3290
|
-
}
|
|
3291
|
-
if (attribute.values) {
|
|
3292
|
-
field.values = attribute.values;
|
|
3293
|
-
}
|
|
3294
|
-
if (field.values && typeof options.maxValues === "number") {
|
|
3295
|
-
field.values = field.values?.slice(0, options.maxValues);
|
|
3296
|
-
}
|
|
3297
|
-
return field;
|
|
3298
|
-
}
|
|
3299
|
-
function attributeTypeToFieldType(aType) {
|
|
3300
|
-
const type = aType.toLowerCase();
|
|
3301
|
-
if (!type || !attrTypeMap[type]) {
|
|
3302
|
-
}
|
|
3303
|
-
return attrTypeMap[type] || { type: "string" };
|
|
3304
|
-
}
|
|
3305
|
-
|
|
3306
|
-
// src/tilejson-loader.ts
|
|
3307
|
-
var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3308
|
-
var TileJSONLoader = {
|
|
3309
|
-
dataType: null,
|
|
3310
|
-
batchType: null,
|
|
3311
|
-
name: "TileJSON",
|
|
3312
|
-
id: "tilejson",
|
|
3313
|
-
module: "pmtiles",
|
|
3314
|
-
version: VERSION4,
|
|
3315
|
-
worker: true,
|
|
3316
|
-
extensions: ["json"],
|
|
3317
|
-
mimeTypes: ["application/json"],
|
|
3318
|
-
text: true,
|
|
3319
|
-
options: {
|
|
3320
|
-
tilejson: {
|
|
3321
|
-
maxValues: void 0
|
|
3322
|
-
}
|
|
3323
|
-
},
|
|
3324
|
-
parse: async (arrayBuffer, options) => {
|
|
3325
|
-
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
3326
|
-
const json = JSON.parse(jsonString);
|
|
3327
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3328
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3329
|
-
},
|
|
3330
|
-
parseTextSync: (text, options) => {
|
|
3331
|
-
const json = JSON.parse(text);
|
|
3332
|
-
const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
|
|
3333
|
-
return parseTileJSON(json, tilejsonOptions);
|
|
3334
|
-
}
|
|
3335
|
-
};
|
|
3336
|
-
|
|
3337
3337
|
// ../images/src/lib/utils/version.ts
|
|
3338
3338
|
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3339
3339
|
|
|
@@ -3743,7 +3743,27 @@ var __exports__ = (() => {
|
|
|
3743
3743
|
};
|
|
3744
3744
|
|
|
3745
3745
|
// src/mvt-source.ts
|
|
3746
|
-
var MVTSource =
|
|
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 {
|
|
3747
3767
|
props;
|
|
3748
3768
|
url;
|
|
3749
3769
|
metadataUrl = null;
|
|
@@ -3752,12 +3772,12 @@ var __exports__ = (() => {
|
|
|
3752
3772
|
metadata;
|
|
3753
3773
|
extension;
|
|
3754
3774
|
mimeType = null;
|
|
3755
|
-
constructor(props) {
|
|
3775
|
+
constructor(url, props) {
|
|
3756
3776
|
super(props);
|
|
3757
3777
|
this.props = props;
|
|
3758
|
-
this.url = resolvePath(
|
|
3759
|
-
this.metadataUrl = props.metadataUrl
|
|
3760
|
-
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";
|
|
3761
3781
|
this.data = this.url;
|
|
3762
3782
|
this.getTileData = this.getTileData.bind(this);
|
|
3763
3783
|
this.metadata = this.getMetadata();
|
|
@@ -4073,107 +4093,353 @@ var __exports__ = (() => {
|
|
|
4073
4093
|
}
|
|
4074
4094
|
};
|
|
4075
4095
|
|
|
4076
|
-
// src/lib/vector-tiler/
|
|
4077
|
-
function
|
|
4078
|
-
|
|
4079
|
-
const
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
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;
|
|
4118
4184
|
}
|
|
4185
|
+
tile.protoFeatures.push(tileFeature);
|
|
4119
4186
|
}
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
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))];
|
|
4123
4254
|
}
|
|
4124
4255
|
|
|
4125
|
-
// src/lib/vector-tiler/
|
|
4126
|
-
function
|
|
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) {
|
|
4127
4329
|
const feature = {
|
|
4128
4330
|
// eslint-disable-next-line
|
|
4129
4331
|
id: id == null ? null : id,
|
|
4130
4332
|
type,
|
|
4131
|
-
|
|
4333
|
+
simplifiedType: void 0,
|
|
4334
|
+
// TODO
|
|
4335
|
+
geometry,
|
|
4132
4336
|
tags,
|
|
4133
4337
|
minX: Infinity,
|
|
4134
4338
|
minY: Infinity,
|
|
4135
4339
|
maxX: -Infinity,
|
|
4136
4340
|
maxY: -Infinity
|
|
4137
4341
|
};
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
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));
|
|
4150
4363
|
}
|
|
4151
4364
|
return feature;
|
|
4152
4365
|
}
|
|
4153
|
-
function calcLineBBox(feature,
|
|
4154
|
-
for (let i = 0; i <
|
|
4155
|
-
feature.minX = Math.min(feature.minX,
|
|
4156
|
-
feature.minY = Math.min(feature.minY,
|
|
4157
|
-
feature.maxX = Math.max(feature.maxX,
|
|
4158
|
-
feature.maxY = Math.max(feature.maxY,
|
|
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]);
|
|
4159
4372
|
}
|
|
4160
4373
|
}
|
|
4161
4374
|
|
|
4162
|
-
// src/lib/vector-tiler/
|
|
4163
|
-
function
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4375
|
+
// src/lib/vector-tiler/features/simplify-path.ts
|
|
4376
|
+
function simplifyPath(coords, first, last, sqTolerance) {
|
|
4377
|
+
let maxSqDist = sqTolerance;
|
|
4378
|
+
const mid = last - first >> 1;
|
|
4379
|
+
let minPosToMid = last - first;
|
|
4380
|
+
let index;
|
|
4381
|
+
const ax = coords[first];
|
|
4382
|
+
const ay = coords[first + 1];
|
|
4383
|
+
const bx = coords[last];
|
|
4384
|
+
const by = coords[last + 1];
|
|
4385
|
+
for (let i = first + 3; i < last; i += 3) {
|
|
4386
|
+
const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
|
|
4387
|
+
if (d > maxSqDist) {
|
|
4388
|
+
index = i;
|
|
4389
|
+
maxSqDist = d;
|
|
4390
|
+
} else if (d === maxSqDist) {
|
|
4391
|
+
const posToMid = Math.abs(i - mid);
|
|
4392
|
+
if (posToMid < minPosToMid) {
|
|
4393
|
+
index = i;
|
|
4394
|
+
minPosToMid = posToMid;
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
if (maxSqDist > sqTolerance) {
|
|
4399
|
+
if (index - first > 3)
|
|
4400
|
+
simplifyPath(coords, first, index, sqTolerance);
|
|
4401
|
+
coords[index + 2] = maxSqDist;
|
|
4402
|
+
if (last - index > 3)
|
|
4403
|
+
simplifyPath(coords, index, last, sqTolerance);
|
|
4173
4404
|
}
|
|
4174
|
-
return features;
|
|
4175
4405
|
}
|
|
4176
|
-
function
|
|
4406
|
+
function getSqSegDist(px, py, x, y, bx, by) {
|
|
4407
|
+
let dx = bx - x;
|
|
4408
|
+
let dy = by - y;
|
|
4409
|
+
if (dx !== 0 || dy !== 0) {
|
|
4410
|
+
const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
|
|
4411
|
+
if (t > 1) {
|
|
4412
|
+
x = bx;
|
|
4413
|
+
y = by;
|
|
4414
|
+
} else if (t > 0) {
|
|
4415
|
+
x += dx * t;
|
|
4416
|
+
y += dy * t;
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
dx = px - x;
|
|
4420
|
+
dy = py - y;
|
|
4421
|
+
return dx * dx + dy * dy;
|
|
4422
|
+
}
|
|
4423
|
+
|
|
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));
|
|
4439
|
+
}
|
|
4440
|
+
return protoFeatures;
|
|
4441
|
+
}
|
|
4442
|
+
function convertFeature(geojson, options, index) {
|
|
4177
4443
|
if (!geojson.geometry) {
|
|
4178
4444
|
return;
|
|
4179
4445
|
}
|
|
@@ -4187,51 +4453,57 @@ var __exports__ = (() => {
|
|
|
4187
4453
|
} else if (options.generateId) {
|
|
4188
4454
|
id = index || 0;
|
|
4189
4455
|
}
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
convertLine(coords, geometry, tolerance, false);
|
|
4198
|
-
} else if (type === "MultiLineString") {
|
|
4199
|
-
if (options.lineMetrics) {
|
|
4200
|
-
for (const line of coords) {
|
|
4201
|
-
geometry = [];
|
|
4202
|
-
convertLine(line, geometry, tolerance, false);
|
|
4203
|
-
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);
|
|
4204
4463
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
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.");
|
|
4233
4505
|
}
|
|
4234
|
-
|
|
4506
|
+
return createProtoFeature(id, type, geometry, geojson.properties);
|
|
4235
4507
|
}
|
|
4236
4508
|
function convertPoint(coords, out) {
|
|
4237
4509
|
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
@@ -4255,7 +4527,7 @@ var __exports__ = (() => {
|
|
|
4255
4527
|
}
|
|
4256
4528
|
const last = out.length - 3;
|
|
4257
4529
|
out[2] = 1;
|
|
4258
|
-
|
|
4530
|
+
simplifyPath(out, 0, last, tolerance);
|
|
4259
4531
|
out[last + 2] = 1;
|
|
4260
4532
|
out.size = Math.abs(size);
|
|
4261
4533
|
out.start = 0;
|
|
@@ -4277,17 +4549,17 @@ var __exports__ = (() => {
|
|
|
4277
4549
|
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
4278
4550
|
}
|
|
4279
4551
|
|
|
4280
|
-
// src/lib/vector-tiler/clip.ts
|
|
4281
|
-
function
|
|
4552
|
+
// src/lib/vector-tiler/features/clip-features.ts
|
|
4553
|
+
function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
4282
4554
|
k1 /= scale;
|
|
4283
4555
|
k2 /= scale;
|
|
4284
4556
|
if (minAll >= k1 && maxAll < k2) {
|
|
4285
|
-
return
|
|
4557
|
+
return features2;
|
|
4286
4558
|
} else if (maxAll < k1 || minAll >= k2) {
|
|
4287
4559
|
return null;
|
|
4288
4560
|
}
|
|
4289
4561
|
const clipped = [];
|
|
4290
|
-
for (const feature of
|
|
4562
|
+
for (const feature of features2) {
|
|
4291
4563
|
const geometry = feature.geometry;
|
|
4292
4564
|
let type = feature.type;
|
|
4293
4565
|
const min = axis === 0 ? feature.minX : feature.minY;
|
|
@@ -4319,7 +4591,7 @@ var __exports__ = (() => {
|
|
|
4319
4591
|
if (newGeometry.length) {
|
|
4320
4592
|
if (options.lineMetrics && type === "LineString") {
|
|
4321
4593
|
for (const line of newGeometry) {
|
|
4322
|
-
clipped.push(
|
|
4594
|
+
clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
|
|
4323
4595
|
}
|
|
4324
4596
|
continue;
|
|
4325
4597
|
}
|
|
@@ -4334,7 +4606,7 @@ var __exports__ = (() => {
|
|
|
4334
4606
|
if (type === "Point" || type === "MultiPoint") {
|
|
4335
4607
|
type = newGeometry.length === 3 ? "Point" : "MultiPoint";
|
|
4336
4608
|
}
|
|
4337
|
-
clipped.push(
|
|
4609
|
+
clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
4338
4610
|
}
|
|
4339
4611
|
}
|
|
4340
4612
|
return clipped.length ? clipped : null;
|
|
@@ -4442,14 +4714,14 @@ var __exports__ = (() => {
|
|
|
4442
4714
|
return t;
|
|
4443
4715
|
}
|
|
4444
4716
|
|
|
4445
|
-
// src/lib/vector-tiler/wrap.ts
|
|
4446
|
-
function
|
|
4717
|
+
// src/lib/vector-tiler/features/wrap-features.ts
|
|
4718
|
+
function wrapFeatures(features2, options) {
|
|
4447
4719
|
const buffer = options.buffer / options.extent;
|
|
4448
|
-
let merged =
|
|
4449
|
-
const left =
|
|
4450
|
-
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);
|
|
4451
4723
|
if (left || right) {
|
|
4452
|
-
merged =
|
|
4724
|
+
merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
|
|
4453
4725
|
if (left) {
|
|
4454
4726
|
merged = shiftFeatureCoords(left, 1).concat(merged);
|
|
4455
4727
|
}
|
|
@@ -4459,30 +4731,39 @@ var __exports__ = (() => {
|
|
|
4459
4731
|
}
|
|
4460
4732
|
return merged;
|
|
4461
4733
|
}
|
|
4462
|
-
function shiftFeatureCoords(
|
|
4734
|
+
function shiftFeatureCoords(features2, offset) {
|
|
4463
4735
|
const newFeatures = [];
|
|
4464
|
-
for (let i = 0; i <
|
|
4465
|
-
const feature =
|
|
4736
|
+
for (let i = 0; i < features2.length; i++) {
|
|
4737
|
+
const feature = features2[i];
|
|
4466
4738
|
const type = feature.type;
|
|
4467
4739
|
let newGeometry;
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
for (const line of polygon) {
|
|
4480
|
-
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));
|
|
4481
4751
|
}
|
|
4482
|
-
|
|
4483
|
-
|
|
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));
|
|
4484
4765
|
}
|
|
4485
|
-
newFeatures.push(
|
|
4766
|
+
newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
4486
4767
|
}
|
|
4487
4768
|
return newFeatures;
|
|
4488
4769
|
}
|
|
@@ -4499,148 +4780,47 @@ var __exports__ = (() => {
|
|
|
4499
4780
|
return newPoints;
|
|
4500
4781
|
}
|
|
4501
4782
|
|
|
4502
|
-
// src/
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
const ring = [];
|
|
4521
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
4522
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
4523
|
-
}
|
|
4524
|
-
feature.geometry.push(ring);
|
|
4525
|
-
}
|
|
4526
|
-
}
|
|
4527
|
-
}
|
|
4528
|
-
tile.transformed = true;
|
|
4529
|
-
return tile;
|
|
4530
|
-
}
|
|
4531
|
-
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
4532
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
4533
|
-
}
|
|
4534
|
-
|
|
4535
|
-
// src/lib/vector-tiler/tile.ts
|
|
4536
|
-
function createTile(features, z, tx, ty, options) {
|
|
4537
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
4538
|
-
const tile = {
|
|
4539
|
-
features: [],
|
|
4540
|
-
numPoints: 0,
|
|
4541
|
-
numSimplified: 0,
|
|
4542
|
-
numFeatures: features.length,
|
|
4543
|
-
source: null,
|
|
4544
|
-
x: tx,
|
|
4545
|
-
y: ty,
|
|
4546
|
-
z,
|
|
4547
|
-
transformed: false,
|
|
4548
|
-
minX: 2,
|
|
4549
|
-
minY: 1,
|
|
4550
|
-
maxX: -1,
|
|
4551
|
-
maxY: 0
|
|
4552
|
-
};
|
|
4553
|
-
for (const feature of features) {
|
|
4554
|
-
addFeature(tile, feature, tolerance, options);
|
|
4555
|
-
}
|
|
4556
|
-
return tile;
|
|
4557
|
-
}
|
|
4558
|
-
function addFeature(tile, feature, tolerance, options) {
|
|
4559
|
-
const geom = feature.geometry;
|
|
4560
|
-
const type = feature.type;
|
|
4561
|
-
const simplified = [];
|
|
4562
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
4563
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
4564
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
4565
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
4566
|
-
if (type === "Point" || type === "MultiPoint") {
|
|
4567
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
4568
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
4569
|
-
tile.numPoints++;
|
|
4570
|
-
tile.numSimplified++;
|
|
4571
|
-
}
|
|
4572
|
-
} else if (type === "LineString") {
|
|
4573
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
4574
|
-
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
4575
|
-
for (let i = 0; i < geom.length; i++) {
|
|
4576
|
-
addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
|
|
4577
|
-
}
|
|
4578
|
-
} else if (type === "MultiPolygon") {
|
|
4579
|
-
for (let k = 0; k < geom.length; k++) {
|
|
4580
|
-
const polygon = geom[k];
|
|
4581
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
4582
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
4583
|
-
}
|
|
4584
|
-
}
|
|
4585
|
-
}
|
|
4586
|
-
if (simplified.length) {
|
|
4587
|
-
let tags = feature.tags || null;
|
|
4588
|
-
if (type === "LineString" && options.lineMetrics) {
|
|
4589
|
-
tags = {};
|
|
4590
|
-
for (const key in feature.tags)
|
|
4591
|
-
tags[key] = feature.tags[key];
|
|
4592
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
4593
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
4594
|
-
}
|
|
4595
|
-
const tileFeature = {
|
|
4596
|
-
geometry: simplified,
|
|
4597
|
-
type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
|
|
4598
|
-
tags
|
|
4599
|
-
};
|
|
4600
|
-
if (feature.id !== null) {
|
|
4601
|
-
tileFeature.id = feature.id;
|
|
4602
|
-
}
|
|
4603
|
-
tile.features.push(tileFeature);
|
|
4604
|
-
}
|
|
4605
|
-
}
|
|
4606
|
-
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
4607
|
-
const sqTolerance = tolerance * tolerance;
|
|
4608
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
4609
|
-
tile.numPoints += geom.length / 3;
|
|
4610
|
-
return;
|
|
4611
|
-
}
|
|
4612
|
-
const ring = [];
|
|
4613
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
4614
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
4615
|
-
tile.numSimplified++;
|
|
4616
|
-
ring.push(geom[i], geom[i + 1]);
|
|
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
|
|
4617
4801
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
4627
|
-
area2 += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
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);
|
|
4628
4810
|
}
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
ring[len - 1 - i] = y;
|
|
4637
|
-
}
|
|
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);
|
|
4638
4818
|
}
|
|
4819
|
+
const data = await url.arrayBuffer();
|
|
4820
|
+
return await loader.parse(data);
|
|
4639
4821
|
}
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
var _TableTileSource = class {
|
|
4643
|
-
/** Stats for this TableTileSource */
|
|
4822
|
+
var _DynamicVectorTileSource = class {
|
|
4823
|
+
/** Stats for this DynamicVectorTileSource */
|
|
4644
4824
|
stats = new Stats({
|
|
4645
4825
|
id: "table-tile-source",
|
|
4646
4826
|
stats: [new Stat("tiles", "count"), new Stat("features", "count")]
|
|
@@ -4649,6 +4829,7 @@ var __exports__ = (() => {
|
|
|
4649
4829
|
mimeType = "application/vnd.mapbox-vector-tile";
|
|
4650
4830
|
localCoordinates = true;
|
|
4651
4831
|
/** The props that this tile source was created with */
|
|
4832
|
+
// @ts-expect-error
|
|
4652
4833
|
props;
|
|
4653
4834
|
/* Schema of the data */
|
|
4654
4835
|
schema = null;
|
|
@@ -4661,7 +4842,7 @@ var __exports__ = (() => {
|
|
|
4661
4842
|
/** Metadata for the tile source (generated TileJSON/tilestats */
|
|
4662
4843
|
metadata;
|
|
4663
4844
|
constructor(table, props) {
|
|
4664
|
-
this.props = { ...
|
|
4845
|
+
this.props = { ...TableTileSource.options.table, ...props?.table };
|
|
4665
4846
|
this.getTileData = this.getTileData.bind(this);
|
|
4666
4847
|
this.ready = this.initializeTilesAsync(table);
|
|
4667
4848
|
this.metadata = this.getMetadata();
|
|
@@ -4705,11 +4886,11 @@ var __exports__ = (() => {
|
|
|
4705
4886
|
* @note Application must await `source.ready` before calling sync methods.
|
|
4706
4887
|
*/
|
|
4707
4888
|
getTileSync(tileIndex) {
|
|
4708
|
-
const
|
|
4709
|
-
if (!
|
|
4889
|
+
const protoTile = this.getProtoTile(tileIndex);
|
|
4890
|
+
if (!protoTile) {
|
|
4710
4891
|
return null;
|
|
4711
4892
|
}
|
|
4712
|
-
return
|
|
4893
|
+
return convertTileToGeoJSON(protoTile, {
|
|
4713
4894
|
coordinates: this.props.coordinates,
|
|
4714
4895
|
tileIndex,
|
|
4715
4896
|
extent: this.props.extent
|
|
@@ -4726,28 +4907,32 @@ var __exports__ = (() => {
|
|
|
4726
4907
|
if (this.props.promoteId && this.props.generateId) {
|
|
4727
4908
|
throw new Error("promoteId and generateId cannot be used together.");
|
|
4728
4909
|
}
|
|
4729
|
-
log.log(1, "
|
|
4910
|
+
log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
|
|
4730
4911
|
log.time(1, "preprocess table")();
|
|
4731
|
-
let
|
|
4912
|
+
let features2 = convertFeaturesToProtoFeature(table, this.props);
|
|
4732
4913
|
log.timeEnd(1, "preprocess table")();
|
|
4733
4914
|
log.time(1, "generate tiles")();
|
|
4734
|
-
|
|
4735
|
-
if (
|
|
4736
|
-
log.log(1, "
|
|
4915
|
+
features2 = wrapFeatures(features2, this.props);
|
|
4916
|
+
if (features2.length === 0) {
|
|
4917
|
+
log.log(1, "DynamicVectorTileSource: no features generated")();
|
|
4737
4918
|
return;
|
|
4738
4919
|
}
|
|
4739
|
-
this.splitTile(
|
|
4920
|
+
this.splitTile(features2, 0, 0, 0);
|
|
4740
4921
|
const rootTile = this.tiles[0];
|
|
4741
4922
|
log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
|
|
4742
4923
|
log.timeEnd(1, "generate tiles")();
|
|
4743
|
-
log.log(
|
|
4924
|
+
log.log(
|
|
4925
|
+
1,
|
|
4926
|
+
`DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`,
|
|
4927
|
+
this.stats
|
|
4928
|
+
)();
|
|
4744
4929
|
}
|
|
4745
4930
|
/**
|
|
4746
4931
|
* Return geojsonvt-style "half formed" vector tile
|
|
4747
4932
|
* @note Application must await `source.ready` before calling sync methods.
|
|
4748
4933
|
*/
|
|
4749
4934
|
// eslint-disable-next-line complexity, max-statements
|
|
4750
|
-
|
|
4935
|
+
getProtoTile(tileIndex) {
|
|
4751
4936
|
const { z, y } = tileIndex;
|
|
4752
4937
|
let { x } = tileIndex;
|
|
4753
4938
|
const { extent } = this.props;
|
|
@@ -4771,12 +4956,12 @@ var __exports__ = (() => {
|
|
|
4771
4956
|
y0 = y0 >> 1;
|
|
4772
4957
|
parent = this.tiles[toID(z0, x0, y0)];
|
|
4773
4958
|
}
|
|
4774
|
-
if (!parent || !parent.
|
|
4959
|
+
if (!parent || !parent.sourceFeatures) {
|
|
4775
4960
|
return null;
|
|
4776
4961
|
}
|
|
4777
4962
|
log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
|
|
4778
4963
|
log.time(1, "drilling down")();
|
|
4779
|
-
this.splitTile(parent.
|
|
4964
|
+
this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
|
|
4780
4965
|
log.timeEnd(1, "drilling down")();
|
|
4781
4966
|
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
4782
4967
|
}
|
|
@@ -4789,28 +4974,28 @@ var __exports__ = (() => {
|
|
|
4789
4974
|
* zoom or the number of points is low as specified in the props.
|
|
4790
4975
|
*/
|
|
4791
4976
|
// eslint-disable-next-line max-params, max-statements, complexity
|
|
4792
|
-
splitTile(
|
|
4793
|
-
const stack = [
|
|
4977
|
+
splitTile(features2, z, x, y, cz, cx, cy) {
|
|
4978
|
+
const stack = [features2, z, x, y];
|
|
4794
4979
|
while (stack.length) {
|
|
4795
4980
|
y = stack.pop();
|
|
4796
4981
|
x = stack.pop();
|
|
4797
4982
|
z = stack.pop();
|
|
4798
|
-
|
|
4983
|
+
features2 = stack.pop();
|
|
4799
4984
|
const z2 = 1 << z;
|
|
4800
4985
|
const id = toID(z, x, y);
|
|
4801
4986
|
let tile = this.tiles[id];
|
|
4802
4987
|
if (!tile) {
|
|
4803
4988
|
log.time(2, "tile creation")();
|
|
4804
|
-
tile = this.tiles[id] =
|
|
4989
|
+
tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
|
|
4805
4990
|
this.tileCoords.push({ z, x, y });
|
|
4806
4991
|
const key = `z${z}`;
|
|
4807
4992
|
let stat = this.stats.get(key, "count");
|
|
4808
4993
|
stat.incrementCount();
|
|
4809
4994
|
stat = this.stats.get("total");
|
|
4810
4995
|
stat.incrementCount();
|
|
4811
|
-
stat =
|
|
4996
|
+
stat = _DynamicVectorTileSource.stats.get(key, "count");
|
|
4812
4997
|
stat.incrementCount();
|
|
4813
|
-
stat =
|
|
4998
|
+
stat = _DynamicVectorTileSource.stats.get("total");
|
|
4814
4999
|
stat.incrementCount();
|
|
4815
5000
|
log.log(
|
|
4816
5001
|
2,
|
|
@@ -4824,7 +5009,7 @@ var __exports__ = (() => {
|
|
|
4824
5009
|
)();
|
|
4825
5010
|
log.timeEnd(2, "tile creation")();
|
|
4826
5011
|
}
|
|
4827
|
-
tile.
|
|
5012
|
+
tile.sourceFeatures = features2;
|
|
4828
5013
|
if (cz === void 0) {
|
|
4829
5014
|
if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
|
|
4830
5015
|
continue;
|
|
@@ -4837,8 +5022,8 @@ var __exports__ = (() => {
|
|
|
4837
5022
|
continue;
|
|
4838
5023
|
}
|
|
4839
5024
|
}
|
|
4840
|
-
tile.
|
|
4841
|
-
if (
|
|
5025
|
+
tile.sourceFeatures = null;
|
|
5026
|
+
if (features2.length === 0)
|
|
4842
5027
|
continue;
|
|
4843
5028
|
log.time(2, "clipping tile")();
|
|
4844
5029
|
const k1 = 0.5 * this.props.buffer / this.props.extent;
|
|
@@ -4849,17 +5034,17 @@ var __exports__ = (() => {
|
|
|
4849
5034
|
let bl = null;
|
|
4850
5035
|
let tr = null;
|
|
4851
5036
|
let br = null;
|
|
4852
|
-
let left =
|
|
4853
|
-
let right =
|
|
4854
|
-
|
|
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;
|
|
4855
5040
|
if (left) {
|
|
4856
|
-
tl =
|
|
4857
|
-
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);
|
|
4858
5043
|
left = null;
|
|
4859
5044
|
}
|
|
4860
5045
|
if (right) {
|
|
4861
|
-
tr =
|
|
4862
|
-
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);
|
|
4863
5048
|
right = null;
|
|
4864
5049
|
}
|
|
4865
5050
|
log.timeEnd(2, "clipping tile")();
|
|
@@ -4870,111 +5055,15 @@ var __exports__ = (() => {
|
|
|
4870
5055
|
}
|
|
4871
5056
|
}
|
|
4872
5057
|
};
|
|
4873
|
-
var
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
// coordinates in tile coordinates or lng/lat
|
|
4877
|
-
maxZoom: 14,
|
|
4878
|
-
// max zoom to preserve detail on
|
|
4879
|
-
indexMaxZoom: 5,
|
|
4880
|
-
// max zoom in the tile index
|
|
4881
|
-
maxPointsPerTile: 1e5,
|
|
4882
|
-
// max number of points per tile in the tile index
|
|
4883
|
-
tolerance: 3,
|
|
4884
|
-
// simplification tolerance (higher means simpler)
|
|
4885
|
-
extent: 4096,
|
|
4886
|
-
// tile extent
|
|
4887
|
-
buffer: 64,
|
|
4888
|
-
// tile buffer on each side
|
|
4889
|
-
lineMetrics: false,
|
|
4890
|
-
// whether to calculate line metrics
|
|
4891
|
-
// @ts-expect-error
|
|
4892
|
-
promoteId: void 0,
|
|
4893
|
-
// name of a feature property to be promoted to feature.id
|
|
4894
|
-
generateId: false,
|
|
4895
|
-
// whether to generate feature ids. Cannot be used with promoteId
|
|
4896
|
-
debug: 0
|
|
4897
|
-
// logging level (0, 1 or 2)
|
|
4898
|
-
});
|
|
4899
|
-
/** Global stats for all TableTileSources */
|
|
4900
|
-
__publicField(TableTileSource, "stats", new Stats({
|
|
5058
|
+
var DynamicVectorTileSource = _DynamicVectorTileSource;
|
|
5059
|
+
/** Global stats for all DynamicVectorTileSources */
|
|
5060
|
+
__publicField(DynamicVectorTileSource, "stats", new Stats({
|
|
4901
5061
|
id: "table-tile-source-all",
|
|
4902
5062
|
stats: [new Stat("count", "tiles"), new Stat("count", "features")]
|
|
4903
5063
|
}));
|
|
4904
5064
|
function toID(z, x, y) {
|
|
4905
5065
|
return ((1 << z) * y + x) * 32 + z;
|
|
4906
5066
|
}
|
|
4907
|
-
function convertToGeoJSONTable(vtTile, props) {
|
|
4908
|
-
const features = [];
|
|
4909
|
-
for (const rawFeature of vtTile.features) {
|
|
4910
|
-
if (!rawFeature || !rawFeature.geometry) {
|
|
4911
|
-
continue;
|
|
4912
|
-
}
|
|
4913
|
-
let type;
|
|
4914
|
-
let coordinates;
|
|
4915
|
-
switch (rawFeature.type) {
|
|
4916
|
-
case 1:
|
|
4917
|
-
if (rawFeature.geometry.length === 1) {
|
|
4918
|
-
type = "Point";
|
|
4919
|
-
coordinates = rawFeature.geometry[0];
|
|
4920
|
-
} else {
|
|
4921
|
-
type = "MultiPoint";
|
|
4922
|
-
coordinates = rawFeature.geometry;
|
|
4923
|
-
}
|
|
4924
|
-
break;
|
|
4925
|
-
case 2:
|
|
4926
|
-
if (rawFeature.geometry.length === 1) {
|
|
4927
|
-
type = "LineString";
|
|
4928
|
-
coordinates = rawFeature.geometry[0];
|
|
4929
|
-
} else {
|
|
4930
|
-
type = "MultiLineString";
|
|
4931
|
-
coordinates = rawFeature.geometry;
|
|
4932
|
-
}
|
|
4933
|
-
break;
|
|
4934
|
-
case 3:
|
|
4935
|
-
if (rawFeature.geometry.length > 1) {
|
|
4936
|
-
type = "MultiPolygon";
|
|
4937
|
-
coordinates = [rawFeature.geometry];
|
|
4938
|
-
} else {
|
|
4939
|
-
type = "Polygon";
|
|
4940
|
-
coordinates = rawFeature.geometry;
|
|
4941
|
-
}
|
|
4942
|
-
break;
|
|
4943
|
-
default:
|
|
4944
|
-
continue;
|
|
4945
|
-
}
|
|
4946
|
-
switch (props.coordinates) {
|
|
4947
|
-
case "EPSG:4326":
|
|
4948
|
-
case "wgs84":
|
|
4949
|
-
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
4950
|
-
break;
|
|
4951
|
-
case "local":
|
|
4952
|
-
convertToLocalCoordinates(coordinates, props.extent);
|
|
4953
|
-
break;
|
|
4954
|
-
default:
|
|
4955
|
-
throw new Error(`Unsupported CRS ${props.coordinates}`);
|
|
4956
|
-
}
|
|
4957
|
-
const feature = {
|
|
4958
|
-
type: "Feature",
|
|
4959
|
-
geometry: {
|
|
4960
|
-
type,
|
|
4961
|
-
coordinates
|
|
4962
|
-
},
|
|
4963
|
-
properties: rawFeature.tags || {},
|
|
4964
|
-
id: rawFeature.id
|
|
4965
|
-
};
|
|
4966
|
-
features.push(feature);
|
|
4967
|
-
}
|
|
4968
|
-
if (features.length === 0) {
|
|
4969
|
-
return null;
|
|
4970
|
-
}
|
|
4971
|
-
const table = {
|
|
4972
|
-
shape: "geojson-table",
|
|
4973
|
-
type: "FeatureCollection",
|
|
4974
|
-
features
|
|
4975
|
-
};
|
|
4976
|
-
return table;
|
|
4977
|
-
}
|
|
4978
5067
|
return __toCommonJS(bundle_exports);
|
|
4979
5068
|
})();
|
|
4980
5069
|
/*! Bundled license information:
|