@loaders.gl/mvt 3.1.0-beta.3 → 3.1.1
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/bundle.js +114 -102
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/helpers/binary-util-functions.js +25 -22
- package/dist/es5/helpers/binary-util-functions.js.map +1 -1
- package/dist/es5/helpers/mapbox-util-functions.js +11 -11
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/es5/index.js +2 -2
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +137 -108
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +157 -147
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +38 -35
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/mvt-loader.js +38 -5
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/helpers/binary-util-functions.js +8 -5
- package/dist/esm/helpers/binary-util-functions.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +6 -5
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/helpers/binary-util-functions.d.ts +2 -6
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +7 -5
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
- package/dist/lib/parse-mvt.d.ts +8 -76
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +6 -5
- package/dist/lib/types.d.ts +0 -64
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +102 -97
- package/package.json +5 -4
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/parse-mvt.ts +10 -8
- package/src/lib/types.ts +0 -69
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -338
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -185
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -353
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
package/dist/bundle.js
CHANGED
|
@@ -877,12 +877,14 @@
|
|
|
877
877
|
|
|
878
878
|
// src/helpers/binary-util-functions.ts
|
|
879
879
|
function classifyRings2(geom) {
|
|
880
|
-
const len = geom.
|
|
880
|
+
const len = geom.indices.length;
|
|
881
|
+
const type = "Polygon";
|
|
881
882
|
if (len <= 1) {
|
|
882
883
|
return {
|
|
884
|
+
type,
|
|
883
885
|
data: geom.data,
|
|
884
886
|
areas: [[getPolygonSignedArea(geom.data)]],
|
|
885
|
-
|
|
887
|
+
indices: [geom.indices]
|
|
886
888
|
};
|
|
887
889
|
}
|
|
888
890
|
const areas = [];
|
|
@@ -892,8 +894,8 @@
|
|
|
892
894
|
let ccw;
|
|
893
895
|
let offset = 0;
|
|
894
896
|
for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
|
|
895
|
-
startIndex = geom.
|
|
896
|
-
endIndex = geom.
|
|
897
|
+
startIndex = geom.indices[i2] - offset;
|
|
898
|
+
endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
|
|
897
899
|
const shape = geom.data.slice(startIndex, endIndex);
|
|
898
900
|
const area2 = getPolygonSignedArea(shape);
|
|
899
901
|
if (area2 === 0) {
|
|
@@ -921,7 +923,7 @@
|
|
|
921
923
|
areas.push(ringAreas);
|
|
922
924
|
if (polygon.length)
|
|
923
925
|
polygons.push(polygon);
|
|
924
|
-
return { areas,
|
|
926
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
925
927
|
}
|
|
926
928
|
function project(data, x0, y0, size) {
|
|
927
929
|
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
@@ -962,10 +964,7 @@
|
|
|
962
964
|
"src/lib/binary-vector-tile/vector-tile-feature.ts"() {
|
|
963
965
|
init_binary_util_functions();
|
|
964
966
|
VectorTileFeature2 = class {
|
|
965
|
-
|
|
966
|
-
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
967
|
-
}
|
|
968
|
-
constructor(pbf, end, extent, keys, values, firstPassData) {
|
|
967
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
969
968
|
this.properties = {};
|
|
970
969
|
this.extent = extent;
|
|
971
970
|
this.type = 0;
|
|
@@ -974,7 +973,7 @@
|
|
|
974
973
|
this._geometry = -1;
|
|
975
974
|
this._keys = keys;
|
|
976
975
|
this._values = values;
|
|
977
|
-
this.
|
|
976
|
+
this._geometryInfo = geometryInfo;
|
|
978
977
|
pbf.readFields(readFeature2, this, end);
|
|
979
978
|
}
|
|
980
979
|
loadGeometry() {
|
|
@@ -986,7 +985,7 @@
|
|
|
986
985
|
x = 0;
|
|
987
986
|
y = 0;
|
|
988
987
|
i = 0;
|
|
989
|
-
const
|
|
988
|
+
const indices = [];
|
|
990
989
|
const data = [];
|
|
991
990
|
while (pbf.pos < endPos) {
|
|
992
991
|
if (length <= 0) {
|
|
@@ -999,13 +998,13 @@
|
|
|
999
998
|
x += pbf.readSVarint();
|
|
1000
999
|
y += pbf.readSVarint();
|
|
1001
1000
|
if (cmd === 1) {
|
|
1002
|
-
|
|
1001
|
+
indices.push(i);
|
|
1003
1002
|
}
|
|
1004
1003
|
data.push(x, y);
|
|
1005
1004
|
i += 2;
|
|
1006
1005
|
} else if (cmd === 7) {
|
|
1007
1006
|
if (i > 0) {
|
|
1008
|
-
const start =
|
|
1007
|
+
const start = indices[indices.length - 1];
|
|
1009
1008
|
data.push(data[start], data[start + 1]);
|
|
1010
1009
|
i += 2;
|
|
1011
1010
|
}
|
|
@@ -1013,42 +1012,38 @@
|
|
|
1013
1012
|
throw new Error(`unknown command ${cmd}`);
|
|
1014
1013
|
}
|
|
1015
1014
|
}
|
|
1016
|
-
return { data,
|
|
1015
|
+
return { data, indices };
|
|
1017
1016
|
}
|
|
1018
1017
|
_toBinaryCoordinates(transform) {
|
|
1019
|
-
|
|
1018
|
+
const geom = this.loadGeometry();
|
|
1019
|
+
let geometry;
|
|
1020
1020
|
transform(geom.data, this);
|
|
1021
1021
|
const coordLength = 2;
|
|
1022
1022
|
switch (this.type) {
|
|
1023
1023
|
case 1:
|
|
1024
|
-
this.
|
|
1025
|
-
this.
|
|
1024
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
1025
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1026
|
+
geometry = { type: "Point", ...geom };
|
|
1026
1027
|
break;
|
|
1027
1028
|
case 2:
|
|
1028
|
-
this.
|
|
1029
|
-
this.
|
|
1030
|
-
this.
|
|
1029
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
1030
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1031
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1032
|
+
geometry = { type: "LineString", ...geom };
|
|
1031
1033
|
break;
|
|
1032
1034
|
case 3:
|
|
1033
|
-
|
|
1034
|
-
this.
|
|
1035
|
-
this.
|
|
1036
|
-
for (const
|
|
1037
|
-
this.
|
|
1035
|
+
geometry = classifyRings2(geom);
|
|
1036
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
1037
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
1038
|
+
for (const indices of geometry.indices) {
|
|
1039
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
1038
1040
|
}
|
|
1039
|
-
this.
|
|
1040
|
-
geom = classified;
|
|
1041
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1041
1042
|
break;
|
|
1043
|
+
default:
|
|
1044
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1042
1045
|
}
|
|
1043
|
-
|
|
1044
|
-
if (geom.lines.length > 1) {
|
|
1045
|
-
geom.type = `Multi${geom.type}`;
|
|
1046
|
-
}
|
|
1047
|
-
const result = {
|
|
1048
|
-
type: "Feature",
|
|
1049
|
-
geometry: geom,
|
|
1050
|
-
properties: this.properties
|
|
1051
|
-
};
|
|
1046
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1052
1047
|
if (this.id !== null) {
|
|
1053
1048
|
result.id = this.id;
|
|
1054
1049
|
}
|
|
@@ -1107,13 +1102,13 @@
|
|
|
1107
1102
|
pbf.readFields(readLayer2, this, end);
|
|
1108
1103
|
this.length = this._features.length;
|
|
1109
1104
|
}
|
|
1110
|
-
feature(i2,
|
|
1105
|
+
feature(i2, geometryInfo) {
|
|
1111
1106
|
if (i2 < 0 || i2 >= this._features.length) {
|
|
1112
1107
|
throw new Error("feature index out of bounds");
|
|
1113
1108
|
}
|
|
1114
1109
|
this._pbf.pos = this._features[i2];
|
|
1115
1110
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1116
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values,
|
|
1111
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1117
1112
|
}
|
|
1118
1113
|
};
|
|
1119
1114
|
}
|
|
@@ -1142,29 +1137,31 @@
|
|
|
1142
1137
|
}
|
|
1143
1138
|
});
|
|
1144
1139
|
|
|
1145
|
-
// src/lib/
|
|
1146
|
-
function
|
|
1147
|
-
|
|
1148
|
-
|
|
1140
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1141
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1142
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1143
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1144
|
+
return fillArrays(features, {
|
|
1145
|
+
propArrayTypes,
|
|
1146
|
+
...geometryInfo
|
|
1147
|
+
}, {
|
|
1148
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1149
1149
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1150
1150
|
});
|
|
1151
1151
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const
|
|
1152
|
+
function extractNumericPropTypes(features) {
|
|
1153
|
+
const propArrayTypes = {};
|
|
1154
1154
|
for (const feature of features) {
|
|
1155
1155
|
if (feature.properties) {
|
|
1156
1156
|
for (const key in feature.properties) {
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1159
|
-
const val = feature.properties[key];
|
|
1160
|
-
numericPropKeys[key] = isNumeric(val);
|
|
1161
|
-
}
|
|
1157
|
+
const val = feature.properties[key];
|
|
1158
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1162
1159
|
}
|
|
1163
1160
|
}
|
|
1164
1161
|
}
|
|
1165
|
-
return
|
|
1162
|
+
return propArrayTypes;
|
|
1166
1163
|
}
|
|
1167
|
-
function fillArrays(features,
|
|
1164
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1168
1165
|
const {
|
|
1169
1166
|
pointPositionsCount,
|
|
1170
1167
|
pointFeaturesCount,
|
|
@@ -1174,13 +1171,15 @@
|
|
|
1174
1171
|
polygonPositionsCount,
|
|
1175
1172
|
polygonObjectsCount,
|
|
1176
1173
|
polygonRingsCount,
|
|
1177
|
-
polygonFeaturesCount
|
|
1178
|
-
|
|
1179
|
-
|
|
1174
|
+
polygonFeaturesCount,
|
|
1175
|
+
propArrayTypes,
|
|
1176
|
+
coordLength
|
|
1177
|
+
} = geometryInfo;
|
|
1178
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1180
1179
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
1181
|
-
const coordLength = 2;
|
|
1182
1180
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1183
1181
|
const points = {
|
|
1182
|
+
type: "Point",
|
|
1184
1183
|
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1185
1184
|
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1186
1185
|
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
@@ -1189,6 +1188,7 @@
|
|
|
1189
1188
|
fields: []
|
|
1190
1189
|
};
|
|
1191
1190
|
const lines = {
|
|
1191
|
+
type: "LineString",
|
|
1192
1192
|
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1193
1193
|
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1194
1194
|
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
@@ -1198,6 +1198,7 @@
|
|
|
1198
1198
|
fields: []
|
|
1199
1199
|
};
|
|
1200
1200
|
const polygons = {
|
|
1201
|
+
type: "Polygon",
|
|
1201
1202
|
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1202
1203
|
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1203
1204
|
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
@@ -1210,7 +1211,8 @@
|
|
|
1210
1211
|
};
|
|
1211
1212
|
for (const object of [points, lines, polygons]) {
|
|
1212
1213
|
for (const propName of numericPropKeys) {
|
|
1213
|
-
|
|
1214
|
+
const T = propArrayTypes[propName];
|
|
1215
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1214
1216
|
}
|
|
1215
1217
|
}
|
|
1216
1218
|
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
@@ -1233,7 +1235,6 @@
|
|
|
1233
1235
|
const properties = feature.properties || {};
|
|
1234
1236
|
switch (geometry.type) {
|
|
1235
1237
|
case "Point":
|
|
1236
|
-
case "MultiPoint":
|
|
1237
1238
|
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1238
1239
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1239
1240
|
if (hasGlobalId) {
|
|
@@ -1242,7 +1243,6 @@
|
|
|
1242
1243
|
indexMap.pointFeature++;
|
|
1243
1244
|
break;
|
|
1244
1245
|
case "LineString":
|
|
1245
|
-
case "MultiLineString":
|
|
1246
1246
|
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1247
1247
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1248
1248
|
if (hasGlobalId) {
|
|
@@ -1251,7 +1251,6 @@
|
|
|
1251
1251
|
indexMap.lineFeature++;
|
|
1252
1252
|
break;
|
|
1253
1253
|
case "Polygon":
|
|
1254
|
-
case "MultiPolygon":
|
|
1255
1254
|
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1256
1255
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1257
1256
|
if (hasGlobalId) {
|
|
@@ -1280,9 +1279,9 @@
|
|
|
1280
1279
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1281
1280
|
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1282
1281
|
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1283
|
-
for (let i2 = 0, il = geometry.
|
|
1284
|
-
const start = geometry.
|
|
1285
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.
|
|
1282
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1283
|
+
const start = geometry.indices[i2];
|
|
1284
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1286
1285
|
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1287
1286
|
indexMap.linePosition += (end - start) / coordLength;
|
|
1288
1287
|
}
|
|
@@ -1293,23 +1292,23 @@
|
|
|
1293
1292
|
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1294
1293
|
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1295
1294
|
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1296
|
-
for (let l = 0, ll = geometry.
|
|
1295
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1297
1296
|
const startPosition = indexMap.polygonPosition;
|
|
1298
1297
|
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1299
1298
|
const areas = geometry.areas[l];
|
|
1300
|
-
const
|
|
1301
|
-
const
|
|
1302
|
-
for (let i2 = 0, il =
|
|
1303
|
-
const start =
|
|
1304
|
-
const end = i2 === il - 1 ?
|
|
1299
|
+
const indices = geometry.indices[l];
|
|
1300
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1301
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1302
|
+
const start = indices[i2];
|
|
1303
|
+
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
1305
1304
|
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1306
1305
|
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1307
1306
|
}
|
|
1308
1307
|
const endPosition = indexMap.polygonPosition;
|
|
1309
|
-
triangulatePolygon(polygons, areas,
|
|
1308
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1310
1309
|
}
|
|
1311
1310
|
}
|
|
1312
|
-
function triangulatePolygon(polygons, areas,
|
|
1311
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1313
1312
|
startPosition,
|
|
1314
1313
|
endPosition,
|
|
1315
1314
|
coordLength
|
|
@@ -1317,52 +1316,54 @@
|
|
|
1317
1316
|
const start = startPosition * coordLength;
|
|
1318
1317
|
const end = endPosition * coordLength;
|
|
1319
1318
|
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1320
|
-
const offset =
|
|
1321
|
-
const holes =
|
|
1322
|
-
const
|
|
1323
|
-
for (let t = 0, tl =
|
|
1324
|
-
polygons.triangles.push(startPosition +
|
|
1319
|
+
const offset = indices[0];
|
|
1320
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1321
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1322
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1323
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1325
1324
|
}
|
|
1326
1325
|
}
|
|
1326
|
+
function wrapProps(obj, size) {
|
|
1327
|
+
const returnObj = {};
|
|
1328
|
+
for (const key in obj) {
|
|
1329
|
+
returnObj[key] = { value: obj[key], size };
|
|
1330
|
+
}
|
|
1331
|
+
return returnObj;
|
|
1332
|
+
}
|
|
1327
1333
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1328
|
-
|
|
1334
|
+
return {
|
|
1329
1335
|
points: {
|
|
1330
1336
|
...points,
|
|
1331
1337
|
positions: { value: points.positions, size: coordLength },
|
|
1332
1338
|
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1333
|
-
featureIds: { value: points.featureIds, size: 1 }
|
|
1339
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
1340
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1334
1341
|
},
|
|
1335
1342
|
lines: {
|
|
1336
1343
|
...lines,
|
|
1337
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1338
1344
|
positions: { value: lines.positions, size: coordLength },
|
|
1345
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1339
1346
|
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1340
|
-
featureIds: { value: lines.featureIds, size: 1 }
|
|
1347
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
1348
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1341
1349
|
},
|
|
1342
1350
|
polygons: {
|
|
1343
1351
|
...polygons,
|
|
1352
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1344
1353
|
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1345
1354
|
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1346
|
-
positions: { value: polygons.positions, size: coordLength },
|
|
1347
1355
|
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1348
1356
|
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1349
|
-
featureIds: { value: polygons.featureIds, size: 1 }
|
|
1357
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1358
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1350
1359
|
}
|
|
1351
1360
|
};
|
|
1352
|
-
for (const geomType in returnObj) {
|
|
1353
|
-
for (const numericProp in returnObj[geomType].numericProps) {
|
|
1354
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
1355
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
1356
|
-
size: 1
|
|
1357
|
-
};
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
return returnObj;
|
|
1361
1361
|
}
|
|
1362
1362
|
function fillNumericProperties(object, properties, index, length2) {
|
|
1363
1363
|
for (const numericPropName in object.numericProps) {
|
|
1364
1364
|
if (numericPropName in properties) {
|
|
1365
|
-
|
|
1365
|
+
const value = properties[numericPropName];
|
|
1366
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1366
1367
|
}
|
|
1367
1368
|
}
|
|
1368
1369
|
}
|
|
@@ -1375,15 +1376,25 @@
|
|
|
1375
1376
|
}
|
|
1376
1377
|
return props;
|
|
1377
1378
|
}
|
|
1378
|
-
function
|
|
1379
|
-
|
|
1379
|
+
function deduceArrayType(x2, constructor) {
|
|
1380
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1381
|
+
return Array;
|
|
1382
|
+
}
|
|
1383
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1380
1384
|
}
|
|
1381
|
-
var
|
|
1382
|
-
"src/lib/
|
|
1385
|
+
var init_flat_geojson_to_binary = __esm({
|
|
1386
|
+
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
1383
1387
|
init_esm();
|
|
1384
1388
|
}
|
|
1385
1389
|
});
|
|
1386
1390
|
|
|
1391
|
+
// ../gis/src/index.ts
|
|
1392
|
+
var init_src = __esm({
|
|
1393
|
+
"../gis/src/index.ts"() {
|
|
1394
|
+
init_flat_geojson_to_binary();
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1387
1398
|
// ../../node_modules/ieee754/index.js
|
|
1388
1399
|
var require_ieee754 = __commonJS({
|
|
1389
1400
|
"../../node_modules/ieee754/index.js"(exports) {
|
|
@@ -2126,7 +2137,8 @@
|
|
|
2126
2137
|
const features = [];
|
|
2127
2138
|
if (options) {
|
|
2128
2139
|
const binary = options.gis.format === "binary";
|
|
2129
|
-
const
|
|
2140
|
+
const geometryInfo = {
|
|
2141
|
+
coordLength: 2,
|
|
2130
2142
|
pointPositionsCount: 0,
|
|
2131
2143
|
pointFeaturesCount: 0,
|
|
2132
2144
|
linePositionsCount: 0,
|
|
@@ -2148,14 +2160,14 @@
|
|
|
2148
2160
|
return;
|
|
2149
2161
|
}
|
|
2150
2162
|
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2151
|
-
const vectorTileFeature = vectorTileLayer.feature(i2,
|
|
2163
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2152
2164
|
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2153
2165
|
features.push(decodedFeature);
|
|
2154
2166
|
}
|
|
2155
2167
|
});
|
|
2156
2168
|
}
|
|
2157
2169
|
if (binary) {
|
|
2158
|
-
const data =
|
|
2170
|
+
const data = flatGeojsonToBinary(features, geometryInfo);
|
|
2159
2171
|
data.byteLength = arrayBuffer.byteLength;
|
|
2160
2172
|
return data;
|
|
2161
2173
|
}
|
|
@@ -2187,7 +2199,7 @@
|
|
|
2187
2199
|
}
|
|
2188
2200
|
function getDecodedFeatureBinary(feature, options) {
|
|
2189
2201
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2190
|
-
if (options.layerProperty) {
|
|
2202
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
2191
2203
|
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
2192
2204
|
}
|
|
2193
2205
|
return decodedFeature;
|
|
@@ -2211,7 +2223,7 @@
|
|
|
2211
2223
|
"src/lib/parse-mvt.ts"() {
|
|
2212
2224
|
init_vector_tile();
|
|
2213
2225
|
init_vector_tile2();
|
|
2214
|
-
|
|
2226
|
+
init_src();
|
|
2215
2227
|
import_pbf = __toModule(require_pbf());
|
|
2216
2228
|
}
|
|
2217
2229
|
});
|
|
@@ -2258,7 +2270,7 @@
|
|
|
2258
2270
|
MVTLoader: () => MVTLoader,
|
|
2259
2271
|
MVTWorkerLoader: () => MVTWorkerLoader
|
|
2260
2272
|
});
|
|
2261
|
-
var
|
|
2273
|
+
var init_src2 = __esm({
|
|
2262
2274
|
"src/index.ts"() {
|
|
2263
2275
|
init_mvt_loader();
|
|
2264
2276
|
}
|
|
@@ -2267,7 +2279,7 @@
|
|
|
2267
2279
|
// src/bundle.ts
|
|
2268
2280
|
var require_bundle = __commonJS({
|
|
2269
2281
|
"src/bundle.ts"(exports, module) {
|
|
2270
|
-
var moduleExports = (
|
|
2282
|
+
var moduleExports = (init_src2(), src_exports);
|
|
2271
2283
|
globalThis.loaders = globalThis.loaders || {};
|
|
2272
2284
|
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
2273
2285
|
}
|
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,IAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -11,32 +11,34 @@ exports.readTag = readTag;
|
|
|
11
11
|
var _polygon = require("@math.gl/polygon");
|
|
12
12
|
|
|
13
13
|
function classifyRings(geom) {
|
|
14
|
-
|
|
14
|
+
var len = geom.indices.length;
|
|
15
|
+
var type = 'Polygon';
|
|
15
16
|
|
|
16
17
|
if (len <= 1) {
|
|
17
18
|
return {
|
|
19
|
+
type: type,
|
|
18
20
|
data: geom.data,
|
|
19
21
|
areas: [[(0, _polygon.getPolygonSignedArea)(geom.data)]],
|
|
20
|
-
|
|
22
|
+
indices: [geom.indices]
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
var areas = [];
|
|
27
|
+
var polygons = [];
|
|
28
|
+
var ringAreas = [];
|
|
29
|
+
var polygon = [];
|
|
30
|
+
var ccw;
|
|
31
|
+
var offset = 0;
|
|
30
32
|
|
|
31
|
-
for (
|
|
32
|
-
startIndex = geom.
|
|
33
|
-
endIndex = geom.
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
for (var endIndex, i = 0, startIndex; i < len; i++) {
|
|
34
|
+
startIndex = geom.indices[i] - offset;
|
|
35
|
+
endIndex = geom.indices[i + 1] - offset || geom.data.length;
|
|
36
|
+
var shape = geom.data.slice(startIndex, endIndex);
|
|
37
|
+
var area = (0, _polygon.getPolygonSignedArea)(shape);
|
|
36
38
|
|
|
37
39
|
if (area === 0) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
var before = geom.data.slice(0, startIndex);
|
|
41
|
+
var after = geom.data.slice(endIndex);
|
|
40
42
|
geom.data = before.concat(after);
|
|
41
43
|
offset += endIndex - startIndex;
|
|
42
44
|
continue;
|
|
@@ -61,16 +63,17 @@ function classifyRings(geom) {
|
|
|
61
63
|
if (ringAreas) areas.push(ringAreas);
|
|
62
64
|
if (polygon.length) polygons.push(polygon);
|
|
63
65
|
return {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
type: type,
|
|
67
|
+
areas: areas,
|
|
68
|
+
indices: polygons,
|
|
66
69
|
data: geom.data
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
function project(data, x0, y0, size) {
|
|
71
|
-
for (
|
|
74
|
+
for (var j = 0, jl = data.length; j < jl; j += 2) {
|
|
72
75
|
data[j] = (data[j] + x0) * 360 / size - 180;
|
|
73
|
-
|
|
76
|
+
var y2 = 180 - (data[j + 1] + y0) * 360 / size;
|
|
74
77
|
data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -82,12 +85,12 @@ function readFeature(tag, feature, pbf) {
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
function readTag(pbf, feature) {
|
|
85
|
-
|
|
88
|
+
var end = pbf.readVarint() + pbf.pos;
|
|
86
89
|
|
|
87
90
|
while (pbf.pos < end) {
|
|
88
|
-
|
|
91
|
+
var key = feature._keys[pbf.readVarint()];
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
var value = feature._values[pbf.readVarint()];
|
|
91
94
|
|
|
92
95
|
feature.properties[key] = value;
|
|
93
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/binary-util-functions.ts"],"names":["classifyRings","geom","len","
|
|
1
|
+
{"version":3,"sources":["../../../src/helpers/binary-util-functions.ts"],"names":["classifyRings","geom","len","indices","length","type","data","areas","polygons","ringAreas","polygon","ccw","offset","endIndex","i","startIndex","shape","slice","area","before","after","concat","undefined","push","project","x0","y0","size","j","jl","y2","Math","PI","atan","exp","readFeature","tag","feature","pbf","id","readVarint","readTag","_geometry","pos","end","key","_keys","value","_values","properties"],"mappings":"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","sourcesContent":["import Protobuf from 'pbf';\nimport {getPolygonSignedArea} from '@math.gl/polygon';\nimport {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';\nimport VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';\n\n/**\n * Classifies an array of rings into polygons with outer rings and holes\n * The function also detects holes which have zero area and\n * removes them. In doing so it modifies the input\n * `geom.data` array to remove the unneeded data\n *\n * @param geometry\n * @returns object\n */\n// eslint-disable-next-line max-statements\nexport function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {\n const len = geom.indices.length;\n const type = 'Polygon';\n\n if (len <= 1) {\n return {\n type,\n data: geom.data,\n areas: [[getPolygonSignedArea(geom.data)]],\n indices: [geom.indices]\n };\n }\n\n const areas: any[] = [];\n const polygons: any[] = [];\n let ringAreas: number[] = [];\n let polygon: number[] = [];\n let ccw: boolean | undefined;\n let offset = 0;\n\n for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {\n startIndex = geom.indices[i] - offset;\n\n endIndex = geom.indices[i + 1] - offset || geom.data.length;\n const shape = geom.data.slice(startIndex, endIndex);\n const area = getPolygonSignedArea(shape);\n\n if (area === 0) {\n // This polygon has no area, so remove it from the shape\n // Remove the section from the data array\n const before = geom.data.slice(0, startIndex);\n const after = geom.data.slice(endIndex);\n geom.data = before.concat(after);\n\n // Need to offset any remaining indices as we have\n // modified the data buffer\n offset += endIndex - startIndex;\n\n // Do not add this index to the output and process next shape\n continue; // eslint-disable-line no-continue\n }\n\n if (ccw === undefined) ccw = area < 0;\n\n if (ccw === area < 0) {\n if (polygon.length) {\n areas.push(ringAreas);\n polygons.push(polygon);\n }\n polygon = [startIndex];\n ringAreas = [area];\n } else {\n ringAreas.push(area);\n polygon.push(startIndex);\n }\n }\n if (ringAreas) areas.push(ringAreas);\n if (polygon.length) polygons.push(polygon);\n\n return {type, areas, indices: polygons, data: geom.data};\n}\n\n/**\n *\n * @param data\n * @param x0\n * @param y0\n * @param size\n */\nexport function project(data: number[], x0: number, y0: number, size: number): void {\n for (let j = 0, jl = data.length; j < jl; j += 2) {\n data[j] = ((data[j] + x0) * 360) / size - 180;\n const y2 = 180 - ((data[j + 1] + y0) * 360) / size;\n data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;\n }\n}\n\n/**\n * All code below is unchanged from the original Mapbox implemenation\n *\n * @param tag\n * @param feature\n * @param pbf\n */\nexport function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void {\n if (feature && pbf) {\n if (tag === 1) feature.id = pbf.readVarint();\n else if (tag === 2) readTag(pbf, feature);\n else if (tag === 3) feature.type = pbf.readVarint();\n else if (tag === 4) feature._geometry = pbf.pos;\n }\n}\n\n/**\n * @param pbf\n * @param feature\n */\nexport function readTag(pbf: Protobuf, feature: VectorTileFeature): void {\n const end = pbf.readVarint() + pbf.pos;\n\n while (pbf.pos < end) {\n const key = feature._keys[pbf.readVarint()];\n const value = feature._values[pbf.readVarint()];\n feature.properties[key] = value;\n }\n}\n"],"file":"binary-util-functions.js"}
|