@loaders.gl/mvt 3.1.0 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/bundle.js +5 -2281
  2. package/dist/dist.min.js +2289 -0
  3. package/dist/es5/helpers/binary-util-functions.js +8 -5
  4. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  5. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +33 -31
  6. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  7. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  8. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  9. package/dist/es5/lib/parse-mvt.js +6 -5
  10. package/dist/es5/lib/parse-mvt.js.map +1 -1
  11. package/dist/es5/mvt-loader.js +1 -1
  12. package/dist/esm/helpers/binary-util-functions.js +8 -5
  13. package/dist/esm/helpers/binary-util-functions.js.map +1 -1
  14. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  15. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  16. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  17. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  18. package/dist/esm/lib/parse-mvt.js +6 -5
  19. package/dist/esm/lib/parse-mvt.js.map +1 -1
  20. package/dist/esm/mvt-loader.js +1 -1
  21. package/dist/helpers/binary-util-functions.d.ts +2 -6
  22. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  23. package/dist/helpers/binary-util-functions.js +7 -5
  24. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
  25. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  26. package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
  27. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
  28. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  29. package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
  30. package/dist/lib/parse-mvt.d.ts +8 -76
  31. package/dist/lib/parse-mvt.d.ts.map +1 -1
  32. package/dist/lib/parse-mvt.js +6 -5
  33. package/dist/lib/types.d.ts +0 -68
  34. package/dist/lib/types.d.ts.map +1 -1
  35. package/dist/mvt-worker.js +90 -89
  36. package/package.json +7 -6
  37. package/src/helpers/binary-util-functions.ts +9 -7
  38. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  39. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  40. package/src/lib/parse-mvt.ts +10 -8
  41. package/src/lib/types.ts +0 -75
  42. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -389
  43. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  44. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -331
  45. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  46. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -177
  47. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
  48. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -358
  49. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -527
@@ -1525,12 +1525,14 @@
1525
1525
 
1526
1526
  // src/helpers/binary-util-functions.ts
1527
1527
  function classifyRings2(geom) {
1528
- const len = geom.lines.length;
1528
+ const len = geom.indices.length;
1529
+ const type = "Polygon";
1529
1530
  if (len <= 1) {
1530
1531
  return {
1532
+ type,
1531
1533
  data: geom.data,
1532
1534
  areas: [[getPolygonSignedArea(geom.data)]],
1533
- lines: [geom.lines]
1535
+ indices: [geom.indices]
1534
1536
  };
1535
1537
  }
1536
1538
  const areas = [];
@@ -1540,8 +1542,8 @@
1540
1542
  let ccw;
1541
1543
  let offset = 0;
1542
1544
  for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
1543
- startIndex = geom.lines[i2] - offset;
1544
- endIndex = geom.lines[i2 + 1] - offset || geom.data.length;
1545
+ startIndex = geom.indices[i2] - offset;
1546
+ endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
1545
1547
  const shape = geom.data.slice(startIndex, endIndex);
1546
1548
  const area2 = getPolygonSignedArea(shape);
1547
1549
  if (area2 === 0) {
@@ -1569,7 +1571,7 @@
1569
1571
  areas.push(ringAreas);
1570
1572
  if (polygon.length)
1571
1573
  polygons.push(polygon);
1572
- return { areas, lines: polygons, data: geom.data };
1574
+ return { type, areas, indices: polygons, data: geom.data };
1573
1575
  }
1574
1576
  function project(data, x0, y0, size) {
1575
1577
  for (let j = 0, jl = data.length; j < jl; j += 2) {
@@ -1608,10 +1610,7 @@
1608
1610
  var y;
1609
1611
  var i;
1610
1612
  var VectorTileFeature2 = class {
1611
- static get types() {
1612
- return ["Unknown", "Point", "LineString", "Polygon"];
1613
- }
1614
- constructor(pbf, end, extent, keys, values, firstPassData) {
1613
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
1615
1614
  this.properties = {};
1616
1615
  this.extent = extent;
1617
1616
  this.type = 0;
@@ -1620,7 +1619,7 @@
1620
1619
  this._geometry = -1;
1621
1620
  this._keys = keys;
1622
1621
  this._values = values;
1623
- this._firstPassData = firstPassData;
1622
+ this._geometryInfo = geometryInfo;
1624
1623
  pbf.readFields(readFeature2, this, end);
1625
1624
  }
1626
1625
  loadGeometry() {
@@ -1632,7 +1631,7 @@
1632
1631
  x = 0;
1633
1632
  y = 0;
1634
1633
  i = 0;
1635
- const lines = [];
1634
+ const indices = [];
1636
1635
  const data = [];
1637
1636
  while (pbf.pos < endPos) {
1638
1637
  if (length <= 0) {
@@ -1645,13 +1644,13 @@
1645
1644
  x += pbf.readSVarint();
1646
1645
  y += pbf.readSVarint();
1647
1646
  if (cmd === 1) {
1648
- lines.push(i);
1647
+ indices.push(i);
1649
1648
  }
1650
1649
  data.push(x, y);
1651
1650
  i += 2;
1652
1651
  } else if (cmd === 7) {
1653
1652
  if (i > 0) {
1654
- const start = lines[lines.length - 1];
1653
+ const start = indices[indices.length - 1];
1655
1654
  data.push(data[start], data[start + 1]);
1656
1655
  i += 2;
1657
1656
  }
@@ -1659,42 +1658,38 @@
1659
1658
  throw new Error(`unknown command ${cmd}`);
1660
1659
  }
1661
1660
  }
1662
- return { data, lines };
1661
+ return { data, indices };
1663
1662
  }
1664
1663
  _toBinaryCoordinates(transform) {
1665
- let geom = this.loadGeometry();
1664
+ const geom = this.loadGeometry();
1665
+ let geometry;
1666
1666
  transform(geom.data, this);
1667
1667
  const coordLength = 2;
1668
1668
  switch (this.type) {
1669
1669
  case 1:
1670
- this._firstPassData.pointFeaturesCount++;
1671
- this._firstPassData.pointPositionsCount += geom.lines.length;
1670
+ this._geometryInfo.pointFeaturesCount++;
1671
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
1672
+ geometry = { type: "Point", ...geom };
1672
1673
  break;
1673
1674
  case 2:
1674
- this._firstPassData.lineFeaturesCount++;
1675
- this._firstPassData.linePathsCount += geom.lines.length;
1676
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
1675
+ this._geometryInfo.lineFeaturesCount++;
1676
+ this._geometryInfo.linePathsCount += geom.indices.length;
1677
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
1678
+ geometry = { type: "LineString", ...geom };
1677
1679
  break;
1678
1680
  case 3:
1679
- const classified = classifyRings2(geom);
1680
- this._firstPassData.polygonFeaturesCount++;
1681
- this._firstPassData.polygonObjectsCount += classified.lines.length;
1682
- for (const lines of classified.lines) {
1683
- this._firstPassData.polygonRingsCount += lines.length;
1681
+ geometry = classifyRings2(geom);
1682
+ this._geometryInfo.polygonFeaturesCount++;
1683
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
1684
+ for (const indices of geometry.indices) {
1685
+ this._geometryInfo.polygonRingsCount += indices.length;
1684
1686
  }
1685
- this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
1686
- geom = classified;
1687
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
1687
1688
  break;
1689
+ default:
1690
+ throw new Error(`Invalid geometry type: ${this.type}`);
1688
1691
  }
1689
- geom.type = VectorTileFeature2.types[this.type];
1690
- if (geom.lines.length > 1) {
1691
- geom.type = `Multi${geom.type}`;
1692
- }
1693
- const result = {
1694
- type: "Feature",
1695
- geometry: geom,
1696
- properties: this.properties
1697
- };
1692
+ const result = { type: "Feature", geometry, properties: this.properties };
1698
1693
  if (this.id !== null) {
1699
1694
  result.id = this.id;
1700
1695
  }
@@ -1722,13 +1717,13 @@
1722
1717
  pbf.readFields(readLayer2, this, end);
1723
1718
  this.length = this._features.length;
1724
1719
  }
1725
- feature(i2, firstPassData) {
1720
+ feature(i2, geometryInfo) {
1726
1721
  if (i2 < 0 || i2 >= this._features.length) {
1727
1722
  throw new Error("feature index out of bounds");
1728
1723
  }
1729
1724
  this._pbf.pos = this._features[i2];
1730
1725
  const end = this._pbf.readVarint() + this._pbf.pos;
1731
- return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
1726
+ return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
1732
1727
  }
1733
1728
  };
1734
1729
  function readLayer2(tag, layer, pbf) {
@@ -1774,13 +1769,15 @@
1774
1769
  }
1775
1770
  }
1776
1771
 
1777
- // src/lib/binary-vector-tile/features-to-binary.ts
1778
- function featuresToBinary(features, firstPassData, options) {
1772
+ // ../gis/src/lib/flat-geojson-to-binary.ts
1773
+ function flatGeojsonToBinary(features, geometryInfo, options) {
1779
1774
  const propArrayTypes = extractNumericPropTypes(features);
1780
1775
  const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1781
- return fillArrays(features, firstPassData, {
1782
- numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
1776
+ return fillArrays(features, {
1783
1777
  propArrayTypes,
1778
+ ...geometryInfo
1779
+ }, {
1780
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1784
1781
  PositionDataType: options ? options.PositionDataType : Float32Array
1785
1782
  });
1786
1783
  }
@@ -1796,7 +1793,7 @@
1796
1793
  }
1797
1794
  return propArrayTypes;
1798
1795
  }
1799
- function fillArrays(features, firstPassData, options) {
1796
+ function fillArrays(features, geometryInfo, options) {
1800
1797
  const {
1801
1798
  pointPositionsCount,
1802
1799
  pointFeaturesCount,
@@ -1806,13 +1803,15 @@
1806
1803
  polygonPositionsCount,
1807
1804
  polygonObjectsCount,
1808
1805
  polygonRingsCount,
1809
- polygonFeaturesCount
1810
- } = firstPassData;
1811
- const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
1806
+ polygonFeaturesCount,
1807
+ propArrayTypes,
1808
+ coordLength
1809
+ } = geometryInfo;
1810
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
1812
1811
  const hasGlobalId = features[0] && "id" in features[0];
1813
- const coordLength = 2;
1814
1812
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1815
1813
  const points = {
1814
+ type: "Point",
1816
1815
  positions: new PositionDataType(pointPositionsCount * coordLength),
1817
1816
  globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
1818
1817
  featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
@@ -1821,6 +1820,7 @@
1821
1820
  fields: []
1822
1821
  };
1823
1822
  const lines = {
1823
+ type: "LineString",
1824
1824
  pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
1825
1825
  positions: new PositionDataType(linePositionsCount * coordLength),
1826
1826
  globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
@@ -1830,6 +1830,7 @@
1830
1830
  fields: []
1831
1831
  };
1832
1832
  const polygons = {
1833
+ type: "Polygon",
1833
1834
  polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
1834
1835
  primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
1835
1836
  positions: new PositionDataType(polygonPositionsCount * coordLength),
@@ -1842,8 +1843,8 @@
1842
1843
  };
1843
1844
  for (const object of [points, lines, polygons]) {
1844
1845
  for (const propName of numericPropKeys) {
1845
- const TypedArray = propArrayTypes[propName];
1846
- object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
1846
+ const T = propArrayTypes[propName];
1847
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
1847
1848
  }
1848
1849
  }
1849
1850
  lines.pathIndices[linePathsCount] = linePositionsCount;
@@ -1866,7 +1867,6 @@
1866
1867
  const properties = feature.properties || {};
1867
1868
  switch (geometry.type) {
1868
1869
  case "Point":
1869
- case "MultiPoint":
1870
1870
  handlePoint(geometry, points, indexMap, coordLength, properties);
1871
1871
  points.properties.push(keepStringProperties(properties, numericPropKeys));
1872
1872
  if (hasGlobalId) {
@@ -1875,7 +1875,6 @@
1875
1875
  indexMap.pointFeature++;
1876
1876
  break;
1877
1877
  case "LineString":
1878
- case "MultiLineString":
1879
1878
  handleLineString(geometry, lines, indexMap, coordLength, properties);
1880
1879
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
1881
1880
  if (hasGlobalId) {
@@ -1884,7 +1883,6 @@
1884
1883
  indexMap.lineFeature++;
1885
1884
  break;
1886
1885
  case "Polygon":
1887
- case "MultiPolygon":
1888
1886
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1889
1887
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1890
1888
  if (hasGlobalId) {
@@ -1913,9 +1911,9 @@
1913
1911
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1914
1912
  lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
1915
1913
  lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
1916
- for (let i2 = 0, il = geometry.lines.length; i2 < il; ++i2) {
1917
- const start = geometry.lines[i2];
1918
- const end = i2 === il - 1 ? geometry.data.length : geometry.lines[i2 + 1];
1914
+ for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
1915
+ const start = geometry.indices[i2];
1916
+ const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
1919
1917
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1920
1918
  indexMap.linePosition += (end - start) / coordLength;
1921
1919
  }
@@ -1926,23 +1924,23 @@
1926
1924
  fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1927
1925
  polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1928
1926
  polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1929
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
1927
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
1930
1928
  const startPosition = indexMap.polygonPosition;
1931
1929
  polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
1932
1930
  const areas = geometry.areas[l];
1933
- const lines = geometry.lines[l];
1934
- const nextLines = geometry.lines[l + 1];
1935
- for (let i2 = 0, il = lines.length; i2 < il; ++i2) {
1936
- const start = lines[i2];
1937
- const end = i2 === il - 1 ? nextLines === void 0 ? geometry.data.length : nextLines[0] : lines[i2 + 1];
1931
+ const indices = geometry.indices[l];
1932
+ const nextIndices = geometry.indices[l + 1];
1933
+ for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
1934
+ const start = indices[i2];
1935
+ const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
1938
1936
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1939
1937
  indexMap.polygonPosition += (end - start) / coordLength;
1940
1938
  }
1941
1939
  const endPosition = indexMap.polygonPosition;
1942
- triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength });
1940
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
1943
1941
  }
1944
1942
  }
1945
- function triangulatePolygon(polygons, areas, lines, {
1943
+ function triangulatePolygon(polygons, areas, indices, {
1946
1944
  startPosition,
1947
1945
  endPosition,
1948
1946
  coordLength
@@ -1950,52 +1948,54 @@
1950
1948
  const start = startPosition * coordLength;
1951
1949
  const end = endPosition * coordLength;
1952
1950
  const polygonPositions = polygons.positions.subarray(start, end);
1953
- const offset = lines[0];
1954
- const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
1955
- const indices = earcut(polygonPositions, holes, coordLength, areas);
1956
- for (let t = 0, tl = indices.length; t < tl; ++t) {
1957
- polygons.triangles.push(startPosition + indices[t]);
1951
+ const offset = indices[0];
1952
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
1953
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
1954
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
1955
+ polygons.triangles.push(startPosition + triangles[t]);
1958
1956
  }
1959
1957
  }
1958
+ function wrapProps(obj, size) {
1959
+ const returnObj = {};
1960
+ for (const key in obj) {
1961
+ returnObj[key] = { value: obj[key], size };
1962
+ }
1963
+ return returnObj;
1964
+ }
1960
1965
  function makeAccessorObjects(points, lines, polygons, coordLength) {
1961
- const returnObj = {
1966
+ return {
1962
1967
  points: {
1963
1968
  ...points,
1964
1969
  positions: { value: points.positions, size: coordLength },
1965
1970
  globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
1966
- featureIds: { value: points.featureIds, size: 1 }
1971
+ featureIds: { value: points.featureIds, size: 1 },
1972
+ numericProps: wrapProps(points.numericProps, 1)
1967
1973
  },
1968
1974
  lines: {
1969
1975
  ...lines,
1970
- pathIndices: { value: lines.pathIndices, size: 1 },
1971
1976
  positions: { value: lines.positions, size: coordLength },
1977
+ pathIndices: { value: lines.pathIndices, size: 1 },
1972
1978
  globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
1973
- featureIds: { value: lines.featureIds, size: 1 }
1979
+ featureIds: { value: lines.featureIds, size: 1 },
1980
+ numericProps: wrapProps(lines.numericProps, 1)
1974
1981
  },
1975
1982
  polygons: {
1976
1983
  ...polygons,
1984
+ positions: { value: polygons.positions, size: coordLength },
1977
1985
  polygonIndices: { value: polygons.polygonIndices, size: 1 },
1978
1986
  primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
1979
- positions: { value: polygons.positions, size: coordLength },
1980
1987
  triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
1981
1988
  globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
1982
- featureIds: { value: polygons.featureIds, size: 1 }
1989
+ featureIds: { value: polygons.featureIds, size: 1 },
1990
+ numericProps: wrapProps(polygons.numericProps, 1)
1983
1991
  }
1984
1992
  };
1985
- for (const geomType in returnObj) {
1986
- for (const numericProp in returnObj[geomType].numericProps) {
1987
- returnObj[geomType].numericProps[numericProp] = {
1988
- value: returnObj[geomType].numericProps[numericProp],
1989
- size: 1
1990
- };
1991
- }
1992
- }
1993
- return returnObj;
1994
1993
  }
1995
1994
  function fillNumericProperties(object, properties, index, length2) {
1996
1995
  for (const numericPropName in object.numericProps) {
1997
1996
  if (numericPropName in properties) {
1998
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length2);
1997
+ const value = properties[numericPropName];
1998
+ object.numericProps[numericPropName].fill(value, index, index + length2);
1999
1999
  }
2000
2000
  }
2001
2001
  }
@@ -2022,7 +2022,8 @@
2022
2022
  const features = [];
2023
2023
  if (options) {
2024
2024
  const binary = options.gis.format === "binary";
2025
- const firstPassData = {
2025
+ const geometryInfo = {
2026
+ coordLength: 2,
2026
2027
  pointPositionsCount: 0,
2027
2028
  pointFeaturesCount: 0,
2028
2029
  linePositionsCount: 0,
@@ -2044,14 +2045,14 @@
2044
2045
  return;
2045
2046
  }
2046
2047
  for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2047
- const vectorTileFeature = vectorTileLayer.feature(i2, firstPassData);
2048
+ const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2048
2049
  const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
2049
2050
  features.push(decodedFeature);
2050
2051
  }
2051
2052
  });
2052
2053
  }
2053
2054
  if (binary) {
2054
- const data = featuresToBinary(features, firstPassData);
2055
+ const data = flatGeojsonToBinary(features, geometryInfo);
2055
2056
  data.byteLength = arrayBuffer.byteLength;
2056
2057
  return data;
2057
2058
  }
@@ -2083,7 +2084,7 @@
2083
2084
  }
2084
2085
  function getDecodedFeatureBinary(feature, options) {
2085
2086
  const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
2086
- if (options.layerProperty) {
2087
+ if (options.layerProperty && decodedFeature.properties) {
2087
2088
  decodedFeature.properties[options.layerProperty] = options.layerName;
2088
2089
  }
2089
2090
  return decodedFeature;
@@ -2104,7 +2105,7 @@
2104
2105
  }
2105
2106
 
2106
2107
  // src/mvt-loader.ts
2107
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2108
+ var VERSION = true ? "3.1.4" : "latest";
2108
2109
  var MVTWorkerLoader = {
2109
2110
  name: "Mapbox Vector Tile",
2110
2111
  id: "mvt",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/mvt",
3
3
  "description": "Loader for Mapbox Vector Tiles",
4
- "version": "3.1.0",
4
+ "version": "3.1.4",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -28,17 +28,18 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "pre-build": "npm run build-worker && npm run build-worker --env.dev && npm run build-bundle",
31
- "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
32
- "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js"
31
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
32
+ "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
33
33
  },
34
34
  "dependencies": {
35
- "@loaders.gl/gis": "3.1.0",
36
- "@loaders.gl/loader-utils": "3.1.0",
35
+ "@loaders.gl/gis": "3.1.4",
36
+ "@loaders.gl/loader-utils": "3.1.4",
37
+ "@loaders.gl/schema": "3.1.4",
37
38
  "@math.gl/polygon": "^3.5.1",
38
39
  "pbf": "^3.2.1"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/pbf": "^3.0.2"
42
43
  },
43
- "gitHead": "b02a011b5a6d6aa6c5870819045c70db168cb930"
44
+ "gitHead": "4d27d3ac6023e53b562dcad83b9254b198e81ee5"
44
45
  }
@@ -1,6 +1,6 @@
1
1
  import Protobuf from 'pbf';
2
2
  import {getPolygonSignedArea} from '@math.gl/polygon';
3
- import {MvtBinaryGeometry} from '../lib/types';
3
+ import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
4
4
  import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
5
5
 
6
6
  /**
@@ -13,14 +13,16 @@ import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
13
13
  * @returns object
14
14
  */
15
15
  // eslint-disable-next-line max-statements
16
- export function classifyRings(geom: MvtBinaryGeometry) {
17
- const len = geom.lines.length;
16
+ export function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {
17
+ const len = geom.indices.length;
18
+ const type = 'Polygon';
18
19
 
19
20
  if (len <= 1) {
20
21
  return {
22
+ type,
21
23
  data: geom.data,
22
24
  areas: [[getPolygonSignedArea(geom.data)]],
23
- lines: [geom.lines]
25
+ indices: [geom.indices]
24
26
  };
25
27
  }
26
28
 
@@ -32,9 +34,9 @@ export function classifyRings(geom: MvtBinaryGeometry) {
32
34
  let offset = 0;
33
35
 
34
36
  for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {
35
- startIndex = geom.lines[i] - offset;
37
+ startIndex = geom.indices[i] - offset;
36
38
 
37
- endIndex = geom.lines[i + 1] - offset || geom.data.length;
39
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
38
40
  const shape = geom.data.slice(startIndex, endIndex);
39
41
  const area = getPolygonSignedArea(shape);
40
42
 
@@ -70,7 +72,7 @@ export function classifyRings(geom: MvtBinaryGeometry) {
70
72
  if (ringAreas) areas.push(ringAreas);
71
73
  if (polygon.length) polygons.push(polygon);
72
74
 
73
- return {areas, lines: polygons, data: geom.data};
75
+ return {type, areas, indices: polygons, data: geom.data};
74
76
  }
75
77
 
76
78
  /**