bboxPolygon function

Feature<Polygon> bboxPolygon(
  1. BBox bbox, {
  2. Map<String, dynamic> properties = const {},
  3. dynamic id,
})

Takes a Bbox and returns an equivalent Feature<Polygon>.

var bbox = Bbox(0, 0, 10, 10);
var poly = bboxPolygon(bbox);
//addToMap
var addToMap = [poly]

Implementation

Feature<Polygon> bboxPolygon(BBox bbox,
    {Map<String, dynamic> properties = const {}, dynamic id}) {
  var west = bbox[0]!;
  var south = bbox[1]!;
  var east = bbox[2]!;
  var north = bbox[3]!;

  if (bbox.length == 6) {
    throw Exception("turf/bbox-polygon does not support BBox with 6 positions");
  }

  var lowLeft = [west, south];
  var topLeft = [west, north];
  var topRight = [east, north];
  var lowRight = [east, south];

  return Feature(
    bbox: bbox.clone(),
    properties: properties,
    id: id,
    geometry: Polygon(
      coordinates: [
        [
          Position.of(lowLeft),
          Position.of(lowRight),
          Position.of(topRight),
          Position.of(topLeft),
          Position.of(lowLeft)
        ]
      ],
    ),
  );
}