setCamera method

  1. @override
void setCamera(
  1. MapViewCamera camera, {
  2. Duration? duration,
})
override

Puts the camera at camera: its centre, and also which way it faces and how far it leans.

With a duration the camera travels there over that time; called once a second with a one-second duration it follows a moving position without a jump between fixes. With none it uses the provider's own animation, and with Duration.zero it is there at once.

Attribution applies as it does to fitBounds, so a host that follows a position can tell its own steps from the user taking the map over.

Implementation

@override
void setCamera(MapViewCamera camera, {Duration? duration}) async {
  // One read of the completer, for the reason [moveCamera] gives.
  final map = await controller;
  final options = CameraOptions(
    center: getPoint(camera.center),
    zoom: camera.zoom ?? (await map.getCameraState()).zoom,
    bearing: camera.bearing,
    pitch: camera.tilt,
    padding: MbxEdgeInsets(
      top: padding.top,
      bottom: padding.bottom,
      left: padding.left,
      right: padding.right,
    ),
  );

  beginProgrammaticMove();
  if (duration == null || duration == Duration.zero) {
    map.setCamera(options);
  } else {
    map.easeTo(
      options,
      MapAnimationOptions(duration: duration.inMilliseconds),
    );
  }
}