@loaders.gl/mvt 4.2.0 → 4.3.0-alpha.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 (108) hide show
  1. package/dist/dist.dev.js +1311 -767
  2. package/dist/dist.min.js +1 -1
  3. package/dist/geojson-tile-source.d.ts +79 -0
  4. package/dist/geojson-tile-source.d.ts.map +1 -0
  5. package/dist/{lib/geojson-tiler/geojson-tiler.js → geojson-tile-source.js} +137 -27
  6. package/dist/index.cjs +570 -560
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/lib/geojsonvt/clip.d.ts.map +1 -0
  12. package/dist/lib/geojsonvt/convert.d.ts +10 -0
  13. package/dist/lib/geojsonvt/convert.d.ts.map +1 -0
  14. package/dist/lib/geojsonvt/feature.d.ts.map +1 -0
  15. package/dist/lib/geojsonvt/simplify.d.ts.map +1 -0
  16. package/dist/lib/geojsonvt/tile.d.ts.map +1 -0
  17. package/dist/lib/geojsonvt/transform.d.ts.map +1 -0
  18. package/dist/lib/geojsonvt/wrap.d.ts.map +1 -0
  19. package/dist/lib/parse-mvt.d.ts +3 -2
  20. package/dist/lib/parse-mvt.d.ts.map +1 -1
  21. package/dist/lib/parse-mvt.js +13 -15
  22. package/dist/lib/types.d.ts +1 -39
  23. package/dist/lib/types.d.ts.map +1 -1
  24. package/dist/lib/utils/geometry-utils.d.ts +46 -0
  25. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  26. package/dist/{helpers/binary-util-functions.js → lib/utils/geometry-utils.js} +79 -46
  27. package/dist/lib/{binary-vector-tile → vector-tile}/vector-tile-feature.d.ts +27 -15
  28. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  29. package/dist/lib/vector-tile/vector-tile-feature.js +345 -0
  30. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  31. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  32. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  33. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  34. package/dist/mvt-loader.d.ts +20 -9
  35. package/dist/mvt-loader.d.ts.map +1 -1
  36. package/dist/mvt-loader.js +3 -2
  37. package/dist/mvt-source.js +4 -4
  38. package/dist/mvt-worker.js +1172 -735
  39. package/dist/tilejson-loader.js +1 -1
  40. package/package.json +6 -6
  41. package/src/{lib/geojson-tiler/geojson-tiler.ts → geojson-tile-source.ts} +172 -33
  42. package/src/index.ts +3 -3
  43. package/src/lib/{geojson-tiler → geojsonvt}/convert.ts +2 -2
  44. package/src/lib/{geojson-tiler → geojsonvt}/tile.ts +2 -2
  45. package/src/lib/parse-mvt.ts +24 -33
  46. package/src/lib/types.ts +1 -39
  47. package/src/{helpers/binary-util-functions.ts → lib/utils/geometry-utils.ts} +92 -48
  48. package/src/lib/vector-tile/vector-tile-feature.ts +407 -0
  49. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  50. package/src/mvt-loader.ts +14 -6
  51. package/src/mvt-source.ts +4 -4
  52. package/dist/helpers/binary-util-functions.d.ts +0 -35
  53. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  54. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  55. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  56. package/dist/helpers/mapbox-util-functions.js +0 -78
  57. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  58. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  59. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  60. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  61. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  62. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  63. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  64. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  65. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  66. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  67. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  68. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  69. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  70. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  71. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  72. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  73. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  74. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  75. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  76. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  77. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  78. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  79. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  80. package/src/helpers/mapbox-util-functions.ts +0 -82
  81. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  82. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  83. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  84. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  85. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  86. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.d.ts +0 -0
  87. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.js +0 -0
  88. /package/dist/lib/{geojson-tiler → geojsonvt}/convert.js +0 -0
  89. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.d.ts +0 -0
  90. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.js +0 -0
  91. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.d.ts +0 -0
  92. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.js +0 -0
  93. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.d.ts +0 -0
  94. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.js +0 -0
  95. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.d.ts +0 -0
  96. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.js +0 -0
  97. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.d.ts +0 -0
  98. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.js +0 -0
  99. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  100. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  101. /package/src/lib/{geojson-tiler → geojsonvt}/LICENSE +0 -0
  102. /package/src/lib/{geojson-tiler → geojsonvt}/clip.ts +0 -0
  103. /package/src/lib/{geojson-tiler → geojsonvt}/feature.ts +0 -0
  104. /package/src/lib/{geojson-tiler → geojsonvt}/simplify.ts +0 -0
  105. /package/src/lib/{geojson-tiler → geojsonvt}/transform.ts +0 -0
  106. /package/src/lib/{geojson-tiler → geojsonvt}/wrap.ts +0 -0
  107. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  108. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ export type { TileJSON } from "./lib/parse-tilejson.js";
4
4
  export type { TileJSONLoaderOptions } from "./tilejson-loader.js";
5
5
  export { TileJSONLoader } from "./tilejson-loader.js";
6
6
  export { MVTSource } from "./mvt-source.js";
7
- export type { GeoJSONTilerOptions } from "./lib/geojson-tiler/geojson-tiler.js";
8
- export { GeoJSONTiler } from "./lib/geojson-tiler/geojson-tiler.js";
7
+ export type { GeoJSONTileSourceOptions } from "./geojson-tile-source.js";
8
+ export { GeoJSONTileSource } from "./geojson-tile-source.js";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AACnD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AAExD,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AACnD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,OAAO,EAAC,cAAc,EAAC,6BAA0B;AAEjD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AAIvC,YAAY,EAAC,mBAAmB,EAAC,6CAA0C;AAC3E,OAAO,EAAC,YAAY,EAAC,6CAA0C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AACnD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AAExD,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AACnD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,OAAO,EAAC,cAAc,EAAC,6BAA0B;AAEjD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AAIvC,YAAY,EAAC,wBAAwB,EAAC,iCAA8B;AACpE,OAAO,EAAC,iBAAiB,EAAC,iCAA8B"}
package/dist/index.js CHANGED
@@ -4,4 +4,4 @@
4
4
  export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
5
5
  export { TileJSONLoader } from "./tilejson-loader.js";
6
6
  export { MVTSource } from "./mvt-source.js";
7
- export { GeoJSONTiler } from "./lib/geojson-tiler/geojson-tiler.js";
7
+ export { GeoJSONTileSource } from "./geojson-tile-source.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAK/C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,kBAAkB,EAAE,GAAG,IAAI,CA4E7B"}
@@ -0,0 +1,10 @@
1
+ import type { Feature, FeatureCollection } from '@loaders.gl/schema';
2
+ import type { GeoJSONTileFeature } from "./tile.js";
3
+ export declare function convert(data: Feature | FeatureCollection, options: any): GeoJSONTileFeature[];
4
+ export type ConvertFeatureOptions = {
5
+ maxZoom?: number;
6
+ tolerance: number;
7
+ extent: number;
8
+ lineMetrics: boolean;
9
+ };
10
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcxF;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,kBAAe;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/simplify.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAkCjG"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAqB9F"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,kBAAe;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}
@@ -1,4 +1,5 @@
1
- import type { Feature, BinaryFeatureCollection, GeoJSONTable } from '@loaders.gl/schema';
1
+ import type { Feature } from '@loaders.gl/schema';
2
+ import type { GeoJSONTable, BinaryFeatureCollection } from '@loaders.gl/schema';
2
3
  import type { MVTLoaderOptions } from "../mvt-loader.js";
3
4
  /**
4
5
  * Parse MVT arrayBuffer and return GeoJSON.
@@ -7,7 +8,7 @@ import type { MVTLoaderOptions } from "../mvt-loader.js";
7
8
  * @param options
8
9
  * @returns A GeoJSON geometry object or a binary representation
9
10
  */
10
- export declare function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions): BinaryFeatureCollection | GeoJSONTable | Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>[] | {
11
+ export declare function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions): GeoJSONTable | Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>[] | BinaryFeatureCollection | {
11
12
  shape: string;
12
13
  data: BinaryFeatureCollection;
13
14
  };
@@ -1 +1 @@
1
- {"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,OAAO,EAEP,uBAAuB,EACvB,YAAY,EACb,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAC,gBAAgB,EAAC,yBAAsB;AAOpD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB;;;EAyB5E"}
1
+ {"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,OAAO,EAAsB,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAC,YAAY,EAAE,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AAQ9E,OAAO,KAAK,EAAC,gBAAgB,EAAC,yBAAsB;AAGpD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB;;;EAyB5E"}
@@ -2,9 +2,9 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright vis.gl contributors
4
4
  import { flatGeojsonToBinary } from '@loaders.gl/gis';
5
+ import { log } from '@loaders.gl/loader-utils';
5
6
  import Protobuf from 'pbf';
6
- import { VectorTile } from "./mapbox-vector-tile/vector-tile.js";
7
- import { BinaryVectorTile } from "./binary-vector-tile/vector-tile.js";
7
+ import { VectorTile } from "./vector-tile/vector-tile.js";
8
8
  /**
9
9
  * Parse MVT arrayBuffer and return GeoJSON.
10
10
  *
@@ -13,7 +13,7 @@ import { BinaryVectorTile } from "./binary-vector-tile/vector-tile.js";
13
13
  * @returns A GeoJSON geometry object or a binary representation
14
14
  */
15
15
  export function parseMVT(arrayBuffer, options) {
16
- const mvtOptions = normalizeOptions(options);
16
+ const mvtOptions = checkOptions(options);
17
17
  const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
18
18
  switch (shape) {
19
19
  case 'columnar-table': // binary + some JS arrays
@@ -62,7 +62,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
62
62
  if (arrayBuffer.byteLength <= 0) {
63
63
  return [features, geometryInfo];
64
64
  }
65
- const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));
65
+ const tile = new VectorTile(new Protobuf(arrayBuffer));
66
66
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
67
67
  selectedLayers.forEach((layerName) => {
68
68
  const vectorTileLayer = tile.layers[layerName];
@@ -70,7 +70,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
70
70
  return;
71
71
  }
72
72
  for (let i = 0; i < vectorTileLayer.length; i++) {
73
- const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
73
+ const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
74
74
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
75
75
  features.push(decodedFeature);
76
76
  }
@@ -90,27 +90,24 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
90
90
  return;
91
91
  }
92
92
  for (let i = 0; i < vectorTileLayer.length; i++) {
93
- const vectorTileFeature = vectorTileLayer.feature(i);
93
+ const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
94
94
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
95
95
  features.push(decodedFeature);
96
96
  }
97
97
  });
98
98
  return features;
99
99
  }
100
- function normalizeOptions(options) {
100
+ /** Check that options are good */
101
+ function checkOptions(options) {
101
102
  if (!options?.mvt) {
102
103
  throw new Error('mvt options required');
103
104
  }
104
- // Validate
105
- const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';
106
- const { tileIndex } = options.mvt;
107
- const hasTileIndex = tileIndex &&
108
- Number.isFinite(tileIndex.x) &&
109
- Number.isFinite(tileIndex.y) &&
110
- Number.isFinite(tileIndex.z);
111
- if (wgs84Coordinates && !hasTileIndex) {
105
+ if (options.mvt?.coordinates === 'wgs84' && !options.mvt.tileIndex) {
112
106
  throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');
113
107
  }
108
+ if (options.gis) {
109
+ log.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();
110
+ }
114
111
  return options.mvt;
115
112
  }
116
113
  /**
@@ -124,6 +121,7 @@ function getDecodedFeature(feature, options, layerName) {
124
121
  options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
125
122
  // Add layer name to GeoJSON properties
126
123
  if (options.layerProperty) {
124
+ decodedFeature.properties ||= {};
127
125
  decodedFeature.properties[options.layerProperty] = layerName;
128
126
  }
129
127
  return decodedFeature;
@@ -1,41 +1,4 @@
1
- /** For local coordinates, the tileIndex is not required */
2
- type MVTLocalCoordinatesOptions = {
3
- /**
4
- * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
5
- */
6
- coordinates: 'local';
7
- tileIndex: null;
8
- };
9
- /** In WGS84 coordinates, the tileIndex is required */
10
- type MVTWgs84CoordinatesOptions = {
11
- /**
12
- * When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.
13
- */
14
- coordinates?: 'wgs84';
15
- /**
16
- * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,
17
- * `z`) to reproject features' coordinates into WGS84.
18
- */
19
- tileIndex?: {
20
- x: number;
21
- y: number;
22
- z: number;
23
- };
24
- };
25
- export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
26
- shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
27
- /**
28
- * When non-`null`, the layer name of each feature is added to
29
- * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature
30
- * has no existing properties). If set to `null`, a layer name property will not be added.
31
- */
32
- layerProperty?: string | number;
33
- /**
34
- * Optional list of layer names. If not `null`, only features belonging to the named layers will
35
- * be included in the output. If `null`, features from all layers are returned.
36
- */
37
- layers?: string[];
38
- };
1
+ /** TODO where is this used? */
39
2
  export type MVTMapboxGeometry = {
40
3
  type?: string;
41
4
  id?: number;
@@ -53,5 +16,4 @@ export type MVTMapboxCoordinates = {
53
16
  };
54
17
  id?: number;
55
18
  };
56
- export {};
57
19
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAIA,2DAA2D;AAC3D,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,sDAAsD;AACtD,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,UAAU,GAA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AE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { FlatIndexedGeometry, FlatPolygon } from '@loaders.gl/schema';
2
+ /**
3
+ *
4
+ * @param ring
5
+ * @returns sum
6
+ */
7
+ export declare function signedArea(ring: number[][]): number;
8
+ /**
9
+ * Projects local tile coordinates to lngLat in place.
10
+ * @param points
11
+ * @param tileIndex
12
+ */
13
+ export declare function projectTileCoordinatesToLngLat(points: number[][], tileIndex: {
14
+ x: number;
15
+ y: number;
16
+ z: number;
17
+ }, extent: number): void;
18
+ /**
19
+ *
20
+ * @param data
21
+ * @param x0
22
+ * @param y0
23
+ * @param size
24
+ */
25
+ export declare function projectToLngLatFlat(data: number[], tileIndex: {
26
+ x: number;
27
+ y: number;
28
+ z: number;
29
+ }, extent: number): void;
30
+ /**
31
+ * Classifies an array of rings into polygons with outer rings and holes
32
+ * @param rings
33
+ * @returns polygons
34
+ */
35
+ export declare function classifyRings(rings: number[][][]): number[][][][];
36
+ /**
37
+ * Classifies an array of rings into polygons with outer rings and holes
38
+ * The function also detects holes which have zero area and
39
+ * removes them. In doing so it modifies the input
40
+ * `geom.data` array to remove the unneeded data
41
+ *
42
+ * @param geometry
43
+ * @returns object
44
+ */
45
+ export declare function classifyRingsFlat(geom: FlatIndexedGeometry): FlatPolygon;
46
+ //# sourceMappingURL=geometry-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/geometry-utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAQ1C;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,SAAS,EAAE;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5C,MAAM,EAAE,MAAM,QAYf;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,EAAE;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5C,MAAM,EAAE,MAAM,GACb,IAAI,CAWN;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,CAuBjE;AAED;;;;;;;;GAQG;AAEH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,GAAG,WAAW,CA4DxE"}
@@ -2,6 +2,84 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright vis.gl contributors
4
4
  import { getPolygonSignedArea } from '@math.gl/polygon';
5
+ /**
6
+ *
7
+ * @param ring
8
+ * @returns sum
9
+ */
10
+ export function signedArea(ring) {
11
+ let sum = 0;
12
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
13
+ p1 = ring[i];
14
+ p2 = ring[j];
15
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
16
+ }
17
+ return sum;
18
+ }
19
+ /**
20
+ * Projects local tile coordinates to lngLat in place.
21
+ * @param points
22
+ * @param tileIndex
23
+ */
24
+ export function projectTileCoordinatesToLngLat(points, tileIndex, extent) {
25
+ const { x, y, z } = tileIndex;
26
+ const size = extent * Math.pow(2, z);
27
+ const x0 = extent * x;
28
+ const y0 = extent * y;
29
+ for (const p of points) {
30
+ p[0] = ((p[0] + x0) * 360) / size - 180;
31
+ const y2 = 180 - ((p[1] + y0) * 360) / size;
32
+ p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
33
+ }
34
+ }
35
+ /**
36
+ *
37
+ * @param data
38
+ * @param x0
39
+ * @param y0
40
+ * @param size
41
+ */
42
+ export function projectToLngLatFlat(data, tileIndex, extent) {
43
+ const { x, y, z } = tileIndex;
44
+ const size = extent * Math.pow(2, z);
45
+ const x0 = extent * x;
46
+ const y0 = extent * y;
47
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
48
+ data[j] = ((data[j] + x0) * 360) / size - 180;
49
+ const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
50
+ data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
51
+ }
52
+ }
53
+ /**
54
+ * Classifies an array of rings into polygons with outer rings and holes
55
+ * @param rings
56
+ * @returns polygons
57
+ */
58
+ export function classifyRings(rings) {
59
+ const len = rings.length;
60
+ if (len <= 1)
61
+ return [rings];
62
+ const polygons = [];
63
+ let polygon;
64
+ let ccw;
65
+ for (let i = 0; i < len; i++) {
66
+ const area = signedArea(rings[i]);
67
+ if (area === 0)
68
+ continue; // eslint-disable-line no-continue
69
+ if (ccw === undefined)
70
+ ccw = area < 0;
71
+ if (ccw === area < 0) {
72
+ if (polygon)
73
+ polygons.push(polygon);
74
+ polygon = [rings[i]];
75
+ }
76
+ else if (polygon)
77
+ polygon.push(rings[i]);
78
+ }
79
+ if (polygon)
80
+ polygons.push(polygon);
81
+ return polygons;
82
+ }
5
83
  /**
6
84
  * Classifies an array of rings into polygons with outer rings and holes
7
85
  * The function also detects holes which have zero area and
@@ -12,7 +90,7 @@ import { getPolygonSignedArea } from '@math.gl/polygon';
12
90
  * @returns object
13
91
  */
14
92
  // eslint-disable-next-line max-statements
15
- export function classifyRings(geom) {
93
+ export function classifyRingsFlat(geom) {
16
94
  const len = geom.indices.length;
17
95
  const type = 'Polygon';
18
96
  if (len <= 1) {
@@ -67,48 +145,3 @@ export function classifyRings(geom) {
67
145
  polygons.push(polygon);
68
146
  return { type, areas, indices: polygons, data: geom.data };
69
147
  }
70
- /**
71
- *
72
- * @param data
73
- * @param x0
74
- * @param y0
75
- * @param size
76
- */
77
- export function project(data, x0, y0, size) {
78
- for (let j = 0, jl = data.length; j < jl; j += 2) {
79
- data[j] = ((data[j] + x0) * 360) / size - 180;
80
- const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
81
- data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
82
- }
83
- }
84
- /**
85
- * All code below is unchanged from the original Mapbox implemenation
86
- *
87
- * @param tag
88
- * @param feature
89
- * @param pbf
90
- */
91
- export function readFeature(tag, feature, pbf) {
92
- if (feature && pbf) {
93
- if (tag === 1)
94
- feature.id = pbf.readVarint();
95
- else if (tag === 2)
96
- readTag(pbf, feature);
97
- else if (tag === 3)
98
- feature.type = pbf.readVarint();
99
- else if (tag === 4)
100
- feature._geometry = pbf.pos;
101
- }
102
- }
103
- /**
104
- * @param pbf
105
- * @param feature
106
- */
107
- export function readTag(pbf, feature) {
108
- const end = pbf.readVarint() + pbf.pos;
109
- while (pbf.pos < end) {
110
- const key = feature._keys[pbf.readVarint()];
111
- const value = feature._values[pbf.readVarint()];
112
- feature.properties[key] = value;
113
- }
114
- }
@@ -1,10 +1,7 @@
1
- import Protobuf from 'pbf';
1
+ import { Feature } from '@loaders.gl/schema';
2
2
  import { FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo } from '@loaders.gl/schema';
3
- import { classifyRings } from "../../helpers/binary-util-functions.js";
4
- export declare const TEST_EXPORTS: {
5
- classifyRings: typeof classifyRings;
6
- };
7
- export declare class BinaryVectorTileFeature {
3
+ import Protobuf from 'pbf';
4
+ export declare class VectorTileFeature {
8
5
  properties: {
9
6
  [x: string]: string | number | boolean | null;
10
7
  };
@@ -16,8 +13,28 @@ export declare class BinaryVectorTileFeature {
16
13
  _keys: string[];
17
14
  _values: (string | number | boolean | null)[];
18
15
  _geometryInfo: GeojsonGeometryInfo;
19
- constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], geometryInfo: GeojsonGeometryInfo);
20
- loadGeometry(): FlatIndexedGeometry;
16
+ static types: Readonly<string[]>;
17
+ constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], geometryInfo?: GeojsonGeometryInfo);
18
+ toGeoJSON(options: {
19
+ x: number;
20
+ y: number;
21
+ z: number;
22
+ } | ((data: number[], feature: {
23
+ extent: any;
24
+ }) => void)): Feature;
25
+ /**
26
+ *
27
+ * @param options
28
+ * @returns
29
+ */
30
+ toBinaryCoordinates(options: {
31
+ x: number;
32
+ y: number;
33
+ z: number;
34
+ } | ((data: number[], feature: {
35
+ extent: any;
36
+ }) => void)): FlatFeature;
37
+ bbox(): number[];
21
38
  /**
22
39
  *
23
40
  * @param transform
@@ -30,12 +47,7 @@ export declare class BinaryVectorTileFeature {
30
47
  properties: import("geojson").GeoJsonProperties;
31
48
  bbox?: import("geojson").BBox | undefined;
32
49
  };
33
- toBinaryCoordinates(options: {
34
- x: number;
35
- y: number;
36
- z: number;
37
- } | ((data: number[], feature: {
38
- extent: any;
39
- }) => void)): FlatFeature;
50
+ loadGeometry(): number[][][];
51
+ loadFlatGeometry(): FlatIndexedGeometry;
40
52
  }
41
53
  //# sourceMappingURL=vector-tile-feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACzF,OAAO,QAAQ,MAAM,KAAK,CAAC;AAG3B,qBAAa,iBAAiB;IAC5B,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,M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