@loaders.gl/mvt 3.1.0 → 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.
Files changed (48) hide show
  1. package/dist/bundle.js +101 -93
  2. package/dist/es5/helpers/binary-util-functions.js +8 -5
  3. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  4. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +33 -31
  5. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  6. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  7. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  8. package/dist/es5/lib/parse-mvt.js +6 -5
  9. package/dist/es5/lib/parse-mvt.js.map +1 -1
  10. package/dist/es5/mvt-loader.js +1 -1
  11. package/dist/esm/helpers/binary-util-functions.js +8 -5
  12. package/dist/esm/helpers/binary-util-functions.js.map +1 -1
  13. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  14. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  15. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  16. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  17. package/dist/esm/lib/parse-mvt.js +6 -5
  18. package/dist/esm/lib/parse-mvt.js.map +1 -1
  19. package/dist/esm/mvt-loader.js +1 -1
  20. package/dist/helpers/binary-util-functions.d.ts +2 -6
  21. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  22. package/dist/helpers/binary-util-functions.js +7 -5
  23. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
  24. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  25. package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
  26. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
  27. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  28. package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
  29. package/dist/lib/parse-mvt.d.ts +8 -76
  30. package/dist/lib/parse-mvt.d.ts.map +1 -1
  31. package/dist/lib/parse-mvt.js +6 -5
  32. package/dist/lib/types.d.ts +0 -68
  33. package/dist/lib/types.d.ts.map +1 -1
  34. package/dist/mvt-worker.js +89 -88
  35. package/package.json +5 -4
  36. package/src/helpers/binary-util-functions.ts +9 -7
  37. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  38. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  39. package/src/lib/parse-mvt.ts +10 -8
  40. package/src/lib/types.ts +0 -75
  41. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -389
  42. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  43. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -331
  44. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  45. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -177
  46. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
  47. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -358
  48. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -527
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.lines.length;
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
- lines: [geom.lines]
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.lines[i2] - offset;
896
- endIndex = geom.lines[i2 + 1] - offset || geom.data.length;
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, lines: polygons, data: geom.data };
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
- static get types() {
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._firstPassData = firstPassData;
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 lines = [];
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
- lines.push(i);
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 = lines[lines.length - 1];
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, lines };
1015
+ return { data, indices };
1017
1016
  }
1018
1017
  _toBinaryCoordinates(transform) {
1019
- let geom = this.loadGeometry();
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._firstPassData.pointFeaturesCount++;
1025
- this._firstPassData.pointPositionsCount += geom.lines.length;
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._firstPassData.lineFeaturesCount++;
1029
- this._firstPassData.linePathsCount += geom.lines.length;
1030
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
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
- const classified = classifyRings2(geom);
1034
- this._firstPassData.polygonFeaturesCount++;
1035
- this._firstPassData.polygonObjectsCount += classified.lines.length;
1036
- for (const lines of classified.lines) {
1037
- this._firstPassData.polygonRingsCount += lines.length;
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._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
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
- geom.type = VectorTileFeature2.types[this.type];
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, firstPassData) {
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, firstPassData);
1111
+ return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
1117
1112
  }
1118
1113
  };
1119
1114
  }
@@ -1142,13 +1137,15 @@
1142
1137
  }
1143
1138
  });
1144
1139
 
1145
- // src/lib/binary-vector-tile/features-to-binary.ts
1146
- function featuresToBinary(features, firstPassData, options) {
1140
+ // ../gis/src/lib/flat-geojson-to-binary.ts
1141
+ function flatGeojsonToBinary(features, geometryInfo, options) {
1147
1142
  const propArrayTypes = extractNumericPropTypes(features);
1148
1143
  const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1149
- return fillArrays(features, firstPassData, {
1150
- numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
1144
+ return fillArrays(features, {
1151
1145
  propArrayTypes,
1146
+ ...geometryInfo
1147
+ }, {
1148
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1152
1149
  PositionDataType: options ? options.PositionDataType : Float32Array
1153
1150
  });
1154
1151
  }
@@ -1164,7 +1161,7 @@
1164
1161
  }
1165
1162
  return propArrayTypes;
1166
1163
  }
1167
- function fillArrays(features, firstPassData, options) {
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
- } = firstPassData;
1179
- const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
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,8 +1211,8 @@
1210
1211
  };
1211
1212
  for (const object of [points, lines, polygons]) {
1212
1213
  for (const propName of numericPropKeys) {
1213
- const TypedArray = propArrayTypes[propName];
1214
- object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
1214
+ const T = propArrayTypes[propName];
1215
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
1215
1216
  }
1216
1217
  }
1217
1218
  lines.pathIndices[linePathsCount] = linePositionsCount;
@@ -1234,7 +1235,6 @@
1234
1235
  const properties = feature.properties || {};
1235
1236
  switch (geometry.type) {
1236
1237
  case "Point":
1237
- case "MultiPoint":
1238
1238
  handlePoint(geometry, points, indexMap, coordLength, properties);
1239
1239
  points.properties.push(keepStringProperties(properties, numericPropKeys));
1240
1240
  if (hasGlobalId) {
@@ -1243,7 +1243,6 @@
1243
1243
  indexMap.pointFeature++;
1244
1244
  break;
1245
1245
  case "LineString":
1246
- case "MultiLineString":
1247
1246
  handleLineString(geometry, lines, indexMap, coordLength, properties);
1248
1247
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
1249
1248
  if (hasGlobalId) {
@@ -1252,7 +1251,6 @@
1252
1251
  indexMap.lineFeature++;
1253
1252
  break;
1254
1253
  case "Polygon":
1255
- case "MultiPolygon":
1256
1254
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1257
1255
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1258
1256
  if (hasGlobalId) {
@@ -1281,9 +1279,9 @@
1281
1279
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1282
1280
  lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
1283
1281
  lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
1284
- for (let i2 = 0, il = geometry.lines.length; i2 < il; ++i2) {
1285
- const start = geometry.lines[i2];
1286
- const end = i2 === il - 1 ? geometry.data.length : geometry.lines[i2 + 1];
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];
1287
1285
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1288
1286
  indexMap.linePosition += (end - start) / coordLength;
1289
1287
  }
@@ -1294,23 +1292,23 @@
1294
1292
  fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1295
1293
  polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1296
1294
  polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1297
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
1295
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
1298
1296
  const startPosition = indexMap.polygonPosition;
1299
1297
  polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
1300
1298
  const areas = geometry.areas[l];
1301
- const lines = geometry.lines[l];
1302
- const nextLines = geometry.lines[l + 1];
1303
- for (let i2 = 0, il = lines.length; i2 < il; ++i2) {
1304
- const start = lines[i2];
1305
- const end = i2 === il - 1 ? nextLines === void 0 ? geometry.data.length : nextLines[0] : lines[i2 + 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];
1306
1304
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1307
1305
  indexMap.polygonPosition += (end - start) / coordLength;
1308
1306
  }
1309
1307
  const endPosition = indexMap.polygonPosition;
1310
- triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength });
1308
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
1311
1309
  }
1312
1310
  }
1313
- function triangulatePolygon(polygons, areas, lines, {
1311
+ function triangulatePolygon(polygons, areas, indices, {
1314
1312
  startPosition,
1315
1313
  endPosition,
1316
1314
  coordLength
@@ -1318,52 +1316,54 @@
1318
1316
  const start = startPosition * coordLength;
1319
1317
  const end = endPosition * coordLength;
1320
1318
  const polygonPositions = polygons.positions.subarray(start, end);
1321
- const offset = lines[0];
1322
- const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
1323
- const indices = earcut(polygonPositions, holes, coordLength, areas);
1324
- for (let t = 0, tl = indices.length; t < tl; ++t) {
1325
- polygons.triangles.push(startPosition + indices[t]);
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]);
1326
1324
  }
1327
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
+ }
1328
1333
  function makeAccessorObjects(points, lines, polygons, coordLength) {
1329
- const returnObj = {
1334
+ return {
1330
1335
  points: {
1331
1336
  ...points,
1332
1337
  positions: { value: points.positions, size: coordLength },
1333
1338
  globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
1334
- featureIds: { value: points.featureIds, size: 1 }
1339
+ featureIds: { value: points.featureIds, size: 1 },
1340
+ numericProps: wrapProps(points.numericProps, 1)
1335
1341
  },
1336
1342
  lines: {
1337
1343
  ...lines,
1338
- pathIndices: { value: lines.pathIndices, size: 1 },
1339
1344
  positions: { value: lines.positions, size: coordLength },
1345
+ pathIndices: { value: lines.pathIndices, size: 1 },
1340
1346
  globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
1341
- featureIds: { value: lines.featureIds, size: 1 }
1347
+ featureIds: { value: lines.featureIds, size: 1 },
1348
+ numericProps: wrapProps(lines.numericProps, 1)
1342
1349
  },
1343
1350
  polygons: {
1344
1351
  ...polygons,
1352
+ positions: { value: polygons.positions, size: coordLength },
1345
1353
  polygonIndices: { value: polygons.polygonIndices, size: 1 },
1346
1354
  primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
1347
- positions: { value: polygons.positions, size: coordLength },
1348
1355
  triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
1349
1356
  globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
1350
- featureIds: { value: polygons.featureIds, size: 1 }
1357
+ featureIds: { value: polygons.featureIds, size: 1 },
1358
+ numericProps: wrapProps(polygons.numericProps, 1)
1351
1359
  }
1352
1360
  };
1353
- for (const geomType in returnObj) {
1354
- for (const numericProp in returnObj[geomType].numericProps) {
1355
- returnObj[geomType].numericProps[numericProp] = {
1356
- value: returnObj[geomType].numericProps[numericProp],
1357
- size: 1
1358
- };
1359
- }
1360
- }
1361
- return returnObj;
1362
1361
  }
1363
1362
  function fillNumericProperties(object, properties, index, length2) {
1364
1363
  for (const numericPropName in object.numericProps) {
1365
1364
  if (numericPropName in properties) {
1366
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length2);
1365
+ const value = properties[numericPropName];
1366
+ object.numericProps[numericPropName].fill(value, index, index + length2);
1367
1367
  }
1368
1368
  }
1369
1369
  }
@@ -1382,12 +1382,19 @@
1382
1382
  }
1383
1383
  return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
1384
1384
  }
1385
- var init_features_to_binary = __esm({
1386
- "src/lib/binary-vector-tile/features-to-binary.ts"() {
1385
+ var init_flat_geojson_to_binary = __esm({
1386
+ "../gis/src/lib/flat-geojson-to-binary.ts"() {
1387
1387
  init_esm();
1388
1388
  }
1389
1389
  });
1390
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
+
1391
1398
  // ../../node_modules/ieee754/index.js
1392
1399
  var require_ieee754 = __commonJS({
1393
1400
  "../../node_modules/ieee754/index.js"(exports) {
@@ -2130,7 +2137,8 @@
2130
2137
  const features = [];
2131
2138
  if (options) {
2132
2139
  const binary = options.gis.format === "binary";
2133
- const firstPassData = {
2140
+ const geometryInfo = {
2141
+ coordLength: 2,
2134
2142
  pointPositionsCount: 0,
2135
2143
  pointFeaturesCount: 0,
2136
2144
  linePositionsCount: 0,
@@ -2152,14 +2160,14 @@
2152
2160
  return;
2153
2161
  }
2154
2162
  for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2155
- const vectorTileFeature = vectorTileLayer.feature(i2, firstPassData);
2163
+ const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2156
2164
  const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
2157
2165
  features.push(decodedFeature);
2158
2166
  }
2159
2167
  });
2160
2168
  }
2161
2169
  if (binary) {
2162
- const data = featuresToBinary(features, firstPassData);
2170
+ const data = flatGeojsonToBinary(features, geometryInfo);
2163
2171
  data.byteLength = arrayBuffer.byteLength;
2164
2172
  return data;
2165
2173
  }
@@ -2191,7 +2199,7 @@
2191
2199
  }
2192
2200
  function getDecodedFeatureBinary(feature, options) {
2193
2201
  const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
2194
- if (options.layerProperty) {
2202
+ if (options.layerProperty && decodedFeature.properties) {
2195
2203
  decodedFeature.properties[options.layerProperty] = options.layerName;
2196
2204
  }
2197
2205
  return decodedFeature;
@@ -2215,7 +2223,7 @@
2215
2223
  "src/lib/parse-mvt.ts"() {
2216
2224
  init_vector_tile();
2217
2225
  init_vector_tile2();
2218
- init_features_to_binary();
2226
+ init_src();
2219
2227
  import_pbf = __toModule(require_pbf());
2220
2228
  }
2221
2229
  });
@@ -2262,7 +2270,7 @@
2262
2270
  MVTLoader: () => MVTLoader,
2263
2271
  MVTWorkerLoader: () => MVTWorkerLoader
2264
2272
  });
2265
- var init_src = __esm({
2273
+ var init_src2 = __esm({
2266
2274
  "src/index.ts"() {
2267
2275
  init_mvt_loader();
2268
2276
  }
@@ -2271,7 +2279,7 @@
2271
2279
  // src/bundle.ts
2272
2280
  var require_bundle = __commonJS({
2273
2281
  "src/bundle.ts"(exports, module) {
2274
- var moduleExports = (init_src(), src_exports);
2282
+ var moduleExports = (init_src2(), src_exports);
2275
2283
  globalThis.loaders = globalThis.loaders || {};
2276
2284
  module.exports = Object.assign(globalThis.loaders, moduleExports);
2277
2285
  }
@@ -11,13 +11,15 @@ exports.readTag = readTag;
11
11
  var _polygon = require("@math.gl/polygon");
12
12
 
13
13
  function classifyRings(geom) {
14
- var len = geom.lines.length;
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
- lines: [geom.lines]
22
+ indices: [geom.indices]
21
23
  };
22
24
  }
23
25
 
@@ -29,8 +31,8 @@ function classifyRings(geom) {
29
31
  var offset = 0;
30
32
 
31
33
  for (var endIndex, i = 0, startIndex; i < len; i++) {
32
- startIndex = geom.lines[i] - offset;
33
- endIndex = geom.lines[i + 1] - offset || geom.data.length;
34
+ startIndex = geom.indices[i] - offset;
35
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
34
36
  var shape = geom.data.slice(startIndex, endIndex);
35
37
  var area = (0, _polygon.getPolygonSignedArea)(shape);
36
38
 
@@ -61,8 +63,9 @@ function classifyRings(geom) {
61
63
  if (ringAreas) areas.push(ringAreas);
62
64
  if (polygon.length) polygons.push(polygon);
63
65
  return {
66
+ type: type,
64
67
  areas: areas,
65
- lines: polygons,
68
+ indices: polygons,
66
69
  data: geom.data
67
70
  };
68
71
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/helpers/binary-util-functions.ts"],"names":["classifyRings","geom","len","lines","length","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","type","_geometry","pos","end","key","_keys","value","_values","properties"],"mappings":";;;;;;;;;;AACA;;AAcO,SAASA,aAAT,CAAuBC,IAAvB,EAAgD;AACrD,MAAMC,GAAG,GAAGD,IAAI,CAACE,KAAL,CAAWC,MAAvB;;AAEA,MAAIF,GAAG,IAAI,CAAX,EAAc;AACZ,WAAO;AACLG,MAAAA,IAAI,EAAEJ,IAAI,CAACI,IADN;AAELC,MAAAA,KAAK,EAAE,CAAC,CAAC,mCAAqBL,IAAI,CAACI,IAA1B,CAAD,CAAD,CAFF;AAGLF,MAAAA,KAAK,EAAE,CAACF,IAAI,CAACE,KAAN;AAHF,KAAP;AAKD;;AAED,MAAMG,KAAY,GAAG,EAArB;AACA,MAAMC,QAAe,GAAG,EAAxB;AACA,MAAIC,SAAmB,GAAG,EAA1B;AACA,MAAIC,OAAiB,GAAG,EAAxB;AACA,MAAIC,GAAJ;AACA,MAAIC,MAAM,GAAG,CAAb;;AAEA,OAAK,IAAIC,QAAJ,EAAsBC,CAAC,GAAG,CAA1B,EAA6BC,UAAlC,EAAsDD,CAAC,GAAGX,GAA1D,EAA+DW,CAAC,EAAhE,EAAoE;AAClEC,IAAAA,UAAU,GAAGb,IAAI,CAACE,KAAL,CAAWU,CAAX,IAAgBF,MAA7B;AAEAC,IAAAA,QAAQ,GAAGX,IAAI,CAACE,KAAL,CAAWU,CAAC,GAAG,CAAf,IAAoBF,MAApB,IAA8BV,IAAI,CAACI,IAAL,CAAUD,MAAnD;AACA,QAAMW,KAAK,GAAGd,IAAI,CAACI,IAAL,CAAUW,KAAV,CAAgBF,UAAhB,EAA4BF,QAA5B,CAAd;AACA,QAAMK,IAAI,GAAG,mCAAqBF,KAArB,CAAb;;AAEA,QAAIE,IAAI,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B,QAAMC,GAAG,GAAGT,OAAO,CAACU,KAAR,CAAcT,GAAG,CAACE,UAAJ,EAAd,CAAZ;;AACA,QAAMQ,KAAK,GAAGX,OAAO,CAACY,OAAR,CAAgBX,GAAG,CAACE,UAAJ,EAAhB,CAAd;;AACAH,IAAAA,OAAO,CAACa,UAAR,CAAmBJ,GAAnB,IAA0BE,KAA1B;AACD;AACF","sourcesContent":["import Protobuf from 'pbf';\nimport {getPolygonSignedArea} from '@math.gl/polygon';\nimport {MvtBinaryGeometry} from '../lib/types';\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: MvtBinaryGeometry) {\n const len = geom.lines.length;\n\n if (len <= 1) {\n return {\n data: geom.data,\n areas: [[getPolygonSignedArea(geom.data)]],\n lines: [geom.lines]\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.lines[i] - offset;\n\n endIndex = geom.lines[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 {areas, lines: 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"}
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":";;;;;;;;;;AACA;;AAcO,SAASA,aAAT,CAAuBC,IAAvB,EAA+D;AACpE,MAAMC,GAAG,GAAGD,IAAI,CAACE,OAAL,CAAaC,MAAzB;AACA,MAAMC,IAAI,GAAG,S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AACF","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"}