GeoBox constructor
A geographic bounding box with west, south, east and north values.
West and east represents geographic longitude coordinates values. South and north represents geographic latitude coordinates values.
For geographic bounding boxes (west-longitude, south-latitude) position
represents the most southwesterly point, and
(east-longitude, north-latitude) position represents the more
northeasterly point. When a bounding box spans the antimeridian, it's
possible that "min-longitude" (west) is larger than "max-longitude" (east)
as a number. See also RFC 7946 chapter 5 about bounding boxes in GeoJSON
for reference.
The longitudal limit values (west and east) are normalized using the
formula (lon + 180.0) % 360.0 - 180.0 if outside the range
[-180.0, 180.0]. If west > east then the bounding box is spanning
the antimeridian.
Latitudal limit values (south and north) are clipped to the range
[-90.0, 90.0]. It's required that south <= north (however this is
not asserted).
Optional minElev and maxElev for 3D boxes, and minM and maxM for
measured boxes can be provided too.
Examples:
// a 2D box (lon: 10.0 .. 15.0, lat: 20.0 .. 25.0)
GeoBox(west: 10.0, south: 20.0, east: 15.0, north: 25.0);
// a 3D box (lon: 10.0 .. 15.0, lat: 20.0 .. 25.0, elev: 30.0 .. 35.0)
const GeoBox(
west: 10.0, south: 20.0, minElev: 30.0,
east: 15.0, north: 25.0, maxElev: 35.0,
);
// a measured 2D box (lon: 10.0..15.0, lat: 20.0..25.0, m: 40.0..45.0)
const GeoBox(
west: 10.0, south: 20.0, minM: 40.0,
east: 15.0, north: 25.0, maxM: 45.0,
);
// a measured 3D box
// (lon: 10.0..15.0, lat: 20.0..25.0, elev: 30.0..35.0, m: 40.0..45.0)
const GeoBox(
west: 10.0, south: 20.0, minElev: 30.0, minM: 40.0,
east: 15.0, north: 25.0, maxElev: 35.0, maxM: 45.0,
);
Implementation
const GeoBox({
required double west,
required double south,
double? minElev,
double? minM,
required double east,
required double north,
double? maxElev,
double? maxM,
}) : _west = west >= -180.0 && west <= 180.0
? west
: (west + 180.0) % 360.0 - 180.0,
_south = south < -90.0 ? -90.0 : (south > 90.0 ? 90.0 : south),
_minElev = minElev,
_minM = minM,
_east = east >= -180.0 && east <= 180.0
? east
: (east + 180.0) % 360.0 - 180.0,
_north = north < -90.0 ? -90.0 : (north > 90.0 ? 90.0 : north),
_maxElev = maxElev,
_maxM = maxM;