I have two bounding boxes and want to create a big one that includes this 2 – join them.
For example(2 results of the turf.bbox):
JavaScript
x
27
27
1
var bboxCircles = turf.bbox({
2
"type": "FeatureCollection",
3
"name": "bboxes",
4
"features": circles
5
});
6
7
var bboxPoly = turf.bbox({
8
"type": "FeatureCollection",
9
"name": "bboxes",
10
"features": polygon
11
});
12
13
bboxCircles = [10, 5, 15, 12];
14
bboxPoly = [-35.9999999999999, -18.9999999999999, 35.4250000000001, 45.5000000000001];
15
16
var resBbox = bboxCircles.concat(bboxPoly).reduce(function(result, value, index, array) {
17
if (index % 2 === 0)
18
result.push(array.slice(index, index + 2));
19
return result;
20
}, []);
21
22
var bounds = new mapboxgl.LngLatBounds();
23
resBbox.forEach(item => {
24
bounds.extend(item);
25
});
26
map.fitBounds(bounds);
27
Is there an easy way with turf etc.? thanks
Advertisement
Answer
Maybe this could be solved using a combination of bboxPolygon
, combine
and bbox
. bboxPolygon
converts a bounding box to a Polygon feature.
JavaScript
1
2
1
var resBbox = turf.bbox(turf.bboxPolygon(bboxCircles).combine(turf.bboxPolygon(bboxPoly)));
2