computeBounds function
Implementation
CameraTargetBounds? computeBounds(
List? locations, MapItem Function(dynamic) mapDataAdapter) {
CameraTargetBounds? targetBounds;
double? leastLat = double.infinity;
double? greatestLat = double.negativeInfinity;
double? leastLong = double.infinity;
double? greatestLong = double.negativeInfinity;
if (locations != null && locations.isNotEmpty) {
for (final item in locations) {
MapItem location = mapDataAdapter(item);
if (location.latitude < leastLat!) {
leastLat = location.latitude;
}
if (location.latitude > greatestLat!) {
greatestLat = location.latitude;
}
if (location.longitude < leastLong!) {
leastLong = location.longitude;
}
if (location.longitude > greatestLong!) {
greatestLong = location.longitude;
}
}
double offset = locations.length > 1 ? MapsConstants.mapPinOffset : 0;
LatLngBounds bounds = LatLngBounds(
southwest: LatLng(leastLat! - offset, leastLong! - offset),
northeast: LatLng(greatestLat! + offset, greatestLong! + offset));
targetBounds = CameraTargetBounds(bounds);
}
return targetBounds;
}