加入两个边界框bbox

时间:2018-03-09 09:40:03

标签: javascript gis mapbox turfjs

我有两个边界框,想要创建一个包含这个2的大框 - 加入它们。

例如(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);

草坪等有简单的方法吗? 感谢

1 个答案:

答案 0 :(得分:1)

也许可以使用bboxPolygoncombinebbox的组合来解决这个问题。 bboxPolygon将边界框转换为多边形要素。

var resBbox = turf.bbox(turf.bboxPolygon(bboxCircles).combine(turf.bboxPolygon(bboxPoly)));