@loaders.gl/mvt 4.0.0-alpha.4 → 4.0.0-alpha.6

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 (198) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +3124 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/helpers/binary-util-functions.js +82 -0
  8. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  9. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  10. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  11. package/dist/es5/index.js +26 -0
  12. package/dist/es5/index.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  17. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  18. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  19. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  20. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  21. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  23. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  25. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  27. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  29. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  31. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  33. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  34. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  35. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  40. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  41. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  42. package/dist/es5/lib/parse-mvt.js +143 -0
  43. package/dist/es5/lib/parse-mvt.js.map +1 -0
  44. package/dist/es5/lib/types.js +2 -0
  45. package/dist/es5/lib/types.js.map +1 -0
  46. package/dist/es5/mvt-loader.js +58 -0
  47. package/dist/es5/mvt-loader.js.map +1 -0
  48. package/dist/es5/workers/mvt-worker.js +6 -0
  49. package/dist/es5/workers/mvt-worker.js.map +1 -0
  50. package/dist/esm/bundle.js +4 -0
  51. package/dist/esm/bundle.js.map +1 -0
  52. package/dist/esm/helpers/binary-util-functions.js +73 -0
  53. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  54. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  55. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  56. package/dist/esm/index.js +3 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  63. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  64. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  65. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  66. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  67. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  69. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  71. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  73. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  75. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  77. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  79. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  80. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  81. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  82. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  87. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  88. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  89. package/dist/esm/lib/parse-mvt.js +138 -0
  90. package/dist/esm/lib/parse-mvt.js.map +1 -0
  91. package/dist/esm/lib/types.js +2 -0
  92. package/dist/esm/lib/types.js.map +1 -0
  93. package/dist/esm/mvt-loader.js +29 -0
  94. package/dist/esm/mvt-loader.js.map +1 -0
  95. package/dist/esm/workers/mvt-worker.js +4 -0
  96. package/dist/esm/workers/mvt-worker.js.map +1 -0
  97. package/dist/helpers/binary-util-functions.d.ts +35 -0
  98. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  99. package/dist/helpers/binary-util-functions.js +111 -74
  100. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  101. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  102. package/dist/helpers/mapbox-util-functions.js +78 -45
  103. package/dist/index.d.ts +4 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +9 -2
  106. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
  107. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  108. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
  109. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  110. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  111. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  112. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  113. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  114. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  115. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  116. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  117. package/dist/lib/geojson-tiler/clip.js +209 -0
  118. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  119. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  120. package/dist/lib/geojson-tiler/convert.js +134 -0
  121. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  122. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  123. package/dist/lib/geojson-tiler/feature.js +46 -0
  124. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  125. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  126. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  127. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  128. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  129. package/dist/lib/geojson-tiler/simplify.js +68 -0
  130. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  131. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  132. package/dist/lib/geojson-tiler/tile.js +125 -0
  133. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  134. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  135. package/dist/lib/geojson-tiler/transform.js +43 -0
  136. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  137. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  138. package/dist/lib/geojson-tiler/wrap.js +86 -0
  139. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  140. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  141. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  142. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  143. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  144. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  145. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  146. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  147. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  148. package/dist/lib/parse-mvt.d.ts +14 -0
  149. package/dist/lib/parse-mvt.d.ts.map +1 -0
  150. package/dist/lib/parse-mvt.js +149 -98
  151. package/dist/lib/types.d.ts +69 -0
  152. package/dist/lib/types.d.ts.map +1 -0
  153. package/dist/lib/types.js +2 -2
  154. package/dist/mvt-loader.d.ts +10 -0
  155. package/dist/mvt-loader.d.ts.map +1 -0
  156. package/dist/mvt-loader.js +43 -22
  157. package/dist/mvt-worker.js +845 -766
  158. package/dist/workers/mvt-worker.d.ts +2 -0
  159. package/dist/workers/mvt-worker.d.ts.map +1 -0
  160. package/dist/workers/mvt-worker.js +5 -4
  161. package/package.json +10 -9
  162. package/src/helpers/binary-util-functions.ts +9 -7
  163. package/src/helpers/mapbox-util-functions.ts +2 -2
  164. package/src/index.ts +7 -0
  165. package/src/lib/binary-vector-tile/vector-tile-feature.ts +42 -45
  166. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  167. package/src/lib/geojson-tiler/LICENSE +19 -0
  168. package/src/lib/geojson-tiler/clip.ts +248 -0
  169. package/src/lib/geojson-tiler/convert.ts +158 -0
  170. package/src/lib/geojson-tiler/feature.ts +45 -0
  171. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  172. package/src/lib/geojson-tiler/simplify.ts +77 -0
  173. package/src/lib/geojson-tiler/tile.ts +185 -0
  174. package/src/lib/geojson-tiler/transform.ts +55 -0
  175. package/src/lib/geojson-tiler/wrap.ts +108 -0
  176. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  177. package/src/lib/parse-mvt.ts +138 -93
  178. package/src/lib/types.ts +49 -72
  179. package/src/mvt-loader.ts +13 -9
  180. package/dist/bundle.js.map +0 -1
  181. package/dist/helpers/binary-util-functions.js.map +0 -1
  182. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
  185. package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  186. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  187. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  188. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  189. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  190. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  191. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  192. package/dist/lib/parse-mvt.js.map +0 -1
  193. package/dist/lib/types.js.map +0 -1
  194. package/dist/mvt-loader.js.map +0 -1
  195. package/dist/workers/mvt-worker.js.map +0 -1
  196. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
  197. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  198. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
package/src/lib/types.ts CHANGED
@@ -1,92 +1,69 @@
1
- export type MvtOptions = {
2
- coordinates: string | number[];
1
+ import type {LoaderOptions} from '@loaders.gl/loader-utils';
2
+
3
+ /** For local coordinates, the tileIndex is not required */
4
+ type MVTLocalCoordinatesOptions = {
5
+ /**
6
+ * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
7
+ */
8
+ coordinates: 'local';
9
+ tileIndex: null;
10
+ };
11
+
12
+ /** In WGS84 coordinates, the tileIndex is required */
13
+ type MVTWgs84CoordinatesOptions = {
14
+ /**
15
+ * 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.
16
+ */
17
+ coordinates: 'wgs84';
18
+
19
+ /**
20
+ * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,
21
+ * `z`) to reproject features' coordinates into WGS84.
22
+ */
3
23
  tileIndex: {x: number; y: number; z: number};
4
- layerProperty: string | number;
5
- layerName: string;
6
24
  };
7
25
 
8
- export type MvtBinaryGeometry = {
9
- data: number[];
10
- lines: any[];
11
- areas?: number[];
12
- type?: string;
13
- id?: number;
26
+ export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
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
+ /**
35
+ * Optional list of layer names. If not `null`, only features belonging to the named layers will
36
+ * be included in the output. If `null`, features from all layers are returned.
37
+ */
38
+ layers?: string[];
39
+ shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
14
40
  };
15
41
 
16
- export type MvtMapboxGeometry = {
42
+ export type MVTMapboxGeometry = {
17
43
  type?: string;
18
44
  id?: number;
19
45
  length: number;
20
46
  coordinates?: any[];
21
47
  };
22
48
 
23
- export type MvtBinaryCoordinates = {
24
- type: string;
25
- geometry: MvtBinaryGeometry;
26
- properties: {[x: string]: string | number | boolean | null};
27
- id?: number;
28
- };
29
-
30
- export type MvtMapboxCoordinates = {
49
+ export type MVTMapboxCoordinates = {
31
50
  type: string;
32
51
  geometry: {
33
52
  type: string;
34
- coordinates: MvtMapboxGeometry;
53
+ coordinates: MVTMapboxGeometry;
35
54
  };
36
55
  properties: {[x: string]: string | number | boolean | null};
37
56
  id?: number;
38
57
  };
39
58
 
40
- export type MvtBinaryOptions = {
41
- numericPropKeys: string[];
42
- PositionDataType: Float32ArrayConstructor;
43
- };
44
-
45
- export type MvtFirstPassedData = {
46
- pointPositionsCount: number;
47
- pointFeaturesCount: number;
48
- linePositionsCount: number;
49
- linePathsCount: number;
50
- lineFeaturesCount: number;
51
- polygonPositionsCount: number;
52
- polygonObjectsCount: number;
53
- polygonRingsCount: number;
54
- polygonFeaturesCount: number;
55
- };
56
-
57
- export type MvtPoints = {
58
- positions: Float32Array;
59
- globalFeatureIds: Uint16Array | Uint32Array;
60
- featureIds: Uint16Array | Uint32Array;
61
- numericProps: object;
62
- properties: {}[];
63
- fields: {
64
- id?: number;
65
- }[];
66
- };
67
-
68
- export type MvtLines = {
69
- pathIndices: Uint16Array | Uint32Array;
70
- positions: Float32Array;
71
- globalFeatureIds: Uint16Array | Uint32Array;
72
- featureIds: Uint16Array | Uint32Array;
73
- numericProps: object;
74
- properties: {}[];
75
- fields: {
76
- id?: number;
77
- }[];
78
- };
79
-
80
- export type MvtPolygons = {
81
- polygonIndices: Uint16Array | Uint32Array;
82
- primitivePolygonIndices: Uint16Array | Uint32Array;
83
- positions: Float32Array;
84
- triangles: number[];
85
- globalFeatureIds: Uint16Array | Uint32Array;
86
- featureIds: Uint16Array | Uint32Array;
87
- numericProps: object;
88
- properties: {}[];
89
- fields: {
90
- id?: number;
91
- }[];
59
+ export type MVTLoaderOptions = LoaderOptions & {
60
+ mvt?: MVTOptions;
61
+ gis?: {
62
+ /**
63
+ * When set to `true`, the parser will output the data in binary format. This is equivalent to loading the data as GeoJSON and then applying [geojsonToBinary](https://loaders.gl/modules/gis/docs/api-reference/geojson-to-binary).
64
+ */
65
+ binary?: boolean;
66
+ /** @deprecated. Use options.mvt.shape */
67
+ format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
68
+ };
92
69
  };
package/src/mvt-loader.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
2
+ import type {MVTLoaderOptions} from './lib/types';
2
3
  import parseMVT from './lib/parse-mvt';
3
4
 
4
5
  // __VERSION__ is injected by babel-plugin-version-inline
5
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
7
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
8
 
9
+ const DEFAULT_MVT_LOADER_OPTIONS: MVTLoaderOptions = {
10
+ mvt: {
11
+ shape: 'geojson',
12
+ coordinates: 'local',
13
+ layerProperty: 'layerName',
14
+ layers: undefined,
15
+ tileIndex: null
16
+ }
17
+ };
18
+
8
19
  /**
9
20
  * Worker loader for the Mapbox Vector Tile format
10
21
  */
@@ -22,14 +33,7 @@ export const MVTWorkerLoader: Loader = {
22
33
  ],
23
34
  worker: true,
24
35
  category: 'geometry',
25
- options: {
26
- mvt: {
27
- coordinates: 'local',
28
- layerProperty: 'layerName',
29
- layers: null,
30
- tileIndex: null
31
- }
32
- }
36
+ options: DEFAULT_MVT_LOADER_OPTIONS
33
37
  };
34
38
 
35
39
  /**
@@ -37,7 +41,7 @@ export const MVTWorkerLoader: Loader = {
37
41
  */
38
42
  export const MVTLoader: LoaderWithParser = {
39
43
  ...MVTWorkerLoader,
40
- parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
44
+ parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),
41
45
  parseSync: parseMVT,
42
46
  binary: true
43
47
  };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/binary-util-functions.ts"],"names":["getPolygonSignedArea","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,SAAQA,oBAAR,QAAmC,kBAAnC;AAcA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAAgD;AACrD,QAAMC,GAAG,GAAGD,IAAI,CAACE,KAAL,CAAWC,MAAvB;;AAEA,MAAIF,GAAG,IAAI,CAAX,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import 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 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/mapbox-util-functions.ts"],"names":["classifyRings","rings","len","length","polygons","polygon","ccw","i","area","signedArea","undefined","push","ring","sum","j","p1","p2","readFeature","tag","feature","pbf","id","readVarint","readTag","type","_geometry","pos","end","key","_keys","value","_values","properties"],"mappings":"AASA,OAAO,SAASA,aAAT,CAAuBC,KAAvB,EAAiD;AACtD,QAAMC,GAAG,GAAGD,KAAK,CAACE,MAAlB;AAEA,MAAID,GAAG,IAAI,CAAX,EAAc,OAAO,CAACD,KAAD,CAAP;AAEd,QAAMG,QAAsB,GAAG,EAA/B;AACA,MAAIC,OAAJ;AACA,MAAIC,GAAJ;;AAEA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGL,GAApB,EAAyBK,CAAC,EAA1B,EAA8B;AAC5B,UAAMC,IAAI,GAAGC,UAAU,CAACR,KAAK,CAACM,CAAD,CAAN,CAAvB;AACA,QAAIC,IAAI,KAAK,CAAb,EAAgB;AAEhB,QAAIF,GAAG,KAAKI,SAAZ,EAAuBJ,GAAG,GAAGE,IAAI,GAAG,CAAb;;AAEvB,QAAIF,G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AAZ,EAAeC,OAAO,CAACK,IAAR,GAAeJ,GAAG,CAACE,UAAJ,EAAf,CAAf,KACA,IAAIJ,GAAG,KAAK,CAAZ,EAAeC,OAAO,CAACM,SAAR,GAAoBL,GAAG,CAACM,GAAxB;AACrB;AACF;AAOD,OAAO,SAASH,OAAT,CAAiBH,GAAjB,EAAgCD,OAAhC,EAAkE;AACvE,QAAMQ,GAAG,GAAGP,GAAG,CAACE,UAAJ,KAAmBF,GAAG,CAACM,GAAnC;;AAEA,SAAON,GAAG,CAACM,GAAJ,GAAUC,GAAjB,EAAsB;AACpB,UAAMC,GAAG,GAAGT,OAAO,CAACU,KAAR,CAAcT,GAAG,CAACE,UAAJ,EAAd,CAAZ;;AACA,UAAMQ,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 {MvtMapboxGeometry} from '../lib/types';\nimport VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';\n\n/**\n * Classifies an array of rings into polygons with outer rings and holes\n * @param rings\n * @returns polygons\n */\nexport function classifyRings(rings: MvtMapboxGeometry) {\n const len = rings.length;\n\n if (len <= 1) return [rings];\n\n const polygons: number[][][] = [];\n let polygon: number[][] | undefined;\n let ccw: boolean | undefined;\n\n for (let i = 0; i < len; i++) {\n const area = signedArea(rings[i]);\n if (area === 0) continue; // eslint-disable-line no-continue\n\n if (ccw === undefined) ccw = area < 0;\n\n if (ccw === area < 0) {\n if (polygon) polygons.push(polygon);\n polygon = [rings[i]];\n } else if (polygon) polygon.push(rings[i]);\n }\n if (polygon) polygons.push(polygon);\n\n return polygons;\n}\n\n/**\n *\n * @param ring\n * @returns sum\n */\nexport function signedArea(ring: number[][]) {\n let sum = 0;\n for (let i = 0, j = ring.length - 1, p1: number[], p2: number[]; i < ring.length; j = i++) {\n p1 = ring[i];\n p2 = ring[j];\n sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);\n }\n return sum;\n}\n\n/**\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 *\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":"mapbox-util-functions.js"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["MVTLoader","MVTWorkerLoader"],"mappings":"AAAA,SAAQA,SAAR,EAAmBC,eAAnB,QAAyC,cAAzC","sourcesContent":["export {MVTLoader, MVTWorkerLoader} from './mvt-loader';\n"],"file":"index.js"}
@@ -1,327 +0,0 @@
1
- import { earcut } from '@math.gl/polygon';
2
- export function featuresToBinary(features, firstPassData, options) {
3
- return fillArrays(features, firstPassData, {
4
- numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
5
- PositionDataType: options ? options.PositionDataType : Float32Array
6
- });
7
- }
8
- export const TEST_EXPORTS = {
9
- extractNumericPropKeys,
10
- fillArrays
11
- };
12
-
13
- function extractNumericPropKeys(features) {
14
- const numericPropKeys = {};
15
-
16
- for (const feature of features) {
17
- if (feature.properties) {
18
- for (const key in feature.properties) {
19
- const numericSoFar = numericPropKeys[key];
20
-
21
- if (numericSoFar || numericSoFar === undefined) {
22
- const val = feature.properties[key];
23
- numericPropKeys[key] = isNumeric(val);
24
- }
25
- }
26
- }
27
- }
28
-
29
- return Object.keys(numericPropKeys).filter(k => numericPropKeys[k]);
30
- }
31
-
32
- function fillArrays(features, firstPassData, options) {
33
- const {
34
- pointPositionsCount,
35
- pointFeaturesCount,
36
- linePositionsCount,
37
- linePathsCount,
38
- lineFeaturesCount,
39
- polygonPositionsCount,
40
- polygonObjectsCount,
41
- polygonRingsCount,
42
- polygonFeaturesCount
43
- } = firstPassData;
44
- const {
45
- numericPropKeys,
46
- PositionDataType = Float32Array
47
- } = options;
48
- const hasGlobalId = features[0] && 'id' in features[0];
49
- const coordLength = 2;
50
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
51
- const points = {
52
- positions: new PositionDataType(pointPositionsCount * coordLength),
53
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
54
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
55
- numericProps: {},
56
- properties: [],
57
- fields: []
58
- };
59
- const lines = {
60
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
61
- positions: new PositionDataType(linePositionsCount * coordLength),
62
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
63
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
64
- numericProps: {},
65
- properties: [],
66
- fields: []
67
- };
68
- const polygons = {
69
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
70
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
71
- positions: new PositionDataType(polygonPositionsCount * coordLength),
72
- triangles: [],
73
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
74
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
75
- numericProps: {},
76
- properties: [],
77
- fields: []
78
- };
79
-
80
- for (const object of [points, lines, polygons]) {
81
- for (const propName of numericPropKeys) {
82
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
83
- }
84
- }
85
-
86
- lines.pathIndices[linePathsCount] = linePositionsCount;
87
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
88
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
89
- const indexMap = {
90
- pointPosition: 0,
91
- pointFeature: 0,
92
- linePosition: 0,
93
- linePath: 0,
94
- lineFeature: 0,
95
- polygonPosition: 0,
96
- polygonObject: 0,
97
- polygonRing: 0,
98
- polygonFeature: 0,
99
- feature: 0
100
- };
101
-
102
- for (const feature of features) {
103
- const geometry = feature.geometry;
104
- const properties = feature.properties || {};
105
-
106
- switch (geometry.type) {
107
- case 'Point':
108
- case 'MultiPoint':
109
- handlePoint(geometry, points, indexMap, coordLength, properties);
110
- points.properties.push(keepStringProperties(properties, numericPropKeys));
111
-
112
- if (hasGlobalId) {
113
- points.fields.push({
114
- id: feature.id
115
- });
116
- }
117
-
118
- indexMap.pointFeature++;
119
- break;
120
-
121
- case 'LineString':
122
- case 'MultiLineString':
123
- handleLineString(geometry, lines, indexMap, coordLength, properties);
124
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
125
-
126
- if (hasGlobalId) {
127
- lines.fields.push({
128
- id: feature.id
129
- });
130
- }
131
-
132
- indexMap.lineFeature++;
133
- break;
134
-
135
- case 'Polygon':
136
- case 'MultiPolygon':
137
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
138
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
139
-
140
- if (hasGlobalId) {
141
- polygons.fields.push({
142
- id: feature.id
143
- });
144
- }
145
-
146
- indexMap.polygonFeature++;
147
- break;
148
-
149
- default:
150
- throw new Error('Invalid geometry type');
151
- }
152
-
153
- indexMap.feature++;
154
- }
155
-
156
- return makeAccessorObjects(points, lines, polygons, coordLength);
157
- }
158
-
159
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
160
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
161
- const nPositions = geometry.data.length / coordLength;
162
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
163
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
164
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
165
- indexMap.pointPosition += nPositions;
166
- }
167
-
168
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
169
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
170
- const nPositions = geometry.data.length / coordLength;
171
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
172
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
173
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
174
-
175
- for (let i = 0, il = geometry.lines.length; i < il; ++i) {
176
- const start = geometry.lines[i];
177
- const end = i === il - 1 ? geometry.data.length : geometry.lines[i + 1];
178
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
179
- indexMap.linePosition += (end - start) / coordLength;
180
- }
181
- }
182
-
183
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
184
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
185
- const nPositions = geometry.data.length / coordLength;
186
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
187
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
188
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
189
-
190
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
191
- const startPosition = indexMap.polygonPosition;
192
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
193
- const areas = geometry.areas[l];
194
- const lines = geometry.lines[l];
195
- const nextLines = geometry.lines[l + 1];
196
-
197
- for (let i = 0, il = lines.length; i < il; ++i) {
198
- const start = lines[i];
199
- const end = i === il - 1 ? nextLines === undefined ? geometry.data.length : nextLines[0] : lines[i + 1];
200
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
201
- indexMap.polygonPosition += (end - start) / coordLength;
202
- }
203
-
204
- const endPosition = indexMap.polygonPosition;
205
- triangulatePolygon(polygons, areas, lines, {
206
- startPosition,
207
- endPosition,
208
- coordLength
209
- });
210
- }
211
- }
212
-
213
- function triangulatePolygon(polygons, areas, lines, {
214
- startPosition,
215
- endPosition,
216
- coordLength
217
- }) {
218
- const start = startPosition * coordLength;
219
- const end = endPosition * coordLength;
220
- const polygonPositions = polygons.positions.subarray(start, end);
221
- const offset = lines[0];
222
- const holes = lines.slice(1).map(n => (n - offset) / coordLength);
223
- const indices = earcut(polygonPositions, holes, coordLength, areas);
224
-
225
- for (let t = 0, tl = indices.length; t < tl; ++t) {
226
- polygons.triangles.push(startPosition + indices[t]);
227
- }
228
- }
229
-
230
- function makeAccessorObjects(points, lines, polygons, coordLength) {
231
- const returnObj = {
232
- points: { ...points,
233
- positions: {
234
- value: points.positions,
235
- size: coordLength
236
- },
237
- globalFeatureIds: {
238
- value: points.globalFeatureIds,
239
- size: 1
240
- },
241
- featureIds: {
242
- value: points.featureIds,
243
- size: 1
244
- }
245
- },
246
- lines: { ...lines,
247
- pathIndices: {
248
- value: lines.pathIndices,
249
- size: 1
250
- },
251
- positions: {
252
- value: lines.positions,
253
- size: coordLength
254
- },
255
- globalFeatureIds: {
256
- value: lines.globalFeatureIds,
257
- size: 1
258
- },
259
- featureIds: {
260
- value: lines.featureIds,
261
- size: 1
262
- }
263
- },
264
- polygons: { ...polygons,
265
- polygonIndices: {
266
- value: polygons.polygonIndices,
267
- size: 1
268
- },
269
- primitivePolygonIndices: {
270
- value: polygons.primitivePolygonIndices,
271
- size: 1
272
- },
273
- positions: {
274
- value: polygons.positions,
275
- size: coordLength
276
- },
277
- triangles: {
278
- value: new Uint32Array(polygons.triangles),
279
- size: 1
280
- },
281
- globalFeatureIds: {
282
- value: polygons.globalFeatureIds,
283
- size: 1
284
- },
285
- featureIds: {
286
- value: polygons.featureIds,
287
- size: 1
288
- }
289
- }
290
- };
291
-
292
- for (const geomType in returnObj) {
293
- for (const numericProp in returnObj[geomType].numericProps) {
294
- returnObj[geomType].numericProps[numericProp] = {
295
- value: returnObj[geomType].numericProps[numericProp],
296
- size: 1
297
- };
298
- }
299
- }
300
-
301
- return returnObj;
302
- }
303
-
304
- function fillNumericProperties(object, properties, index, length) {
305
- for (const numericPropName in object.numericProps) {
306
- if (numericPropName in properties) {
307
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);
308
- }
309
- }
310
- }
311
-
312
- function keepStringProperties(properties, numericKeys) {
313
- const props = {};
314
-
315
- for (const key in properties) {
316
- if (!numericKeys.includes(key)) {
317
- props[key] = properties[key];
318
- }
319
- }
320
-
321
- return props;
322
- }
323
-
324
- function isNumeric(x) {
325
- return Number.isFinite(x);
326
- }
327
- //# sourceMappingURL=features-to-binary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","fillArrays","numericPropKeys","extractNumericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","numericSoFar","undefined","val","isNumeric","Object","keys","filter","k","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","Number","isFinite"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAwBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,SAAOC,UAAU,CAACH,QAAD,EAAWC,aAAX,EAA0B;AACzCG,IAAAA,eAAe,EAAEF,OAAO,GAAGA,OAAO,CAACE,eAAX,GAA6BC,sBAAsB,CAACL,QAAD,CADlC;AAEzCM,IAAAA,gBAAgB,EAAEJ,OAAO,GAAGA,OAAO,CAACI,gBAAX,GAA8BC;AAFd,GAA1B,CAAjB;AAID;AAED,OAAO,MAAMC,YAAY,GAAG;AAC1BH,EAAAA,sBAD0B;AAE1BF,EAAAA;AAF0B,CAArB;;AAWP,SAASE,sBAAT,CAAgCL,QAAhC,EAA4E;AAC1E,QAAMI,eAAe,GAAG,EAAxB;;AACA,OAAK,MAAMK,OAAX,IAAsBT,QAAtB,EAAgC;AAC9B,QAAIS,OAAO,CAACC,UAAZ,EAAwB;AACtB,WAAK,MAAMC,GAAX,IAAkBF,OAAO,CAACC,UAA1B,EAAsC;AAIpC,cAAME,YAAY,GAAGR,eAAe,CAACO,GAAD,CAApC;;AACA,YAAIC,YAAY,IAAIA,YAAY,KAAKC,SAArC,EAAgD;AAC9C,gBAAMC,GAAG,GAAGL,OAAO,CAACC,UAAR,CAAmBC,GAAnB,CAAZ;AACAP,UAAAA,eAAe,CAACO,GAAD,CAAf,GAAuBI,SAAS,CAACD,GAAD,CAAhC;AACD;AACF;AACF;AACF;;AAED,SAAOE,MAAM,CAACC,IAAP,CAAYb,eAAZ,EAA6Bc,MAA7B,CAAqCC,CAAD,IAAOf,eAAe,CAACe,CAAD,CAA1D,CAAP;AACD;;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;AACF;AACF;;AASD,SAAS+B,oBAAT,CACErD,UADF,EAEE4F,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAM5F,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAAC4F,WAAW,CAACE,QAAZ,CAAqB7F,GAArB,CAAL,EAAgC;AAC9B4F,MAAAA,KAAK,CAAC5F,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAO4F,KAAP;AACD;;AAED,SAASxF,SAAT,CAAmB0F,CAAnB,EAA+B;AAC7B,SAAOC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAP;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n extractNumericPropKeys,\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric keys\n */\nfunction extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[] {\n const numericPropKeys = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, false is stored to prevent rechecking in the future\n const numericSoFar = numericPropKeys[key];\n if (numericSoFar || numericSoFar === undefined) {\n const val = feature.properties[key];\n numericPropKeys[key] = isNumeric(val);\n }\n }\n }\n }\n\n return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction isNumeric(x: unknown) {\n return Number.isFinite(x);\n}\n"],"file":"features-to-binary.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","loadGeometry","pos","readVarint","lines","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","geometry","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAvB,EAAgCC,WAAhC,QAAkD,qCAAlD;AAGA,IAAIC,MAAJ;AACA,IAAIC,GAAJ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C,MAAAA,QAAQ,EAAEb,IAFyB;AAGnCpB,MAAAA,UAAU,EAAE,KAAKA;AAHkB,KAArC;;AAMA,QAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB8B,MAAAA,MAAM,CAAC9B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,WAAO8B,MAAP;AACD;;AAEDE,EAAAA,mBAAmB,CACjBC,OADiB,EAEK;AACtB,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKjB,oBAAL,CAA0BiB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKjB,oBAAL,CAA0BrC,OAA1B,CAAP;AACD;;AArLoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData} from '../types';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _firstPassData: MvtFirstPassedData;\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n firstPassData: MvtFirstPassedData\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._firstPassData = firstPassData;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtBinaryGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const lines: number[] = []; // Indices where lines start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n lines.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = lines[lines.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, lines};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate `lines`\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `lines`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], lines: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], lines: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]\n // }\n // Thus the lines member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the lines array\n let geom = this.loadGeometry();\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._firstPassData.pointFeaturesCount++;\n this._firstPassData.pointPositionsCount += geom.lines.length;\n break;\n\n case 2: // LineString\n this._firstPassData.lineFeaturesCount++;\n this._firstPassData.linePathsCount += geom.lines.length;\n this._firstPassData.linePositionsCount += geom.data.length / coordLength;\n break;\n\n case 3: // Polygon\n const classified = classifyRings(geom);\n\n // Unlike Point & LineString geom.lines is a 2D array, thanks\n // to the classifyRings method\n this._firstPassData.polygonFeaturesCount++;\n this._firstPassData.polygonObjectsCount += classified.lines.length;\n\n for (const lines of classified.lines) {\n this._firstPassData.polygonRingsCount += lines.length;\n }\n this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;\n\n geom = classified;\n break;\n }\n\n geom.type = VectorTileFeature.types[this.type];\n if (geom.lines.length > 1) {\n geom.type = `Multi${geom.type}`;\n }\n\n const result: MvtBinaryCoordinates = {\n type: 'Feature',\n geometry: geom,\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtBinaryCoordinates {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}