@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (175) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +1748 -913
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/helpers/binary-util-functions.js +82 -0
  6. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  7. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  8. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  9. package/dist/es5/index.js +26 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  17. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  18. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  19. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  20. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  21. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  23. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  25. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  27. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  29. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  31. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  33. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  34. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  35. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  40. package/dist/es5/lib/parse-mvt.js +143 -0
  41. package/dist/es5/lib/parse-mvt.js.map +1 -0
  42. package/dist/es5/lib/types.js +2 -0
  43. package/dist/es5/lib/types.js.map +1 -0
  44. package/dist/es5/mvt-loader.js +58 -0
  45. package/dist/es5/mvt-loader.js.map +1 -0
  46. package/dist/es5/workers/mvt-worker.js +6 -0
  47. package/dist/es5/workers/mvt-worker.js.map +1 -0
  48. package/dist/esm/bundle.js +4 -0
  49. package/dist/esm/bundle.js.map +1 -0
  50. package/dist/esm/helpers/binary-util-functions.js +73 -0
  51. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  52. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  53. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  54. package/dist/esm/index.js +3 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  57. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  58. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  63. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  64. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  65. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  66. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  67. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  69. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  71. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  73. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  75. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  77. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  79. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  80. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  81. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  82. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  87. package/dist/esm/lib/parse-mvt.js +138 -0
  88. package/dist/esm/lib/parse-mvt.js.map +1 -0
  89. package/dist/esm/lib/types.js +2 -0
  90. package/dist/esm/lib/types.js.map +1 -0
  91. package/dist/esm/mvt-loader.js +29 -0
  92. package/dist/esm/mvt-loader.js.map +1 -0
  93. package/dist/esm/workers/mvt-worker.js +4 -0
  94. package/dist/esm/workers/mvt-worker.js.map +1 -0
  95. package/dist/helpers/binary-util-functions.js +111 -77
  96. package/dist/helpers/mapbox-util-functions.d.ts +2 -2
  97. package/dist/helpers/mapbox-util-functions.js +78 -45
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +9 -2
  101. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  102. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
  103. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  104. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  105. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  106. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  107. package/dist/lib/geojson-tiler/clip.js +209 -0
  108. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  109. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  110. package/dist/lib/geojson-tiler/convert.js +134 -0
  111. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  112. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  113. package/dist/lib/geojson-tiler/feature.js +46 -0
  114. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  115. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  116. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  117. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  118. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  119. package/dist/lib/geojson-tiler/simplify.js +68 -0
  120. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  121. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  122. package/dist/lib/geojson-tiler/tile.js +125 -0
  123. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  124. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  125. package/dist/lib/geojson-tiler/transform.js +43 -0
  126. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  127. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  128. package/dist/lib/geojson-tiler/wrap.js +86 -0
  129. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +4 -4
  130. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  131. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  132. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  133. package/dist/lib/parse-mvt.d.ts +6 -9
  134. package/dist/lib/parse-mvt.d.ts.map +1 -1
  135. package/dist/lib/parse-mvt.js +148 -98
  136. package/dist/lib/types.d.ts +48 -7
  137. package/dist/lib/types.d.ts.map +1 -1
  138. package/dist/lib/types.js +2 -2
  139. package/dist/mvt-loader.d.ts.map +1 -1
  140. package/dist/mvt-loader.js +43 -22
  141. package/dist/mvt-worker.js +903 -829
  142. package/dist/workers/mvt-worker.js +5 -4
  143. package/package.json +7 -7
  144. package/src/helpers/mapbox-util-functions.ts +2 -2
  145. package/src/index.ts +7 -0
  146. package/src/lib/binary-vector-tile/vector-tile-feature.ts +6 -1
  147. package/src/lib/geojson-tiler/LICENSE +19 -0
  148. package/src/lib/geojson-tiler/clip.ts +248 -0
  149. package/src/lib/geojson-tiler/convert.ts +158 -0
  150. package/src/lib/geojson-tiler/feature.ts +45 -0
  151. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  152. package/src/lib/geojson-tiler/simplify.ts +77 -0
  153. package/src/lib/geojson-tiler/tile.ts +185 -0
  154. package/src/lib/geojson-tiler/transform.ts +55 -0
  155. package/src/lib/geojson-tiler/wrap.ts +108 -0
  156. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  157. package/src/lib/parse-mvt.ts +136 -93
  158. package/src/lib/types.ts +53 -7
  159. package/src/mvt-loader.ts +13 -9
  160. package/dist/bundle.js.map +0 -1
  161. package/dist/helpers/binary-util-functions.js.map +0 -1
  162. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  165. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  166. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  167. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  168. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  169. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  170. package/dist/lib/parse-mvt.js.map +0 -1
  171. package/dist/lib/types.js.map +0 -1
  172. package/dist/mvt-loader.js.map +0 -1
  173. package/dist/workers/mvt-worker.js.map +0 -1
  174. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  175. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
@@ -1,4 +1,5 @@
1
- import { MVTLoader } from '../mvt-loader';
2
- import { createLoaderWorker } from '@loaders.gl/loader-utils';
3
- createLoaderWorker(MVTLoader);
4
- //# sourceMappingURL=mvt-worker.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mvt_loader_1 = require("../mvt-loader");
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ (0, loader_utils_1.createLoaderWorker)(mvt_loader_1.MVTLoader);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/mvt",
3
3
  "description": "Loader for Mapbox Vector Tiles",
4
- "version": "4.0.0-alpha.5",
4
+ "version": "4.0.0-alpha.7",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -18,8 +18,8 @@
18
18
  "Mapbox Vector Tiles"
19
19
  ],
20
20
  "types": "dist/index.d.ts",
21
- "main": "dist/index.js",
22
- "module": "dist/index.js",
21
+ "main": "dist/es5/index.js",
22
+ "module": "dist/esm/index.js",
23
23
  "sideEffects": false,
24
24
  "files": [
25
25
  "src",
@@ -32,14 +32,14 @@
32
32
  "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
33
33
  },
34
34
  "dependencies": {
35
- "@loaders.gl/gis": "4.0.0-alpha.5",
36
- "@loaders.gl/loader-utils": "4.0.0-alpha.5",
37
- "@loaders.gl/schema": "4.0.0-alpha.5",
35
+ "@loaders.gl/gis": "4.0.0-alpha.7",
36
+ "@loaders.gl/loader-utils": "4.0.0-alpha.7",
37
+ "@loaders.gl/schema": "4.0.0-alpha.7",
38
38
  "@math.gl/polygon": "^3.5.1",
39
39
  "pbf": "^3.2.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/pbf": "^3.0.2"
43
43
  },
44
- "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
44
+ "gitHead": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
45
45
  }
@@ -1,5 +1,5 @@
1
1
  import Protobuf from 'pbf';
2
- import {MvtMapboxGeometry} from '../lib/types';
2
+ import {MVTMapboxGeometry} from '../lib/types';
3
3
  import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
4
4
 
5
5
  /**
@@ -7,7 +7,7 @@ import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
7
7
  * @param rings
8
8
  * @returns polygons
9
9
  */
10
- export function classifyRings(rings: MvtMapboxGeometry) {
10
+ export function classifyRings(rings: MVTMapboxGeometry) {
11
11
  const len = rings.length;
12
12
 
13
13
  if (len <= 1) return [rings];
package/src/index.ts CHANGED
@@ -1 +1,8 @@
1
+ // loaders.gl, MIT license
2
+
1
3
  export {MVTLoader, MVTWorkerLoader} from './mvt-loader';
4
+
5
+ // GeoJSONTiler
6
+
7
+ export type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';
8
+ export {GeoJSONTiler} from './lib/geojson-tiler/geojson-tiler';
@@ -189,6 +189,11 @@ export default class VectorTileFeature {
189
189
  if (typeof options === 'function') {
190
190
  return this._toBinaryCoordinates(options);
191
191
  }
192
- return this._toBinaryCoordinates(project);
192
+ const {x, y, z} = options;
193
+ const size = this.extent * Math.pow(2, z);
194
+ const x0 = this.extent * x;
195
+ const y0 = this.extent * y;
196
+
197
+ return this._toBinaryCoordinates((data: number[]) => project(data, x0, y0, size));
193
198
  }
194
199
  }
@@ -0,0 +1,19 @@
1
+ This directory is forked from Mapbox's https://github.com/mapbox/geojson-vt under ISC License.
2
+
3
+ ```
4
+ ISC License
5
+
6
+ Copyright (c) 2015, Mapbox
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any purpose
9
+ with or without fee is hereby granted, provided that the above copyright notice
10
+ and this permission notice appear in all copies.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
14
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
18
+ THIS SOFTWARE.
19
+ ```
@@ -0,0 +1,248 @@
1
+ // loaders.gl, MIT license
2
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
3
+
4
+ import type {GeoJSONTileFeature} from './tile';
5
+ import {createFeature} from './feature';
6
+
7
+ /* eslint-disable no-continue */
8
+
9
+ /**
10
+ * Clip features between two vertical or horizontal axis-parallel lines:
11
+ * | |
12
+ * ___|___ | /
13
+ * / | \____|____/
14
+ * | |
15
+ *
16
+ * @param k1 and k2 are the line coordinates
17
+ * @param axis: 0 for x, 1 for y
18
+ * @param minAll and maxAll: minimum and maximum coordinate value for all features
19
+ */
20
+ // eslint-disable-next-line max-params, complexity, max-statements
21
+ export function clip(
22
+ features: GeoJSONTileFeature[],
23
+ scale: number,
24
+ k1: number,
25
+ k2: number,
26
+ axis,
27
+ minAll: number,
28
+ maxAll: number,
29
+ options: {lineMetrics: boolean}
30
+ ): GeoJSONTileFeature[] | null {
31
+ k1 /= scale;
32
+ k2 /= scale;
33
+
34
+ if (minAll >= k1 && maxAll < k2) {
35
+ return features;
36
+ }
37
+ // trivial accept
38
+ else if (maxAll < k1 || minAll >= k2) {
39
+ return null; // trivial reject
40
+ }
41
+
42
+ const clipped: GeoJSONTileFeature[] = [];
43
+
44
+ for (const feature of features) {
45
+ const geometry = feature.geometry;
46
+ let type = feature.type;
47
+
48
+ const min = axis === 0 ? feature.minX : feature.minY;
49
+ const max = axis === 0 ? feature.maxX : feature.maxY;
50
+
51
+ if (min >= k1 && max < k2) {
52
+ // trivial accept
53
+ clipped.push(feature);
54
+ continue;
55
+ } else if (max < k1 || min >= k2) {
56
+ // trivial reject
57
+ continue;
58
+ }
59
+
60
+ let newGeometry: number[][][] | number[][] = [];
61
+
62
+ if (type === 'Point' || type === 'MultiPoint') {
63
+ clipPoints(geometry, newGeometry, k1, k2, axis);
64
+ } else if (type === 'LineString') {
65
+ clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
66
+ } else if (type === 'MultiLineString') {
67
+ clipLines(geometry, newGeometry, k1, k2, axis, false);
68
+ } else if (type === 'Polygon') {
69
+ clipLines(geometry, newGeometry, k1, k2, axis, true);
70
+ } else if (type === 'MultiPolygon') {
71
+ for (const polygon of geometry) {
72
+ const newPolygon = [];
73
+ clipLines(polygon, newPolygon, k1, k2, axis, true);
74
+ if (newPolygon.length) {
75
+ newGeometry.push(newPolygon);
76
+ }
77
+ }
78
+ }
79
+
80
+ if (newGeometry.length) {
81
+ if (options.lineMetrics && type === 'LineString') {
82
+ for (const line of newGeometry) {
83
+ clipped.push(createFeature(feature.id, type, line, feature.tags));
84
+ }
85
+ continue;
86
+ }
87
+
88
+ if (type === 'LineString' || type === 'MultiLineString') {
89
+ if (newGeometry.length === 1) {
90
+ type = 'LineString';
91
+ // @ts-expect-error TODO - use proper GeoJSON geometry types
92
+ newGeometry = newGeometry[0];
93
+ } else {
94
+ type = 'MultiLineString';
95
+ }
96
+ }
97
+ if (type === 'Point' || type === 'MultiPoint') {
98
+ type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
99
+ }
100
+
101
+ clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
102
+ }
103
+ }
104
+
105
+ return clipped.length ? clipped : null;
106
+ }
107
+
108
+ function clipPoints(geom, newGeom, k1: number, k2: number, axis): void {
109
+ for (let i = 0; i < geom.length; i += 3) {
110
+ const a = geom[i + axis];
111
+
112
+ if (a >= k1 && a <= k2) {
113
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
114
+ }
115
+ }
116
+ }
117
+
118
+ // eslint-disable-next-line max-params, complexity, max-statements
119
+ function clipLine(
120
+ geom,
121
+ newGeom,
122
+ k1: number,
123
+ k2: number,
124
+ axis,
125
+ isPolygon: boolean,
126
+ trackMetrics: boolean
127
+ ): void {
128
+ let slice = newSlice(geom);
129
+ const intersect = axis === 0 ? intersectX : intersectY;
130
+ let len = geom.start;
131
+ let segLen;
132
+ let t;
133
+
134
+ for (let i = 0; i < geom.length - 3; i += 3) {
135
+ const ax = geom[i];
136
+ const ay = geom[i + 1];
137
+ const az = geom[i + 2];
138
+ const bx = geom[i + 3];
139
+ const by = geom[i + 4];
140
+ const a = axis === 0 ? ax : ay;
141
+ const b = axis === 0 ? bx : by;
142
+ let exited = false;
143
+
144
+ if (trackMetrics) {
145
+ segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
146
+ }
147
+
148
+ if (a < k1) {
149
+ // ---|--> | (line enters the clip region from the left)
150
+ if (b > k1) {
151
+ t = intersect(slice, ax, ay, bx, by, k1);
152
+ if (trackMetrics) {
153
+ slice.start = len + segLen * t;
154
+ }
155
+ }
156
+ } else if (a > k2) {
157
+ // | <--|--- (line enters the clip region from the right)
158
+ if (b < k2) {
159
+ t = intersect(slice, ax, ay, bx, by, k2);
160
+ if (trackMetrics) {
161
+ slice.start = len + segLen * t;
162
+ }
163
+ }
164
+ } else {
165
+ addPoint(slice, ax, ay, az);
166
+ }
167
+ if (b < k1 && a >= k1) {
168
+ // <--|--- | or <--|-----|--- (line exits the clip region on the left)
169
+ t = intersect(slice, ax, ay, bx, by, k1);
170
+ exited = true;
171
+ }
172
+ if (b > k2 && a <= k2) {
173
+ // | ---|--> or ---|-----|--> (line exits the clip region on the right)
174
+ t = intersect(slice, ax, ay, bx, by, k2);
175
+ exited = true;
176
+ }
177
+
178
+ if (!isPolygon && exited) {
179
+ if (trackMetrics) {
180
+ slice.end = len + segLen * t;
181
+ }
182
+ newGeom.push(slice);
183
+ slice = newSlice(geom);
184
+ }
185
+
186
+ if (trackMetrics) {
187
+ len += segLen;
188
+ }
189
+ }
190
+
191
+ // add the last point
192
+ let last = geom.length - 3;
193
+ const ax = geom[last];
194
+ const ay = geom[last + 1];
195
+ const az = geom[last + 2];
196
+ const a = axis === 0 ? ax : ay;
197
+ if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
198
+
199
+ // close the polygon if its endpoints are not the same after clipping
200
+ last = slice.length - 3;
201
+ if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
202
+ addPoint(slice, slice[0], slice[1], slice[2]);
203
+ }
204
+
205
+ // add the final slice
206
+ if (slice.length) {
207
+ newGeom.push(slice);
208
+ }
209
+ }
210
+
211
+ class Slice extends Array<number> {
212
+ size?: number;
213
+ start?: number;
214
+ end?: number;
215
+ }
216
+
217
+ function newSlice(line: {size: number; start: number; end: number}): Slice {
218
+ const slice: Slice = [];
219
+ slice.size = line.size;
220
+ slice.start = line.start;
221
+ slice.end = line.end;
222
+ return slice;
223
+ }
224
+
225
+ // eslint-disable-next-line max-params
226
+ function clipLines(geom, newGeom, k1: number, k2: number, axis, isPolygon: boolean): void {
227
+ for (const line of geom) {
228
+ clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
229
+ }
230
+ }
231
+
232
+ function addPoint(out: number[], x: number, y: number, z: number): void {
233
+ out.push(x, y, z);
234
+ }
235
+
236
+ // eslint-disable-next-line max-params
237
+ function intersectX(out, ax: number, ay: number, bx: number, by: number, x: number): number {
238
+ const t = (x - ax) / (bx - ax);
239
+ addPoint(out, x, ay + (by - ay) * t, 1);
240
+ return t;
241
+ }
242
+
243
+ // eslint-disable-next-line max-params
244
+ function intersectY(out, ax: number, ay: number, bx: number, by: number, y): number {
245
+ const t = (y - ay) / (by - ay);
246
+ addPoint(out, ax + (bx - ax) * t, y, 1);
247
+ return t;
248
+ }
@@ -0,0 +1,158 @@
1
+ // loaders.gl, MIT license
2
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
3
+
4
+ /* eslint-disable */
5
+ // @ts-nocheck
6
+
7
+ import type {Feature} from '@loaders.gl/schema';
8
+ import type {GeoJSONTileFeature} from './tile';
9
+
10
+ import {simplify} from './simplify';
11
+ import {createFeature} from './feature';
12
+
13
+ // converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
14
+
15
+ export function convert(data: Feature, options): GeoJSONTileFeature[] {
16
+ const features = [];
17
+ if (data.type === 'FeatureCollection') {
18
+ for (let i = 0; i < data.features.length; i++) {
19
+ convertFeature(features, data.features[i], options, i);
20
+ }
21
+ } else if (data.type === 'Feature') {
22
+ convertFeature(features, data, options);
23
+ } else {
24
+ // single geometry or a geometry collection
25
+ convertFeature(features, {geometry: data}, options);
26
+ }
27
+
28
+ return features;
29
+ }
30
+
31
+ export type ConvertFeatureOptions = {
32
+ maxZoom?: number;
33
+ tolerance: number;
34
+ extent: number;
35
+ lineMetrics: boolean;
36
+ };
37
+
38
+ function convertFeature(
39
+ features: GeoJSONTileFeature[],
40
+ geojson: Feature,
41
+ options: ConvertFeatureOptions,
42
+ index: number
43
+ ): void {
44
+ if (!geojson.geometry) {
45
+ return;
46
+ }
47
+
48
+ const coords = geojson.geometry.coordinates;
49
+ const type = geojson.geometry.type;
50
+ const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
51
+ let geometry = [];
52
+ let id = geojson.id;
53
+ if (options.promoteId) {
54
+ id = geojson.properties[options.promoteId];
55
+ } else if (options.generateId) {
56
+ id = index || 0;
57
+ }
58
+ if (type === 'Point') {
59
+ convertPoint(coords, geometry);
60
+ } else if (type === 'MultiPoint') {
61
+ for (const p of coords) {
62
+ convertPoint(p, geometry);
63
+ }
64
+ } else if (type === 'LineString') {
65
+ convertLine(coords, geometry, tolerance, false);
66
+ } else if (type === 'MultiLineString') {
67
+ if (options.lineMetrics) {
68
+ // explode into linestrings to be able to track metrics
69
+ for (const line of coords) {
70
+ geometry = [];
71
+ convertLine(line, geometry, tolerance, false);
72
+ features.push(createFeature(id, 'LineString', geometry, geojson.properties));
73
+ }
74
+ return;
75
+ } else {
76
+ convertLines(coords, geometry, tolerance, false);
77
+ }
78
+ } else if (type === 'Polygon') {
79
+ convertLines(coords, geometry, tolerance, true);
80
+ } else if (type === 'MultiPolygon') {
81
+ for (const polygon of coords) {
82
+ const newPolygon = [];
83
+ convertLines(polygon, newPolygon, tolerance, true);
84
+ geometry.push(newPolygon);
85
+ }
86
+ } else if (type === 'GeometryCollection') {
87
+ for (const singleGeometry of geojson.geometry.geometries) {
88
+ convertFeature(
89
+ features,
90
+ {
91
+ id,
92
+ geometry: singleGeometry,
93
+ properties: geojson.properties
94
+ },
95
+ options,
96
+ index
97
+ );
98
+ }
99
+ return;
100
+ } else {
101
+ throw new Error('Input data is not a valid GeoJSON object.');
102
+ }
103
+
104
+ features.push(createFeature(id, type, geometry, geojson.properties));
105
+ }
106
+
107
+ function convertPoint(coords, out): void {
108
+ out.push(projectX(coords[0]), projectY(coords[1]), 0);
109
+ }
110
+
111
+ function convertLine(ring: number[], out, tolerance: number, isPolygon: boolean): void {
112
+ let x0, y0;
113
+ let size = 0;
114
+
115
+ for (let j = 0; j < ring.length; j++) {
116
+ const x = projectX(ring[j][0]);
117
+ const y = projectY(ring[j][1]);
118
+
119
+ out.push(x, y, 0);
120
+
121
+ if (j > 0) {
122
+ if (isPolygon) {
123
+ size += (x0 * y - x * y0) / 2; // area
124
+ } else {
125
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
126
+ }
127
+ }
128
+ x0 = x;
129
+ y0 = y;
130
+ }
131
+
132
+ const last = out.length - 3;
133
+ out[2] = 1;
134
+ simplify(out, 0, last, tolerance);
135
+ out[last + 2] = 1;
136
+
137
+ out.size = Math.abs(size);
138
+ out.start = 0;
139
+ out.end = out.size;
140
+ }
141
+
142
+ function convertLines(rings: number[][], out, tolerance: number, isPolygon: boolean): void {
143
+ for (let i = 0; i < rings.length; i++) {
144
+ const geom = [];
145
+ convertLine(rings[i], geom, tolerance, isPolygon);
146
+ out.push(geom);
147
+ }
148
+ }
149
+
150
+ function projectX(x: number): number {
151
+ return x / 360 + 0.5;
152
+ }
153
+
154
+ function projectY(y: number): number {
155
+ const sin = Math.sin((y * Math.PI) / 180);
156
+ const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
157
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
158
+ }
@@ -0,0 +1,45 @@
1
+ // loaders.gl, MIT license
2
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
3
+
4
+ import {GeoJSONTileFeature} from './tile';
5
+
6
+ export function createFeature(id, type, geom, tags): GeoJSONTileFeature {
7
+ const feature: GeoJSONTileFeature = {
8
+ // eslint-disable-next-line
9
+ id: id == null ? null : id,
10
+ type,
11
+ geometry: geom,
12
+ tags,
13
+ minX: Infinity,
14
+ minY: Infinity,
15
+ maxX: -Infinity,
16
+ maxY: -Infinity
17
+ };
18
+
19
+ if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
20
+ calcLineBBox(feature, geom);
21
+ } else if (type === 'Polygon') {
22
+ // the outer ring (ie [0]) contains all inner rings
23
+ calcLineBBox(feature, geom[0]);
24
+ } else if (type === 'MultiLineString') {
25
+ for (const line of geom) {
26
+ calcLineBBox(feature, line);
27
+ }
28
+ } else if (type === 'MultiPolygon') {
29
+ for (const polygon of geom) {
30
+ // the outer ring (ie [0]) contains all inner rings
31
+ calcLineBBox(feature, polygon[0]);
32
+ }
33
+ }
34
+
35
+ return feature;
36
+ }
37
+
38
+ function calcLineBBox(feature, geom) {
39
+ for (let i = 0; i < geom.length; i += 3) {
40
+ feature.minX = Math.min(feature.minX, geom[i]);
41
+ feature.minY = Math.min(feature.minY, geom[i + 1]);
42
+ feature.maxX = Math.max(feature.maxX, geom[i]);
43
+ feature.maxY = Math.max(feature.maxY, geom[i + 1]);
44
+ }
45
+ }