The MapCamera
object describes the map's current viewport. It does not provide methods to change it: that is the responsibility of a MapController
.
The MapCamera
object also provides access to some other helpful methods that depend on it, such as pointToLatLng
& latLngToPoint
.
FlutterMap
ChildTo get the camera from within the context of a FlutterMap
widget, use MapCamera.of(context)
.
Calling this method in a build
method will cause the widget to automatically rebuild when the MapCamera
changes. See #2.-hooking-into-inherited-state for more information.
If this behaviour is unwanted, use #single-time instead.
If this throws a StateError
, try wrapping the concerned widget in a Builder
, to ensure the FlutterMap
widget is parenting the BuildContext
. If this has no effect, use #usage-outside-of-fluttermap instead.
FlutterMap
To get the camera from outside the context of the FlutterMap
widget, you'll need to setup a MapController
first: see Control Camera > #usage-outside-of-fluttermap.
Then, use the .camera
getter.
Avoid using MapController.of(context).camera
from within the context of FlutterMap
, as it is redundant and less performant than using MapCamera.of(context)
directly.