@performant-software/geospatial 3.1.22-beta.2 → 3.1.22-beta.4
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.
- package/package.json +1 -1
- package/src/utils/Map.js +45 -1
- package/types/utils/Map.js.flow +45 -1
package/package.json
CHANGED
package/src/utils/Map.js
CHANGED
|
@@ -4,9 +4,15 @@ import { WarpedMapLayer } from '@allmaps/maplibre';
|
|
|
4
4
|
import {
|
|
5
5
|
bbox,
|
|
6
6
|
bboxPolygon,
|
|
7
|
+
bearing,
|
|
8
|
+
bezierSpline,
|
|
7
9
|
buffer,
|
|
10
|
+
destination,
|
|
11
|
+
distance,
|
|
8
12
|
feature,
|
|
9
|
-
featureCollection
|
|
13
|
+
featureCollection,
|
|
14
|
+
lineString,
|
|
15
|
+
midpoint
|
|
10
16
|
} from '@turf/turf';
|
|
11
17
|
import _ from 'underscore';
|
|
12
18
|
import circle from '@turf/circle';
|
|
@@ -202,11 +208,49 @@ const validateCoordinates = (coordinates) => {
|
|
|
202
208
|
return valid;
|
|
203
209
|
};
|
|
204
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Returns a GeoJSON FeatureCollection of LineStrings (arcs) for the passed coordinates.
|
|
213
|
+
*
|
|
214
|
+
* @param coordinates
|
|
215
|
+
* @param options
|
|
216
|
+
*
|
|
217
|
+
* @returns {FeatureCollection<LineString, GeoJsonProperties>}
|
|
218
|
+
*/
|
|
219
|
+
const toArcs = (coordinates, options = {}) => {
|
|
220
|
+
const { curvature = 0.2 } = options;
|
|
221
|
+
const features = [];
|
|
222
|
+
|
|
223
|
+
for (let i = 0; i < coordinates.length - 1; i += 1) {
|
|
224
|
+
const start = coordinates[i];
|
|
225
|
+
const end = coordinates[i + 1];
|
|
226
|
+
|
|
227
|
+
const d = distance(start, end);
|
|
228
|
+
const m = midpoint(start, end);
|
|
229
|
+
const b = bearing(start, end);
|
|
230
|
+
|
|
231
|
+
const offsetBearing = b + 90 > 180 ? b + 90 - 360 : b + 90;
|
|
232
|
+
const dest = destination(m, d * curvature, offsetBearing);
|
|
233
|
+
|
|
234
|
+
const line = lineString([start, dest.geometry.coordinates, end]);
|
|
235
|
+
const arc = bezierSpline(line);
|
|
236
|
+
|
|
237
|
+
arc.properties = {
|
|
238
|
+
...arc.properties,
|
|
239
|
+
index: i
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
features.push(arc);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return featureCollection(features);
|
|
246
|
+
};
|
|
247
|
+
|
|
205
248
|
export default {
|
|
206
249
|
addGeoreferenceLayer,
|
|
207
250
|
toCertaintyCircle,
|
|
208
251
|
getBoundingBox,
|
|
209
252
|
removeLayer,
|
|
253
|
+
toArcs,
|
|
210
254
|
toFeature,
|
|
211
255
|
toFeatureCollection,
|
|
212
256
|
validateBoundingBox,
|
package/types/utils/Map.js.flow
CHANGED
|
@@ -4,9 +4,15 @@ import { WarpedMapLayer } from '@allmaps/maplibre';
|
|
|
4
4
|
import {
|
|
5
5
|
bbox,
|
|
6
6
|
bboxPolygon,
|
|
7
|
+
bearing,
|
|
8
|
+
bezierSpline,
|
|
7
9
|
buffer,
|
|
10
|
+
destination,
|
|
11
|
+
distance,
|
|
8
12
|
feature,
|
|
9
|
-
featureCollection
|
|
13
|
+
featureCollection,
|
|
14
|
+
lineString,
|
|
15
|
+
midpoint
|
|
10
16
|
} from '@turf/turf';
|
|
11
17
|
import _ from 'underscore';
|
|
12
18
|
import circle from '@turf/circle';
|
|
@@ -202,11 +208,49 @@ const validateCoordinates = (coordinates) => {
|
|
|
202
208
|
return valid;
|
|
203
209
|
};
|
|
204
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Returns a GeoJSON FeatureCollection of LineStrings (arcs) for the passed coordinates.
|
|
213
|
+
*
|
|
214
|
+
* @param coordinates
|
|
215
|
+
* @param options
|
|
216
|
+
*
|
|
217
|
+
* @returns {FeatureCollection<LineString, GeoJsonProperties>}
|
|
218
|
+
*/
|
|
219
|
+
const toArcs = (coordinates, options = {}) => {
|
|
220
|
+
const { curvature = 0.2 } = options;
|
|
221
|
+
const features = [];
|
|
222
|
+
|
|
223
|
+
for (let i = 0; i < coordinates.length - 1; i += 1) {
|
|
224
|
+
const start = coordinates[i];
|
|
225
|
+
const end = coordinates[i + 1];
|
|
226
|
+
|
|
227
|
+
const d = distance(start, end);
|
|
228
|
+
const m = midpoint(start, end);
|
|
229
|
+
const b = bearing(start, end);
|
|
230
|
+
|
|
231
|
+
const offsetBearing = b + 90 > 180 ? b + 90 - 360 : b + 90;
|
|
232
|
+
const dest = destination(m, d * curvature, offsetBearing);
|
|
233
|
+
|
|
234
|
+
const line = lineString([start, dest.geometry.coordinates, end]);
|
|
235
|
+
const arc = bezierSpline(line);
|
|
236
|
+
|
|
237
|
+
arc.properties = {
|
|
238
|
+
...arc.properties,
|
|
239
|
+
index: i
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
features.push(arc);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return featureCollection(features);
|
|
246
|
+
};
|
|
247
|
+
|
|
205
248
|
export default {
|
|
206
249
|
addGeoreferenceLayer,
|
|
207
250
|
toCertaintyCircle,
|
|
208
251
|
getBoundingBox,
|
|
209
252
|
removeLayer,
|
|
253
|
+
toArcs,
|
|
210
254
|
toFeature,
|
|
211
255
|
toFeatureCollection,
|
|
212
256
|
validateBoundingBox,
|