gpt4 book ai didi

javascript - 连接两个边界框 bbox

转载 作者:行者123 更新时间:2023-12-03 02:20:13 25 4
gpt4 key购买 nike

我有两个边界框,想要创建一个包含这两个边界框的大边界框 - 将它们连接起来。

例如(turf.bbox的2个结果):

  var bboxCircles = turf.bbox({
"type": "FeatureCollection",
"name": "bboxes",
"features": circles
});

var bboxPoly = turf.bbox({
"type": "FeatureCollection",
"name": "bboxes",
"features": polygon
});

bboxCircles = [10, 5, 15, 12];
bboxPoly = [-35.9999999999999, -18.9999999999999, 35.4250000000001, 45.5000000000001];

var resBbox = bboxCircles.concat(bboxPoly).reduce(function(result, value, index, array) {
if (index % 2 === 0)
result.push(array.slice(index, index + 2));
return result;
}, []);

var bounds = new mapboxgl.LngLatBounds();
resBbox.forEach(item => {
bounds.extend(item);
});
map.fitBounds(bounds);

有草皮等的简单方法吗?谢谢

最佳答案

还有一种非常简单的方法,无需任何像 Turf 这样的库(Typescript 示例):

type BBox = [number, number, number, number];

const mergeBoundingBoxes = (boundingBoxes: BBox[]): BBox => {
let minLeft: number = 180;
let minBottom: number = 90;
let maxRight: number = -180;
let maxTop: number = -90;

boundingBoxes.forEach(([left, bottom, right, top]) => {
if (left < minLeft) minLeft = left;
if (bottom < minBottom) minBottom = bottom;
if (right > maxRight) maxRight = right;
if (top > maxTop) maxTop = top;
});

return [minLeft, minBottom, maxRight, maxTop];
};

关于javascript - 连接两个边界框 bbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49190736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com