setCamera method
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}) {
// flutter_map turns the map itself, clockwise; a bearing is the way the
// top of it points, which is the same angle the other way round. The map
// is flat, so there is nothing to tilt.
final rotation = (360 - camera.bearing % 360) % 360;
final zoom = camera.zoom ?? mapController.mapController.camera.zoom;
if (duration == Duration.zero) {
mapController.mapController.moveAndRotate(camera.center, zoom, rotation);
return;
}
mapController.animateTo(
customId: 'setCamera',
dest: camera.center,
zoom: zoom,
rotation: rotation,
duration: duration,
// A step of a follow is one straight stretch of road: easing in and out
// of each would make the map pulse once a second.
curve: duration == null ? null : Curves.linear,
);
}