fitCameraToGeojson method

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

Implementation

Future<void> fitCameraToGeojson({
  required GeoJsonDTO geojson,
  required MapController mapController,
  EdgeInsets? padding,
  LazyloadMapLayer? mapLazyloader,
  Function()? onEnd,
}) async {
  if (geojson.geom.polygons?.isEmpty == true) {
    return; //does nothing if there are no polygons
  }

  List<LatLng> coords = [];
  for (GeomPolygon g in geojson.geom.polygons!) {
    coords.addAll(g.outerPoints);
  }

  CameraFit fit = CameraFit.coordinates(
    coordinates: coords,
    padding: const EdgeInsets.all(40),
  );

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