@loaders.gl/mvt 4.2.0-alpha.4 → 4.2.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 (93) hide show
  1. package/dist/dist.dev.js +312 -244
  2. package/dist/dist.min.js +14 -0
  3. package/dist/helpers/binary-util-functions.d.ts +1 -1
  4. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  5. package/dist/helpers/binary-util-functions.js +99 -61
  6. package/dist/helpers/mapbox-util-functions.d.ts +2 -2
  7. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
  8. package/dist/helpers/mapbox-util-functions.js +67 -33
  9. package/dist/index.cjs +86 -68
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +8 -8
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3 -1
  14. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
  15. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  16. package/dist/lib/binary-vector-tile/vector-tile-feature.js +144 -118
  17. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -1
  18. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  19. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -38
  20. package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -1
  21. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
  22. package/dist/lib/binary-vector-tile/vector-tile.js +18 -12
  23. package/dist/lib/geojson-tiler/clip.d.ts +1 -1
  24. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
  25. package/dist/lib/geojson-tiler/clip.js +180 -142
  26. package/dist/lib/geojson-tiler/convert.d.ts +1 -1
  27. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
  28. package/dist/lib/geojson-tiler/convert.js +116 -100
  29. package/dist/lib/geojson-tiler/feature.d.ts +1 -1
  30. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
  31. package/dist/lib/geojson-tiler/feature.js +38 -29
  32. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +1 -1
  33. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
  34. package/dist/lib/geojson-tiler/geojson-tiler.js +198 -159
  35. package/dist/lib/geojson-tiler/simplify.js +60 -40
  36. package/dist/lib/geojson-tiler/tile.js +108 -88
  37. package/dist/lib/geojson-tiler/transform.d.ts +1 -1
  38. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
  39. package/dist/lib/geojson-tiler/transform.js +35 -26
  40. package/dist/lib/geojson-tiler/wrap.d.ts +1 -1
  41. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
  42. package/dist/lib/geojson-tiler/wrap.js +74 -53
  43. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
  44. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
  45. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +164 -151
  46. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -1
  47. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
  48. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -38
  49. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -1
  50. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
  51. package/dist/lib/mapbox-vector-tile/vector-tile.js +18 -12
  52. package/dist/lib/parse-mvt.d.ts +1 -1
  53. package/dist/lib/parse-mvt.d.ts.map +1 -1
  54. package/dist/lib/parse-mvt.js +142 -115
  55. package/dist/lib/parse-tilejson.js +234 -176
  56. package/dist/lib/types.js +0 -1
  57. package/dist/mvt-loader.d.ts +1 -1
  58. package/dist/mvt-loader.d.ts.map +1 -1
  59. package/dist/mvt-loader.js +42 -22
  60. package/dist/mvt-source.js +153 -139
  61. package/dist/mvt-worker.js +39 -2
  62. package/dist/tilejson-loader.d.ts +1 -1
  63. package/dist/tilejson-loader.d.ts.map +1 -1
  64. package/dist/tilejson-loader.js +32 -31
  65. package/dist/workers/mvt-worker.js +0 -1
  66. package/package.json +12 -8
  67. package/dist/helpers/binary-util-functions.js.map +0 -1
  68. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/lib/binary-vector-tile/LICENSE.txt +0 -31
  71. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  72. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  73. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  74. package/dist/lib/geojson-tiler/LICENSE +0 -19
  75. package/dist/lib/geojson-tiler/clip.js.map +0 -1
  76. package/dist/lib/geojson-tiler/convert.js.map +0 -1
  77. package/dist/lib/geojson-tiler/feature.js.map +0 -1
  78. package/dist/lib/geojson-tiler/geojson-tiler.js.map +0 -1
  79. package/dist/lib/geojson-tiler/simplify.js.map +0 -1
  80. package/dist/lib/geojson-tiler/tile.js.map +0 -1
  81. package/dist/lib/geojson-tiler/transform.js.map +0 -1
  82. package/dist/lib/geojson-tiler/wrap.js.map +0 -1
  83. package/dist/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  84. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  85. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  86. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  87. package/dist/lib/parse-mvt.js.map +0 -1
  88. package/dist/lib/parse-tilejson.js.map +0 -1
  89. package/dist/lib/types.js.map +0 -1
  90. package/dist/mvt-loader.js.map +0 -1
  91. package/dist/mvt-source.js.map +0 -1
  92. package/dist/tilejson-loader.js.map +0 -1
  93. package/dist/workers/mvt-worker.js.map +0 -1
@@ -1,172 +1,210 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
1
5
  import { createFeature } from "./feature.js";
6
+ /* eslint-disable no-continue */
7
+ /**
8
+ * Clip features between two vertical or horizontal axis-parallel lines:
9
+ * | |
10
+ * ___|___ | /
11
+ * / | \____|____/
12
+ * | |
13
+ *
14
+ * @param k1 and k2 are the line coordinates
15
+ * @param axis: 0 for x, 1 for y
16
+ * @param minAll and maxAll: minimum and maximum coordinate value for all features
17
+ */
18
+ // eslint-disable-next-line max-params, complexity, max-statements
2
19
  export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
3
- k1 /= scale;
4
- k2 /= scale;
5
- if (minAll >= k1 && maxAll < k2) {
6
- return features;
7
- } else if (maxAll < k1 || minAll >= k2) {
8
- return null;
9
- }
10
- const clipped = [];
11
- for (const feature of features) {
12
- const geometry = feature.geometry;
13
- let type = feature.type;
14
- const min = axis === 0 ? feature.minX : feature.minY;
15
- const max = axis === 0 ? feature.maxX : feature.maxY;
16
- if (min >= k1 && max < k2) {
17
- clipped.push(feature);
18
- continue;
19
- } else if (max < k1 || min >= k2) {
20
- continue;
20
+ k1 /= scale;
21
+ k2 /= scale;
22
+ if (minAll >= k1 && maxAll < k2) {
23
+ return features;
21
24
  }
22
- let newGeometry = [];
23
- if (type === 'Point' || type === 'MultiPoint') {
24
- clipPoints(geometry, newGeometry, k1, k2, axis);
25
- } else if (type === 'LineString') {
26
- clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
27
- } else if (type === 'MultiLineString') {
28
- clipLines(geometry, newGeometry, k1, k2, axis, false);
29
- } else if (type === 'Polygon') {
30
- clipLines(geometry, newGeometry, k1, k2, axis, true);
31
- } else if (type === 'MultiPolygon') {
32
- for (const polygon of geometry) {
33
- const newPolygon = [];
34
- clipLines(polygon, newPolygon, k1, k2, axis, true);
35
- if (newPolygon.length) {
36
- newGeometry.push(newPolygon);
37
- }
38
- }
25
+ // trivial accept
26
+ else if (maxAll < k1 || minAll >= k2) {
27
+ return null; // trivial reject
39
28
  }
40
- if (newGeometry.length) {
41
- if (options.lineMetrics && type === 'LineString') {
42
- for (const line of newGeometry) {
43
- clipped.push(createFeature(feature.id, type, line, feature.tags));
44
- }
45
- continue;
46
- }
47
- if (type === 'LineString' || type === 'MultiLineString') {
48
- if (newGeometry.length === 1) {
49
- type = 'LineString';
50
- newGeometry = newGeometry[0];
51
- } else {
52
- type = 'MultiLineString';
53
- }
54
- }
55
- if (type === 'Point' || type === 'MultiPoint') {
56
- type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
57
- }
58
- clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
29
+ const clipped = [];
30
+ for (const feature of features) {
31
+ const geometry = feature.geometry;
32
+ let type = feature.type;
33
+ const min = axis === 0 ? feature.minX : feature.minY;
34
+ const max = axis === 0 ? feature.maxX : feature.maxY;
35
+ if (min >= k1 && max < k2) {
36
+ // trivial accept
37
+ clipped.push(feature);
38
+ continue;
39
+ }
40
+ else if (max < k1 || min >= k2) {
41
+ // trivial reject
42
+ continue;
43
+ }
44
+ let newGeometry = [];
45
+ if (type === 'Point' || type === 'MultiPoint') {
46
+ clipPoints(geometry, newGeometry, k1, k2, axis);
47
+ }
48
+ else if (type === 'LineString') {
49
+ clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
50
+ }
51
+ else if (type === 'MultiLineString') {
52
+ clipLines(geometry, newGeometry, k1, k2, axis, false);
53
+ }
54
+ else if (type === 'Polygon') {
55
+ clipLines(geometry, newGeometry, k1, k2, axis, true);
56
+ }
57
+ else if (type === 'MultiPolygon') {
58
+ for (const polygon of geometry) {
59
+ const newPolygon = [];
60
+ clipLines(polygon, newPolygon, k1, k2, axis, true);
61
+ if (newPolygon.length) {
62
+ newGeometry.push(newPolygon);
63
+ }
64
+ }
65
+ }
66
+ if (newGeometry.length) {
67
+ if (options.lineMetrics && type === 'LineString') {
68
+ for (const line of newGeometry) {
69
+ clipped.push(createFeature(feature.id, type, line, feature.tags));
70
+ }
71
+ continue;
72
+ }
73
+ if (type === 'LineString' || type === 'MultiLineString') {
74
+ if (newGeometry.length === 1) {
75
+ type = 'LineString';
76
+ // @ts-expect-error TODO - use proper GeoJSON geometry types
77
+ newGeometry = newGeometry[0];
78
+ }
79
+ else {
80
+ type = 'MultiLineString';
81
+ }
82
+ }
83
+ if (type === 'Point' || type === 'MultiPoint') {
84
+ type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
85
+ }
86
+ clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
87
+ }
59
88
  }
60
- }
61
- return clipped.length ? clipped : null;
89
+ return clipped.length ? clipped : null;
62
90
  }
63
91
  function clipPoints(geom, newGeom, k1, k2, axis) {
64
- for (let i = 0; i < geom.length; i += 3) {
65
- const a = geom[i + axis];
66
- if (a >= k1 && a <= k2) {
67
- addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
92
+ for (let i = 0; i < geom.length; i += 3) {
93
+ const a = geom[i + axis];
94
+ if (a >= k1 && a <= k2) {
95
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
96
+ }
68
97
  }
69
- }
70
98
  }
99
+ // eslint-disable-next-line max-params, complexity, max-statements
71
100
  function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
72
- let slice = newSlice(geom);
73
- const intersect = axis === 0 ? intersectX : intersectY;
74
- let len = geom.start;
75
- let segLen;
76
- let t;
77
- for (let i = 0; i < geom.length - 3; i += 3) {
78
- const ax = geom[i];
79
- const ay = geom[i + 1];
80
- const az = geom[i + 2];
81
- const bx = geom[i + 3];
82
- const by = geom[i + 4];
83
- const a = axis === 0 ? ax : ay;
84
- const b = axis === 0 ? bx : by;
85
- let exited = false;
86
- if (trackMetrics) {
87
- segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
88
- }
89
- if (a < k1) {
90
- if (b > k1) {
91
- t = intersect(slice, ax, ay, bx, by, k1);
101
+ let slice = newSlice(geom);
102
+ const intersect = axis === 0 ? intersectX : intersectY;
103
+ let len = geom.start;
104
+ let segLen;
105
+ let t;
106
+ for (let i = 0; i < geom.length - 3; i += 3) {
107
+ const ax = geom[i];
108
+ const ay = geom[i + 1];
109
+ const az = geom[i + 2];
110
+ const bx = geom[i + 3];
111
+ const by = geom[i + 4];
112
+ const a = axis === 0 ? ax : ay;
113
+ const b = axis === 0 ? bx : by;
114
+ let exited = false;
92
115
  if (trackMetrics) {
93
- slice.start = len + segLen * t;
116
+ segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
117
+ }
118
+ if (a < k1) {
119
+ // ---|--> | (line enters the clip region from the left)
120
+ if (b > k1) {
121
+ t = intersect(slice, ax, ay, bx, by, k1);
122
+ if (trackMetrics) {
123
+ slice.start = len + segLen * t;
124
+ }
125
+ }
126
+ }
127
+ else if (a > k2) {
128
+ // | <--|--- (line enters the clip region from the right)
129
+ if (b < k2) {
130
+ t = intersect(slice, ax, ay, bx, by, k2);
131
+ if (trackMetrics) {
132
+ slice.start = len + segLen * t;
133
+ }
134
+ }
135
+ }
136
+ else {
137
+ addPoint(slice, ax, ay, az);
138
+ }
139
+ if (b < k1 && a >= k1) {
140
+ // <--|--- | or <--|-----|--- (line exits the clip region on the left)
141
+ t = intersect(slice, ax, ay, bx, by, k1);
142
+ exited = true;
143
+ }
144
+ if (b > k2 && a <= k2) {
145
+ // | ---|--> or ---|-----|--> (line exits the clip region on the right)
146
+ t = intersect(slice, ax, ay, bx, by, k2);
147
+ exited = true;
148
+ }
149
+ if (!isPolygon && exited) {
150
+ if (trackMetrics) {
151
+ slice.end = len + segLen * t;
152
+ }
153
+ newGeom.push(slice);
154
+ slice = newSlice(geom);
94
155
  }
95
- }
96
- } else if (a > k2) {
97
- if (b < k2) {
98
- t = intersect(slice, ax, ay, bx, by, k2);
99
156
  if (trackMetrics) {
100
- slice.start = len + segLen * t;
157
+ len += segLen;
101
158
  }
102
- }
103
- } else {
104
- addPoint(slice, ax, ay, az);
105
- }
106
- if (b < k1 && a >= k1) {
107
- t = intersect(slice, ax, ay, bx, by, k1);
108
- exited = true;
109
- }
110
- if (b > k2 && a <= k2) {
111
- t = intersect(slice, ax, ay, bx, by, k2);
112
- exited = true;
113
159
  }
114
- if (!isPolygon && exited) {
115
- if (trackMetrics) {
116
- slice.end = len + segLen * t;
117
- }
118
- newGeom.push(slice);
119
- slice = newSlice(geom);
160
+ // add the last point
161
+ let last = geom.length - 3;
162
+ const ax = geom[last];
163
+ const ay = geom[last + 1];
164
+ const az = geom[last + 2];
165
+ const a = axis === 0 ? ax : ay;
166
+ if (a >= k1 && a <= k2)
167
+ addPoint(slice, ax, ay, az);
168
+ // close the polygon if its endpoints are not the same after clipping
169
+ last = slice.length - 3;
170
+ if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
171
+ addPoint(slice, slice[0], slice[1], slice[2]);
120
172
  }
121
- if (trackMetrics) {
122
- len += segLen;
173
+ // add the final slice
174
+ if (slice.length) {
175
+ newGeom.push(slice);
123
176
  }
124
- }
125
- let last = geom.length - 3;
126
- const ax = geom[last];
127
- const ay = geom[last + 1];
128
- const az = geom[last + 2];
129
- const a = axis === 0 ? ax : ay;
130
- if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
131
- last = slice.length - 3;
132
- if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
133
- addPoint(slice, slice[0], slice[1], slice[2]);
134
- }
135
- if (slice.length) {
136
- newGeom.push(slice);
137
- }
138
177
  }
139
178
  class Slice extends Array {
140
- constructor() {
141
- super(...arguments);
142
- this.size = void 0;
143
- this.start = void 0;
144
- this.end = void 0;
145
- }
179
+ size;
180
+ start;
181
+ end;
146
182
  }
147
183
  function newSlice(line) {
148
- const slice = [];
149
- slice.size = line.size;
150
- slice.start = line.start;
151
- slice.end = line.end;
152
- return slice;
184
+ const slice = [];
185
+ slice.size = line.size;
186
+ slice.start = line.start;
187
+ slice.end = line.end;
188
+ return slice;
153
189
  }
190
+ // eslint-disable-next-line max-params
154
191
  function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
155
- for (const line of geom) {
156
- clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
157
- }
192
+ for (const line of geom) {
193
+ clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
194
+ }
158
195
  }
159
196
  function addPoint(out, x, y, z) {
160
- out.push(x, y, z);
197
+ out.push(x, y, z);
161
198
  }
199
+ // eslint-disable-next-line max-params
162
200
  function intersectX(out, ax, ay, bx, by, x) {
163
- const t = (x - ax) / (bx - ax);
164
- addPoint(out, x, ay + (by - ay) * t, 1);
165
- return t;
201
+ const t = (x - ax) / (bx - ax);
202
+ addPoint(out, x, ay + (by - ay) * t, 1);
203
+ return t;
166
204
  }
205
+ // eslint-disable-next-line max-params
167
206
  function intersectY(out, ax, ay, bx, by, y) {
168
- const t = (y - ay) / (by - ay);
169
- addPoint(out, ax + (bx - ax) * t, y, 1);
170
- return t;
207
+ const t = (y - ay) / (by - ay);
208
+ addPoint(out, ax + (bx - ax) * t, y, 1);
209
+ return t;
171
210
  }
172
- //# sourceMappingURL=clip.js.map
@@ -1,5 +1,5 @@
1
1
  import type { Feature } from '@loaders.gl/schema';
2
- import type { GeoJSONTileFeature } from './tile';
2
+ import type { GeoJSONTileFeature } from "./tile.js";
3
3
  export declare function convert(data: Feature, options: any): GeoJSONTileFeature[];
4
4
  export type ConvertFeatureOptions = {
5
5
  maxZoom?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcpE;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcpE;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -1,116 +1,132 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
1
5
  import { simplify } from "./simplify.js";
2
6
  import { createFeature } from "./feature.js";
7
+ // converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
3
8
  export function convert(data, options) {
4
- const features = [];
5
- if (data.type === 'FeatureCollection') {
6
- for (let i = 0; i < data.features.length; i++) {
7
- convertFeature(features, data.features[i], options, i);
8
- }
9
- } else if (data.type === 'Feature') {
10
- convertFeature(features, data, options);
11
- } else {
12
- convertFeature(features, {
13
- geometry: data
14
- }, options);
15
- }
16
- return features;
9
+ const features = [];
10
+ if (data.type === 'FeatureCollection') {
11
+ for (let i = 0; i < data.features.length; i++) {
12
+ convertFeature(features, data.features[i], options, i);
13
+ }
14
+ }
15
+ else if (data.type === 'Feature') {
16
+ convertFeature(features, data, options);
17
+ }
18
+ else {
19
+ // single geometry or a geometry collection
20
+ convertFeature(features, { geometry: data }, options);
21
+ }
22
+ return features;
17
23
  }
18
24
  function convertFeature(features, geojson, options, index) {
19
- if (!geojson.geometry) {
20
- return;
21
- }
22
- const coords = geojson.geometry.coordinates;
23
- const type = geojson.geometry.type;
24
- const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
25
- let geometry = [];
26
- let id = geojson.id;
27
- if (options.promoteId) {
28
- id = geojson.properties[options.promoteId];
29
- } else if (options.generateId) {
30
- id = index || 0;
31
- }
32
- if (type === 'Point') {
33
- convertPoint(coords, geometry);
34
- } else if (type === 'MultiPoint') {
35
- for (const p of coords) {
36
- convertPoint(p, geometry);
37
- }
38
- } else if (type === 'LineString') {
39
- convertLine(coords, geometry, tolerance, false);
40
- } else if (type === 'MultiLineString') {
41
- if (options.lineMetrics) {
42
- for (const line of coords) {
43
- geometry = [];
44
- convertLine(line, geometry, tolerance, false);
45
- features.push(createFeature(id, 'LineString', geometry, geojson.properties));
46
- }
47
- return;
48
- } else {
49
- convertLines(coords, geometry, tolerance, false);
50
- }
51
- } else if (type === 'Polygon') {
52
- convertLines(coords, geometry, tolerance, true);
53
- } else if (type === 'MultiPolygon') {
54
- for (const polygon of coords) {
55
- const newPolygon = [];
56
- convertLines(polygon, newPolygon, tolerance, true);
57
- geometry.push(newPolygon);
58
- }
59
- } else if (type === 'GeometryCollection') {
60
- for (const singleGeometry of geojson.geometry.geometries) {
61
- convertFeature(features, {
62
- id,
63
- geometry: singleGeometry,
64
- properties: geojson.properties
65
- }, options, index);
66
- }
67
- return;
68
- } else {
69
- throw new Error('Input data is not a valid GeoJSON object.');
70
- }
71
- features.push(createFeature(id, type, geometry, geojson.properties));
25
+ if (!geojson.geometry) {
26
+ return;
27
+ }
28
+ const coords = geojson.geometry.coordinates;
29
+ const type = geojson.geometry.type;
30
+ const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
31
+ let geometry = [];
32
+ let id = geojson.id;
33
+ if (options.promoteId) {
34
+ id = geojson.properties[options.promoteId];
35
+ }
36
+ else if (options.generateId) {
37
+ id = index || 0;
38
+ }
39
+ if (type === 'Point') {
40
+ convertPoint(coords, geometry);
41
+ }
42
+ else if (type === 'MultiPoint') {
43
+ for (const p of coords) {
44
+ convertPoint(p, geometry);
45
+ }
46
+ }
47
+ else if (type === 'LineString') {
48
+ convertLine(coords, geometry, tolerance, false);
49
+ }
50
+ else if (type === 'MultiLineString') {
51
+ if (options.lineMetrics) {
52
+ // explode into linestrings to be able to track metrics
53
+ for (const line of coords) {
54
+ geometry = [];
55
+ convertLine(line, geometry, tolerance, false);
56
+ features.push(createFeature(id, 'LineString', geometry, geojson.properties));
57
+ }
58
+ return;
59
+ }
60
+ else {
61
+ convertLines(coords, geometry, tolerance, false);
62
+ }
63
+ }
64
+ else if (type === 'Polygon') {
65
+ convertLines(coords, geometry, tolerance, true);
66
+ }
67
+ else if (type === 'MultiPolygon') {
68
+ for (const polygon of coords) {
69
+ const newPolygon = [];
70
+ convertLines(polygon, newPolygon, tolerance, true);
71
+ geometry.push(newPolygon);
72
+ }
73
+ }
74
+ else if (type === 'GeometryCollection') {
75
+ for (const singleGeometry of geojson.geometry.geometries) {
76
+ convertFeature(features, {
77
+ id,
78
+ geometry: singleGeometry,
79
+ properties: geojson.properties
80
+ }, options, index);
81
+ }
82
+ return;
83
+ }
84
+ else {
85
+ throw new Error('Input data is not a valid GeoJSON object.');
86
+ }
87
+ features.push(createFeature(id, type, geometry, geojson.properties));
72
88
  }
73
89
  function convertPoint(coords, out) {
74
- out.push(projectX(coords[0]), projectY(coords[1]), 0);
90
+ out.push(projectX(coords[0]), projectY(coords[1]), 0);
75
91
  }
76
92
  function convertLine(ring, out, tolerance, isPolygon) {
77
- let x0, y0;
78
- let size = 0;
79
- for (let j = 0; j < ring.length; j++) {
80
- const x = projectX(ring[j][0]);
81
- const y = projectY(ring[j][1]);
82
- out.push(x, y, 0);
83
- if (j > 0) {
84
- if (isPolygon) {
85
- size += (x0 * y - x * y0) / 2;
86
- } else {
87
- size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
88
- }
89
- }
90
- x0 = x;
91
- y0 = y;
92
- }
93
- const last = out.length - 3;
94
- out[2] = 1;
95
- simplify(out, 0, last, tolerance);
96
- out[last + 2] = 1;
97
- out.size = Math.abs(size);
98
- out.start = 0;
99
- out.end = out.size;
93
+ let x0, y0;
94
+ let size = 0;
95
+ for (let j = 0; j < ring.length; j++) {
96
+ const x = projectX(ring[j][0]);
97
+ const y = projectY(ring[j][1]);
98
+ out.push(x, y, 0);
99
+ if (j > 0) {
100
+ if (isPolygon) {
101
+ size += (x0 * y - x * y0) / 2; // area
102
+ }
103
+ else {
104
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
105
+ }
106
+ }
107
+ x0 = x;
108
+ y0 = y;
109
+ }
110
+ const last = out.length - 3;
111
+ out[2] = 1;
112
+ simplify(out, 0, last, tolerance);
113
+ out[last + 2] = 1;
114
+ out.size = Math.abs(size);
115
+ out.start = 0;
116
+ out.end = out.size;
100
117
  }
101
118
  function convertLines(rings, out, tolerance, isPolygon) {
102
- for (let i = 0; i < rings.length; i++) {
103
- const geom = [];
104
- convertLine(rings[i], geom, tolerance, isPolygon);
105
- out.push(geom);
106
- }
119
+ for (let i = 0; i < rings.length; i++) {
120
+ const geom = [];
121
+ convertLine(rings[i], geom, tolerance, isPolygon);
122
+ out.push(geom);
123
+ }
107
124
  }
108
125
  function projectX(x) {
109
- return x / 360 + 0.5;
126
+ return x / 360 + 0.5;
110
127
  }
111
128
  function projectY(y) {
112
- const sin = Math.sin(y * Math.PI / 180);
113
- const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
114
- return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
129
+ const sin = Math.sin((y * Math.PI) / 180);
130
+ const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
131
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
115
132
  }
116
- //# sourceMappingURL=convert.js.map
@@ -1,3 +1,3 @@
1
- import { GeoJSONTileFeature } from './tile';
1
+ import { GeoJSONTileFeature } from "./tile.js";
2
2
  export declare function createFeature(id: any, type: any, geom: any, tags: any): GeoJSONTileFeature;
3
3
  //# sourceMappingURL=feature.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}
1
+ {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,kBAAe;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}