boundingBox property

  1. @override
RectangleGeographicArea get boundingBox
override

Get the bounding box. This is the smallest rectangle that can be drawn around the area such that it surrounds this geographic area completely.

If the area is bigger than what is allowed in the WGS 84 coordinate system, the rectangle is truncated to valid WGS 84 coordinate values. The RectangleGeographicArea is always aligned with parallels and meridians.

Returns

Implementation

@override
RectangleGeographicArea get boundingBox {
  if (coordinates.isEmpty) {
    return RectangleGeographicArea(
      topLeft: Coordinates(),
      bottomRight: Coordinates(),
    );
  }

  late double left, right, top, bottom;
  left = right = coordinates.first.longitude;
  top = bottom = coordinates.first.latitude;

  for (final Coordinates coordinate in coordinates) {
    right = max(right, coordinate.longitude);
    bottom = min(bottom, coordinate.latitude);
    left = min(left, coordinate.longitude);
    top = max(top, coordinate.latitude);
  }

  return RectangleGeographicArea(
    topLeft: Coordinates(longitude: left, latitude: top),
    bottomRight: Coordinates(longitude: right, latitude: bottom),
  );
}