@loaders.gl/mvt 4.0.0-alpha.1 → 4.0.0-alpha.11

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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mvt-loader.js","names":["parseMVT","VERSION","DEFAULT_MVT_LOADER_OPTIONS","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","MVTLoader","parse","arrayBuffer","parseSync","binary"],"sources":["../../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nconst DEFAULT_MVT_LOADER_OPTIONS: MVTLoaderOptions = {\n mvt: {\n shape: 'geojson',\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: undefined,\n tileIndex: null\n }\n};\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: DEFAULT_MVT_LOADER_OPTIONS\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"mappings":"AAEA,OAAOA,QAAQ,MAAM,iBAAiB;AAItC,MAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAE3E,MAAMC,0BAA4C,GAAG;EACnDC,GAAG,EAAE;IACHC,KAAK,EAAE,SAAS;IAChBC,WAAW,EAAE,OAAO;IACpBC,aAAa,EAAE,WAAW;IAC1BC,MAAM,EAAEC,SAAS;IACjBC,SAAS,EAAE;EACb;AACF,CAAC;AAKD,OAAO,MAAMC,eAAuB,GAAG;EACrCC,IAAI,EAAE,oBAAoB;EAC1BC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEb,OAAO;EAEhBc,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;EAC1BC,SAAS,EAAE,CACT,oCAAoC,EACpC,wBAAwB,CAEzB;EACDC,MAAM,EAAE,IAAI;EACZC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAEjB;AACX,CAAC;AAKD,OAAO,MAAMkB,SAA2B,GAAG;EACzC,GAAGV,eAAe;EAClBW,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEH,OAA0B,KAAKnB,QAAQ,CAACsB,WAAW,EAAEH,OAAO,CAAC;EACxFI,SAAS,EAAEvB,QAAQ;EACnBwB,MAAM,EAAE;AACV,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { MVTLoader } from '../mvt-loader';
2
+ import { createLoaderWorker } from '@loaders.gl/loader-utils';
3
+ createLoaderWorker(MVTLoader);
4
+ //# sourceMappingURL=mvt-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mvt-worker.js","names":["MVTLoader","createLoaderWorker"],"sources":["../../../src/workers/mvt-worker.ts"],"sourcesContent":["import {MVTLoader} from '../mvt-loader';\nimport {createLoaderWorker} from '@loaders.gl/loader-utils';\n\ncreateLoaderWorker(MVTLoader);\n"],"mappings":"AAAA,SAAQA,SAAS,QAAO,eAAe;AACvC,SAAQC,kBAAkB,QAAO,0BAA0B;AAE3DA,kBAAkB,CAACD,SAAS,CAAC"}
@@ -0,0 +1,35 @@
1
+ import Protobuf from 'pbf';
2
+ import { FlatIndexedGeometry, FlatPolygon } from '@loaders.gl/schema';
3
+ import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
4
+ /**
5
+ * Classifies an array of rings into polygons with outer rings and holes
6
+ * The function also detects holes which have zero area and
7
+ * removes them. In doing so it modifies the input
8
+ * `geom.data` array to remove the unneeded data
9
+ *
10
+ * @param geometry
11
+ * @returns object
12
+ */
13
+ export declare function classifyRings(geom: FlatIndexedGeometry): FlatPolygon;
14
+ /**
15
+ *
16
+ * @param data
17
+ * @param x0
18
+ * @param y0
19
+ * @param size
20
+ */
21
+ export declare function project(data: number[], x0: number, y0: number, size: number): void;
22
+ /**
23
+ * All code below is unchanged from the original Mapbox implemenation
24
+ *
25
+ * @param tag
26
+ * @param feature
27
+ * @param pbf
28
+ */
29
+ export declare function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void;
30
+ /**
31
+ * @param pbf
32
+ * @param feature
33
+ */
34
+ export declare function readTag(pbf: Protobuf, feature: VectorTileFeature): void;
35
+ //# sourceMappingURL=binary-util-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/binary-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AACpE,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;;;;;GAQG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,WAAW,CA4DpE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
@@ -1,81 +1,118 @@
1
- import { getPolygonSignedArea } from '@math.gl/polygon';
2
- export function classifyRings(geom) {
3
- const len = geom.lines.length;
4
-
5
- if (len <= 1) {
6
- return {
7
- data: geom.data,
8
- areas: [[getPolygonSignedArea(geom.data)]],
9
- lines: [geom.lines]
10
- };
11
- }
12
-
13
- const areas = [];
14
- const polygons = [];
15
- let ringAreas = [];
16
- let polygon = [];
17
- let ccw;
18
- let offset = 0;
19
-
20
- for (let endIndex, i = 0, startIndex; i < len; i++) {
21
- startIndex = geom.lines[i] - offset;
22
- endIndex = geom.lines[i + 1] - offset || geom.data.length;
23
- const shape = geom.data.slice(startIndex, endIndex);
24
- const area = getPolygonSignedArea(shape);
25
-
26
- if (area === 0) {
27
- const before = geom.data.slice(0, startIndex);
28
- const after = geom.data.slice(endIndex);
29
- geom.data = before.concat(after);
30
- offset += endIndex - startIndex;
31
- continue;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readTag = exports.readFeature = exports.project = exports.classifyRings = void 0;
4
+ const polygon_1 = require("@math.gl/polygon");
5
+ /**
6
+ * Classifies an array of rings into polygons with outer rings and holes
7
+ * The function also detects holes which have zero area and
8
+ * removes them. In doing so it modifies the input
9
+ * `geom.data` array to remove the unneeded data
10
+ *
11
+ * @param geometry
12
+ * @returns object
13
+ */
14
+ // eslint-disable-next-line max-statements
15
+ function classifyRings(geom) {
16
+ const len = geom.indices.length;
17
+ const type = 'Polygon';
18
+ if (len <= 1) {
19
+ return {
20
+ type,
21
+ data: geom.data,
22
+ areas: [[(0, polygon_1.getPolygonSignedArea)(geom.data)]],
23
+ indices: [geom.indices]
24
+ };
32
25
  }
33
-
34
- if (ccw === undefined) ccw = area < 0;
35
-
36
- if (ccw === area < 0) {
37
- if (polygon.length) {
26
+ const areas = [];
27
+ const polygons = [];
28
+ let ringAreas = [];
29
+ let polygon = [];
30
+ let ccw;
31
+ let offset = 0;
32
+ for (let endIndex, i = 0, startIndex; i < len; i++) {
33
+ startIndex = geom.indices[i] - offset;
34
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
35
+ const shape = geom.data.slice(startIndex, endIndex);
36
+ const area = (0, polygon_1.getPolygonSignedArea)(shape);
37
+ if (area === 0) {
38
+ // This polygon has no area, so remove it from the shape
39
+ // Remove the section from the data array
40
+ const before = geom.data.slice(0, startIndex);
41
+ const after = geom.data.slice(endIndex);
42
+ geom.data = before.concat(after);
43
+ // Need to offset any remaining indices as we have
44
+ // modified the data buffer
45
+ offset += endIndex - startIndex;
46
+ // Do not add this index to the output and process next shape
47
+ continue; // eslint-disable-line no-continue
48
+ }
49
+ if (ccw === undefined)
50
+ ccw = area < 0;
51
+ if (ccw === area < 0) {
52
+ if (polygon.length) {
53
+ areas.push(ringAreas);
54
+ polygons.push(polygon);
55
+ }
56
+ polygon = [startIndex];
57
+ ringAreas = [area];
58
+ }
59
+ else {
60
+ ringAreas.push(area);
61
+ polygon.push(startIndex);
62
+ }
63
+ }
64
+ if (ringAreas)
38
65
  areas.push(ringAreas);
66
+ if (polygon.length)
39
67
  polygons.push(polygon);
40
- }
41
-
42
- polygon = [startIndex];
43
- ringAreas = [area];
44
- } else {
45
- ringAreas.push(area);
46
- polygon.push(startIndex);
47
- }
48
- }
49
-
50
- if (ringAreas) areas.push(ringAreas);
51
- if (polygon.length) polygons.push(polygon);
52
- return {
53
- areas,
54
- lines: polygons,
55
- data: geom.data
56
- };
68
+ return { type, areas, indices: polygons, data: geom.data };
57
69
  }
58
- export function project(data, x0, y0, size) {
59
- for (let j = 0, jl = data.length; j < jl; j += 2) {
60
- data[j] = (data[j] + x0) * 360 / size - 180;
61
- const y2 = 180 - (data[j + 1] + y0) * 360 / size;
62
- data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
63
- }
70
+ exports.classifyRings = classifyRings;
71
+ /**
72
+ *
73
+ * @param data
74
+ * @param x0
75
+ * @param y0
76
+ * @param size
77
+ */
78
+ function project(data, x0, y0, size) {
79
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
80
+ data[j] = ((data[j] + x0) * 360) / size - 180;
81
+ const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
82
+ data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
83
+ }
64
84
  }
65
- export function readFeature(tag, feature, pbf) {
66
- if (feature && pbf) {
67
- if (tag === 1) feature.id = pbf.readVarint();else if (tag === 2) readTag(pbf, feature);else if (tag === 3) feature.type = pbf.readVarint();else if (tag === 4) feature._geometry = pbf.pos;
68
- }
85
+ exports.project = project;
86
+ /**
87
+ * All code below is unchanged from the original Mapbox implemenation
88
+ *
89
+ * @param tag
90
+ * @param feature
91
+ * @param pbf
92
+ */
93
+ function readFeature(tag, feature, pbf) {
94
+ if (feature && pbf) {
95
+ if (tag === 1)
96
+ feature.id = pbf.readVarint();
97
+ else if (tag === 2)
98
+ readTag(pbf, feature);
99
+ else if (tag === 3)
100
+ feature.type = pbf.readVarint();
101
+ else if (tag === 4)
102
+ feature._geometry = pbf.pos;
103
+ }
69
104
  }
70
- export function readTag(pbf, feature) {
71
- const end = pbf.readVarint() + pbf.pos;
72
-
73
- while (pbf.pos < end) {
74
- const key = feature._keys[pbf.readVarint()];
75
-
76
- const value = feature._values[pbf.readVarint()];
77
-
78
- feature.properties[key] = value;
79
- }
105
+ exports.readFeature = readFeature;
106
+ /**
107
+ * @param pbf
108
+ * @param feature
109
+ */
110
+ function readTag(pbf, feature) {
111
+ const end = pbf.readVarint() + pbf.pos;
112
+ while (pbf.pos < end) {
113
+ const key = feature._keys[pbf.readVarint()];
114
+ const value = feature._values[pbf.readVarint()];
115
+ feature.properties[key] = value;
116
+ }
80
117
  }
81
- //# sourceMappingURL=binary-util-functions.js.map
118
+ exports.readTag = readTag;
@@ -0,0 +1,29 @@
1
+ import Protobuf from 'pbf';
2
+ import { MVTMapboxGeometry } from '../lib/types';
3
+ import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
4
+ /**
5
+ * Classifies an array of rings into polygons with outer rings and holes
6
+ * @param rings
7
+ * @returns polygons
8
+ */
9
+ export declare function classifyRings(rings: MVTMapboxGeometry): MVTMapboxGeometry[] | number[][][];
10
+ /**
11
+ *
12
+ * @param ring
13
+ * @returns sum
14
+ */
15
+ export declare function signedArea(ring: number[][]): number;
16
+ /**
17
+ *
18
+ * @param tag
19
+ * @param feature
20
+ * @param pbf
21
+ */
22
+ export declare function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void;
23
+ /**
24
+ *
25
+ * @param pbf
26
+ * @param feature
27
+ */
28
+ export declare function readTag(pbf: Protobuf, feature: VectorTileFeature): void;
29
+ //# sourceMappingURL=mapbox-util-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/mapbox-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,sCAuBrD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAQ1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
@@ -1,49 +1,82 @@
1
- export function classifyRings(rings) {
2
- const len = rings.length;
3
- if (len <= 1) return [rings];
4
- const polygons = [];
5
- let polygon;
6
- let ccw;
7
-
8
- for (let i = 0; i < len; i++) {
9
- const area = signedArea(rings[i]);
10
- if (area === 0) continue;
11
- if (ccw === undefined) ccw = area < 0;
12
-
13
- if (ccw === area < 0) {
14
- if (polygon) polygons.push(polygon);
15
- polygon = [rings[i]];
16
- } else if (polygon) polygon.push(rings[i]);
17
- }
18
-
19
- if (polygon) polygons.push(polygon);
20
- return polygons;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readTag = exports.readFeature = exports.signedArea = exports.classifyRings = void 0;
4
+ /**
5
+ * Classifies an array of rings into polygons with outer rings and holes
6
+ * @param rings
7
+ * @returns polygons
8
+ */
9
+ function classifyRings(rings) {
10
+ const len = rings.length;
11
+ if (len <= 1)
12
+ return [rings];
13
+ const polygons = [];
14
+ let polygon;
15
+ let ccw;
16
+ for (let i = 0; i < len; i++) {
17
+ const area = signedArea(rings[i]);
18
+ if (area === 0)
19
+ continue; // eslint-disable-line no-continue
20
+ if (ccw === undefined)
21
+ ccw = area < 0;
22
+ if (ccw === area < 0) {
23
+ if (polygon)
24
+ polygons.push(polygon);
25
+ polygon = [rings[i]];
26
+ }
27
+ else if (polygon)
28
+ polygon.push(rings[i]);
29
+ }
30
+ if (polygon)
31
+ polygons.push(polygon);
32
+ return polygons;
21
33
  }
22
- export function signedArea(ring) {
23
- let sum = 0;
24
-
25
- for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
26
- p1 = ring[i];
27
- p2 = ring[j];
28
- sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
29
- }
30
-
31
- return sum;
34
+ exports.classifyRings = classifyRings;
35
+ /**
36
+ *
37
+ * @param ring
38
+ * @returns sum
39
+ */
40
+ function signedArea(ring) {
41
+ let sum = 0;
42
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
43
+ p1 = ring[i];
44
+ p2 = ring[j];
45
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
46
+ }
47
+ return sum;
32
48
  }
33
- export function readFeature(tag, feature, pbf) {
34
- if (feature && pbf) {
35
- if (tag === 1) feature.id = pbf.readVarint();else if (tag === 2) readTag(pbf, feature);else if (tag === 3) feature.type = pbf.readVarint();else if (tag === 4) feature._geometry = pbf.pos;
36
- }
49
+ exports.signedArea = signedArea;
50
+ /**
51
+ *
52
+ * @param tag
53
+ * @param feature
54
+ * @param pbf
55
+ */
56
+ function readFeature(tag, feature, pbf) {
57
+ if (feature && pbf) {
58
+ if (tag === 1)
59
+ feature.id = pbf.readVarint();
60
+ else if (tag === 2)
61
+ readTag(pbf, feature);
62
+ else if (tag === 3)
63
+ feature.type = pbf.readVarint();
64
+ else if (tag === 4)
65
+ feature._geometry = pbf.pos;
66
+ }
37
67
  }
38
- export function readTag(pbf, feature) {
39
- const end = pbf.readVarint() + pbf.pos;
40
-
41
- while (pbf.pos < end) {
42
- const key = feature._keys[pbf.readVarint()];
43
-
44
- const value = feature._values[pbf.readVarint()];
45
-
46
- feature.properties[key] = value;
47
- }
68
+ exports.readFeature = readFeature;
69
+ /**
70
+ *
71
+ * @param pbf
72
+ * @param feature
73
+ */
74
+ function readTag(pbf, feature) {
75
+ const end = pbf.readVarint() + pbf.pos;
76
+ while (pbf.pos < end) {
77
+ const key = feature._keys[pbf.readVarint()];
78
+ const value = feature._values[pbf.readVarint()];
79
+ feature.properties[key] = value;
80
+ }
48
81
  }
49
- //# sourceMappingURL=mapbox-util-functions.js.map
82
+ exports.readTag = readTag;
@@ -0,0 +1,4 @@
1
+ export { MVTLoader, MVTWorkerLoader } from './mvt-loader';
2
+ export type { GeoJSONTilerOptions } from './lib/geojson-tiler/geojson-tiler';
3
+ export { GeoJSONTiler } from './lib/geojson-tiler/geojson-tiler';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAIxD,YAAY,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,9 @@
1
- export { MVTLoader, MVTWorkerLoader } from './mvt-loader';
2
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.GeoJSONTiler = exports.MVTWorkerLoader = exports.MVTLoader = void 0;
5
+ var mvt_loader_1 = require("./mvt-loader");
6
+ Object.defineProperty(exports, "MVTLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTLoader; } });
7
+ Object.defineProperty(exports, "MVTWorkerLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTWorkerLoader; } });
8
+ var geojson_tiler_1 = require("./lib/geojson-tiler/geojson-tiler");
9
+ Object.defineProperty(exports, "GeoJSONTiler", { enumerable: true, get: function () { return geojson_tiler_1.GeoJSONTiler; } });
@@ -0,0 +1,41 @@
1
+ import Protobuf from 'pbf';
2
+ import { FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo } from '@loaders.gl/schema';
3
+ import { classifyRings } from '../../helpers/binary-util-functions';
4
+ export declare const TEST_EXPORTS: {
5
+ classifyRings: typeof classifyRings;
6
+ };
7
+ export default class VectorTileFeature {
8
+ properties: {
9
+ [x: string]: string | number | boolean | null;
10
+ };
11
+ extent: any;
12
+ type: number;
13
+ id: number | null;
14
+ _pbf: Protobuf;
15
+ _geometry: number;
16
+ _keys: string[];
17
+ _values: (string | number | boolean | null)[];
18
+ _geometryInfo: GeojsonGeometryInfo;
19
+ constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], geometryInfo: GeojsonGeometryInfo);
20
+ loadGeometry(): FlatIndexedGeometry;
21
+ /**
22
+ *
23
+ * @param transform
24
+ * @returns result
25
+ */
26
+ _toBinaryCoordinates(transform: any): {
27
+ type: "Feature";
28
+ geometry: import("@loaders.gl/schema").FlatGeometry;
29
+ id?: string | number | undefined;
30
+ properties: import("geojson").GeoJsonProperties;
31
+ bbox?: import("geojson").BBox | undefined;
32
+ };
33
+ toBinaryCoordinates(options: {
34
+ x: number;
35
+ y: number;
36
+ z: number;
37
+ } | ((data: number[], feature: {
38
+ extent: any;
39
+ }) => void)): FlatFeature;
40
+ }
41
+ //# sourceMappingURL=vector-tile-feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAC,aAAa,EAAuB,MAAM,qCAAqC,CAAC;AAWxF,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,aAAa,EAAE,mBAAmB,CAAC;gBAIjC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,EAC5C,YAAY,EAAE,mBAAmB;IAmBnC,YAAY,IAAI,mBAAmB;IAqDnC;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,KAAA;;;;;;;IAuE9B,mBAAmB,CACjB,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,WAAW;CAWf"}