@loaders.gl/mvt 4.3.2 → 4.4.0-alpha.2

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 (51) hide show
  1. package/dist/dist.dev.js +151 -93
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +74 -78
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -1
  8. package/dist/lib/parse-mvt.d.ts.map +1 -1
  9. package/dist/lib/pojo-parser/mvt-constants.d.ts +116 -0
  10. package/dist/lib/pojo-parser/mvt-constants.d.ts.map +1 -0
  11. package/dist/lib/pojo-parser/mvt-constants.js +126 -0
  12. package/dist/lib/pojo-parser/mvt-types.d.ts +17 -0
  13. package/dist/lib/pojo-parser/mvt-types.d.ts.map +1 -0
  14. package/dist/lib/pojo-parser/mvt-types.js +4 -0
  15. package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts +77 -0
  16. package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts.map +1 -0
  17. package/dist/lib/pojo-parser/parse-geometry-from-pbf.js +234 -0
  18. package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts +25 -0
  19. package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts.map +1 -0
  20. package/dist/lib/pojo-parser/parse-mvt-from-pbf.js +262 -0
  21. package/dist/lib/vector-tile/vector-tile-feature.d.ts +2 -1
  22. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
  23. package/dist/lib/vector-tile/vector-tile-layer.d.ts +1 -1
  24. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -1
  25. package/dist/mvt-format.d.ts +12 -0
  26. package/dist/mvt-format.d.ts.map +1 -0
  27. package/dist/mvt-format.js +20 -0
  28. package/dist/mvt-loader.d.ts +12 -12
  29. package/dist/mvt-loader.d.ts.map +1 -1
  30. package/dist/mvt-loader.js +3 -13
  31. package/dist/mvt-source.d.ts +22 -24
  32. package/dist/mvt-source.d.ts.map +1 -1
  33. package/dist/mvt-source.js +14 -23
  34. package/dist/mvt-worker.js +20 -15
  35. package/dist/table-tile-source.d.ts +38 -38
  36. package/dist/table-tile-source.d.ts.map +1 -1
  37. package/dist/table-tile-source.js +54 -53
  38. package/dist/tilejson-loader.js +1 -1
  39. package/package.json +7 -7
  40. package/src/index.ts +2 -2
  41. package/src/lib/parse-mvt.ts +2 -8
  42. package/src/lib/pojo-parser/mvt-constants.ts +135 -0
  43. package/src/lib/pojo-parser/mvt-types.ts +22 -0
  44. package/src/lib/pojo-parser/parse-geometry-from-pbf.ts +285 -0
  45. package/src/lib/pojo-parser/parse-mvt-from-pbf.ts +310 -0
  46. package/src/lib/vector-tile/vector-tile-feature.ts +2 -6
  47. package/src/lib/vector-tile/vector-tile-layer.ts +1 -1
  48. package/src/mvt-format.ts +23 -0
  49. package/src/mvt-loader.ts +2 -13
  50. package/src/mvt-source.ts +33 -38
  51. package/src/table-tile-source.ts +116 -96
package/dist/index.cjs CHANGED
@@ -302,7 +302,7 @@ function attributeTypeToFieldType(aType) {
302
302
  }
303
303
 
304
304
  // dist/tilejson-loader.js
305
- var VERSION = true ? "4.3.1" : "latest";
305
+ var VERSION = true ? "4.4.0-alpha.1" : "latest";
306
306
  var TileJSONLoader = {
307
307
  dataType: null,
308
308
  batchType: null,
@@ -979,15 +979,11 @@ function getDecodedFeatureBinary(feature, options, layerName) {
979
979
  return decodedFeature;
980
980
  }
981
981
 
982
- // dist/mvt-loader.js
983
- var VERSION2 = true ? "4.3.1" : "latest";
984
- var MVTWorkerLoader = {
985
- dataType: null,
986
- batchType: null,
982
+ // dist/mvt-format.js
983
+ var MVTFormat = {
987
984
  name: "Mapbox Vector Tile",
988
985
  id: "mvt",
989
986
  module: "mvt",
990
- version: VERSION2,
991
987
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
992
988
  extensions: ["mvt", "pbf"],
993
989
  mimeTypes: [
@@ -996,8 +992,17 @@ var MVTWorkerLoader = {
996
992
  "application/x-protobuf"
997
993
  // 'application/octet-stream'
998
994
  ],
995
+ category: "geometry"
996
+ };
997
+
998
+ // dist/mvt-loader.js
999
+ var VERSION2 = true ? "4.4.0-alpha.1" : "latest";
1000
+ var MVTWorkerLoader = {
1001
+ ...MVTFormat,
1002
+ dataType: null,
1003
+ batchType: null,
1004
+ version: VERSION2,
999
1005
  worker: true,
1000
- category: "geometry",
1001
1006
  options: {
1002
1007
  mvt: {
1003
1008
  shape: "geojson",
@@ -1020,42 +1025,32 @@ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1020
1025
  var import_images = require("@loaders.gl/images");
1021
1026
  var import_mvt = require("@loaders.gl/mvt");
1022
1027
  var MVTSource = {
1023
- name: "MVT",
1024
- id: "mvt",
1025
- module: "mvt",
1028
+ ...MVTFormat,
1026
1029
  version: "0.0.0",
1027
- extensions: ["mvt"],
1028
- mimeTypes: ["application/octet-stream"],
1029
- options: {
1030
+ type: "mvt",
1031
+ fromUrl: true,
1032
+ fromBlob: false,
1033
+ defaultOptions: {
1030
1034
  mvt: {
1031
1035
  // TODO - add options here
1032
1036
  }
1033
1037
  },
1034
- type: "mvt",
1035
- fromUrl: true,
1036
- fromBlob: false,
1037
1038
  testURL: (url) => true,
1038
- createDataSource(url, props) {
1039
- return new MVTTileSource(url, props);
1039
+ createDataSource(url, options) {
1040
+ return new MVTTileSource(url, options);
1040
1041
  }
1041
1042
  };
1042
1043
  var MVTTileSource = class extends import_loader_utils2.DataSource {
1043
- props;
1044
- url;
1045
1044
  metadataUrl = null;
1046
- data;
1047
1045
  schema = "tms";
1048
1046
  metadata;
1049
1047
  extension;
1050
1048
  mimeType = null;
1051
- constructor(url, props) {
1049
+ constructor(url, options) {
1052
1050
  var _a, _b;
1053
- super(props);
1054
- this.props = props;
1055
- this.url = (0, import_loader_utils2.resolvePath)(url);
1056
- this.metadataUrl = ((_a = props.mvt) == null ? void 0 : _a.metadataUrl) || `${this.url}/tilejson.json`;
1057
- this.extension = ((_b = props.mvt) == null ? void 0 : _b.extension) || ".png";
1058
- this.data = this.url;
1051
+ super(url, options, MVTSource.defaultOptions);
1052
+ this.metadataUrl = ((_a = options.mvt) == null ? void 0 : _a.metadataUrl) || `${this.url}/tilejson.json`;
1053
+ this.extension = ((_b = options.mvt) == null ? void 0 : _b.extension) || ".png";
1059
1054
  this.getTileData = this.getTileData.bind(this);
1060
1055
  this.metadata = this.getMetadata();
1061
1056
  if (isURLTemplate(this.url)) {
@@ -1181,7 +1176,7 @@ function stringHash(s) {
1181
1176
 
1182
1177
  // dist/table-tile-source.js
1183
1178
  var import_loader_utils3 = require("@loaders.gl/loader-utils");
1184
- var import_schema = require("@loaders.gl/schema");
1179
+ var import_schema_utils = require("@loaders.gl/schema-utils");
1185
1180
  var import_stats = require("@probe.gl/stats");
1186
1181
 
1187
1182
  // dist/lib/vector-tiler/proto-tile.js
@@ -1870,10 +1865,14 @@ function shiftCoords(points, offset) {
1870
1865
  var TableTileSource = {
1871
1866
  name: "TableTiler",
1872
1867
  id: "table-tiler",
1868
+ module: "mvt",
1873
1869
  version: "0.0.0",
1874
1870
  extensions: ["mvt"],
1875
1871
  mimeTypes: ["application/octet-stream"],
1876
- options: {
1872
+ type: "table",
1873
+ fromUrl: false,
1874
+ fromBlob: false,
1875
+ defaultOptions: {
1877
1876
  table: {
1878
1877
  coordinates: "local",
1879
1878
  promoteId: void 0,
@@ -1886,28 +1885,17 @@ var TableTileSource = {
1886
1885
  generateId: void 0
1887
1886
  }
1888
1887
  },
1889
- type: "table",
1890
1888
  testURL: (url) => url.endsWith(".geojson"),
1891
1889
  createDataSource(url, options) {
1892
1890
  var _a, _b;
1893
1891
  const needsLoading = typeof url === "string" || url instanceof Blob;
1894
- const loader = (_b = (_a = options == null ? void 0 : options.table) == null ? void 0 : _a.loaders) == null ? void 0 : _b[0];
1892
+ const loader = (_b = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.loaders) == null ? void 0 : _b[0];
1895
1893
  const tablePromise = needsLoading ? loadTable(url, loader) : url;
1896
- return new DynamicVectorTileSource(tablePromise, options);
1894
+ return new TableVectorTileSource(tablePromise, options);
1897
1895
  }
1898
- // @ts-expect-error
1899
1896
  };
1900
- async function loadTable(url, loader) {
1901
- if (typeof url === "string") {
1902
- const response = await fetch(url);
1903
- const data2 = await response.arrayBuffer();
1904
- return await loader.parse(data2);
1905
- }
1906
- const data = await url.arrayBuffer();
1907
- return await loader.parse(data);
1908
- }
1909
- var _DynamicVectorTileSource = class {
1910
- /** Stats for this DynamicVectorTileSource */
1897
+ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
1898
+ /** Stats for this TableVectorTileSource */
1911
1899
  stats = new import_stats.Stats({
1912
1900
  id: "table-tile-source",
1913
1901
  stats: [new import_stats.Stat("tiles", "count"), new import_stats.Stat("features", "count")]
@@ -1915,9 +1903,7 @@ var _DynamicVectorTileSource = class {
1915
1903
  /** MIME type of the tiles emitted by this tile source */
1916
1904
  mimeType = "application/vnd.mapbox-vector-tile";
1917
1905
  localCoordinates = true;
1918
- /** The props that this tile source was created with */
1919
- // @ts-expect-error
1920
- props;
1906
+ tableOptions;
1921
1907
  /* Schema of the data */
1922
1908
  schema = null;
1923
1909
  /** Map of generated tiles, indexed by stringified tile coordinates */
@@ -1928,20 +1914,21 @@ var _DynamicVectorTileSource = class {
1928
1914
  ready;
1929
1915
  /** Metadata for the tile source (generated TileJSON/tilestats */
1930
1916
  metadata;
1931
- constructor(table, props) {
1932
- this.props = { ...TableTileSource.options.table, ...props == null ? void 0 : props.table };
1917
+ constructor(table, options) {
1918
+ super(table, options, TableTileSource.defaultOptions);
1919
+ this.tableOptions = (0, import_loader_utils3.getRequiredOptions)(this.options).table;
1933
1920
  this.getTileData = this.getTileData.bind(this);
1934
1921
  this.ready = this.initializeTilesAsync(table);
1935
1922
  this.metadata = this.getMetadata();
1936
1923
  }
1937
1924
  async initializeTilesAsync(tablePromise) {
1938
1925
  const table = await tablePromise;
1939
- this.schema = (0, import_schema.deduceTableSchema)(table);
1926
+ this.schema = (0, import_schema_utils.deduceTableSchema)(table);
1940
1927
  this.createRootTiles(table);
1941
1928
  }
1942
1929
  async getMetadata() {
1943
1930
  await this.ready;
1944
- return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
1931
+ return { schema: this.schema, minZoom: 0, maxZoom: this.tableOptions.maxZoom };
1945
1932
  }
1946
1933
  async getSchema() {
1947
1934
  await this.ready;
@@ -1978,9 +1965,9 @@ var _DynamicVectorTileSource = class {
1978
1965
  return null;
1979
1966
  }
1980
1967
  return convertTileToGeoJSON(protoTile, {
1981
- coordinates: this.props.coordinates,
1968
+ coordinates: this.tableOptions.coordinates,
1982
1969
  tileIndex,
1983
- extent: this.props.extent
1970
+ extent: this.tableOptions.extent
1984
1971
  });
1985
1972
  }
1986
1973
  /**
@@ -1988,27 +1975,27 @@ var _DynamicVectorTileSource = class {
1988
1975
  * @note the tiles stores all the features together with additional data
1989
1976
  */
1990
1977
  createRootTiles(table) {
1991
- if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
1978
+ if (this.tableOptions.maxZoom < 0 || this.tableOptions.maxZoom > 24) {
1992
1979
  throw new Error("maxZoom should be in the 0-24 range");
1993
1980
  }
1994
- if (this.props.promoteId && this.props.generateId) {
1981
+ if (this.tableOptions.promoteId && this.tableOptions.generateId) {
1995
1982
  throw new Error("promoteId and generateId cannot be used together.");
1996
1983
  }
1997
- import_loader_utils3.log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
1984
+ import_loader_utils3.log.log(1, "TableVectorTileSource creating root tiles", this.tableOptions)();
1998
1985
  import_loader_utils3.log.time(1, "preprocess table")();
1999
- let features2 = convertFeaturesToProtoFeature(table, this.props);
1986
+ let features2 = convertFeaturesToProtoFeature(table, this.tableOptions);
2000
1987
  import_loader_utils3.log.timeEnd(1, "preprocess table")();
2001
1988
  import_loader_utils3.log.time(1, "generate tiles")();
2002
- features2 = wrapFeatures(features2, this.props);
1989
+ features2 = wrapFeatures(features2, this.tableOptions);
2003
1990
  if (features2.length === 0) {
2004
- import_loader_utils3.log.log(1, "DynamicVectorTileSource: no features generated")();
1991
+ import_loader_utils3.log.log(1, "TableVectorTileSource: no features generated")();
2005
1992
  return;
2006
1993
  }
2007
1994
  this.splitTile(features2, 0, 0, 0);
2008
1995
  const rootTile = this.tiles[0];
2009
1996
  import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
2010
1997
  import_loader_utils3.log.timeEnd(1, "generate tiles")();
2011
- import_loader_utils3.log.log(1, `DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
1998
+ import_loader_utils3.log.log(1, `TableVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
2012
1999
  }
2013
2000
  /**
2014
2001
  * Return geojsonvt-style "half formed" vector tile
@@ -2018,7 +2005,7 @@ var _DynamicVectorTileSource = class {
2018
2005
  getProtoTile(tileIndex) {
2019
2006
  const { z, y } = tileIndex;
2020
2007
  let { x } = tileIndex;
2021
- const { extent } = this.props;
2008
+ const { extent } = this.tableOptions;
2022
2009
  if (z < 0 || z > 24) {
2023
2010
  return null;
2024
2011
  }
@@ -2054,7 +2041,7 @@ var _DynamicVectorTileSource = class {
2054
2041
  * @param cz, cx, and cy are the coordinates of the target tile
2055
2042
  *
2056
2043
  * If no target tile is specified, splitting stops when we reach the maximum
2057
- * zoom or the number of points is low as specified in the props.
2044
+ * zoom or the number of points is low as specified in the options.
2058
2045
  */
2059
2046
  // eslint-disable-next-line max-params, max-statements, complexity
2060
2047
  splitTile(features2, z, x, y, cz, cx, cy) {
@@ -2069,26 +2056,26 @@ var _DynamicVectorTileSource = class {
2069
2056
  let tile = this.tiles[id];
2070
2057
  if (!tile) {
2071
2058
  import_loader_utils3.log.time(2, "tile creation")();
2072
- tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
2059
+ tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.tableOptions);
2073
2060
  this.tileCoords.push({ z, x, y });
2074
2061
  const key = `z${z}`;
2075
2062
  let stat = this.stats.get(key, "count");
2076
2063
  stat.incrementCount();
2077
2064
  stat = this.stats.get("total");
2078
2065
  stat.incrementCount();
2079
- stat = _DynamicVectorTileSource.stats.get(key, "count");
2066
+ stat = _TableVectorTileSource.stats.get(key, "count");
2080
2067
  stat.incrementCount();
2081
- stat = _DynamicVectorTileSource.stats.get("total");
2068
+ stat = _TableVectorTileSource.stats.get("total");
2082
2069
  stat.incrementCount();
2083
2070
  import_loader_utils3.log.log(2, "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
2084
2071
  import_loader_utils3.log.timeEnd(2, "tile creation")();
2085
2072
  }
2086
2073
  tile.sourceFeatures = features2;
2087
2074
  if (cz === void 0) {
2088
- if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
2075
+ if (z === this.tableOptions.indexMaxZoom || tile.numPoints <= this.tableOptions.maxPointsPerTile) {
2089
2076
  continue;
2090
2077
  }
2091
- } else if (z === this.props.maxZoom || z === cz) {
2078
+ } else if (z === this.tableOptions.maxZoom || z === cz) {
2092
2079
  continue;
2093
2080
  } else if (cz !== void 0) {
2094
2081
  const zoomSteps = cz - z;
@@ -2100,7 +2087,7 @@ var _DynamicVectorTileSource = class {
2100
2087
  if (features2.length === 0)
2101
2088
  continue;
2102
2089
  import_loader_utils3.log.time(2, "clipping tile")();
2103
- const k1 = 0.5 * this.props.buffer / this.props.extent;
2090
+ const k1 = 0.5 * this.tableOptions.buffer / this.tableOptions.extent;
2104
2091
  const k2 = 0.5 - k1;
2105
2092
  const k3 = 0.5 + k1;
2106
2093
  const k4 = 1 + k1;
@@ -2108,17 +2095,17 @@ var _DynamicVectorTileSource = class {
2108
2095
  let bl = null;
2109
2096
  let tr = null;
2110
2097
  let br = null;
2111
- let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
2112
- let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
2098
+ let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.tableOptions);
2099
+ let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.tableOptions);
2113
2100
  features2 = null;
2114
2101
  if (left) {
2115
- tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2116
- bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
2102
+ tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.tableOptions);
2103
+ bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.tableOptions);
2117
2104
  left = null;
2118
2105
  }
2119
2106
  if (right) {
2120
- tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2121
- br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
2107
+ tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.tableOptions);
2108
+ br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.tableOptions);
2122
2109
  right = null;
2123
2110
  }
2124
2111
  import_loader_utils3.log.timeEnd(2, "clipping tile")();
@@ -2129,13 +2116,22 @@ var _DynamicVectorTileSource = class {
2129
2116
  }
2130
2117
  }
2131
2118
  };
2132
- var DynamicVectorTileSource = _DynamicVectorTileSource;
2119
+ var TableVectorTileSource = _TableVectorTileSource;
2133
2120
  /** Global stats for all DynamicVectorTileSources */
2134
- __publicField(DynamicVectorTileSource, "stats", new import_stats.Stats({
2121
+ __publicField(TableVectorTileSource, "stats", new import_stats.Stats({
2135
2122
  id: "table-tile-source-all",
2136
2123
  stats: [new import_stats.Stat("count", "tiles"), new import_stats.Stat("count", "features")]
2137
2124
  }));
2138
2125
  function toID(z, x, y) {
2139
2126
  return ((1 << z) * y + x) * 32 + z;
2140
2127
  }
2128
+ async function loadTable(url, loader) {
2129
+ if (typeof url === "string") {
2130
+ const response = await fetch(url);
2131
+ const data2 = await response.arrayBuffer();
2132
+ return await loader.parse(data2);
2133
+ }
2134
+ const data = await url.arrayBuffer();
2135
+ return await loader.parse(data);
2136
+ }
2141
2137
  //# sourceMappingURL=index.cjs.map