fitCameraToGeojsonList static method

Future<void> fitCameraToGeojsonList({
  1. required List<GeoJsonDTO> geojsons,
  2. required MapController mapController,
  3. EdgeInsets? padding,
  4. LazyloadMapLayer? mapLazyloader,
  5. dynamic onEnd()?,
})

Implementation

static Future<void> fitCameraToGeojsonList({
  required List<GeoJsonDTO> geojsons,
  required MapController mapController,
  EdgeInsets? padding,
  LazyloadMapLayer? mapLazyloader,
  Function()? onEnd,
}) async {

  if (geojsons.isEmpty == true) return; //secure

  List<LatLng> coords = [];

  for (GeoJsonDTO geojson in geojsons) {
    if (geojson.geom.polygons != null) {
      for(var p in geojson.geom.polygons!) {
        coords.addAll(p.outerPoints);
      }
    }
  }

  if (coords.isEmpty == true) return; //secure

  CameraFit fit = CameraFit.coordinates(
    coordinates: coords,
    padding: padding ?? EdgeInsets.all(__defaultPadding),
  );

  if(mapLazyloader != null) mapLazyloader.clearLastRefreshedBounds();
  mapController.fitCamera(fit);
  if(onEnd != null) onEnd();
}