MapCamera class
Describes the view of a map. This includes the size/zoom/position/crs as well as the minimum/maximum zoom. This class is mostly immutable but has some fields that get calculated lazily, changes to the map view may occur via the MapController or user interactions which will result in a new MapCamera value.
Constructors
-
MapCamera({required Crs crs, required LatLng center, required double zoom, required double rotation, required Point<
double> nonRotatedSize, double? minZoom, double? maxZoom, Point<double> ? size, Bounds<double> ? pixelBounds, LatLngBounds? bounds, Point<int> ? pixelOrigin}) -
Create an instance of MapCamera. The
pixelOrigin
,bounds
, andpixelBounds
may be set if they are known already. Otherwise if left null they will be calculated lazily when they are used. - MapCamera.initialCamera(MapOptions options)
-
Initializes MapCamera from the given
options
and with the nonRotatedSize set to kImpossibleSize.
Properties
- center → LatLng
-
The
LatLng
which corresponds with the center of this camera.final - crs → Crs
-
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- maxZoom → double?
-
final
- minZoom → double?
-
final
-
nonRotatedSize
→ Point<
double> -
The size of the map view ignoring rotation. This will be the size of the
FlutterMap widget.
final
-
nonrotatedSize
→ Point<
double> -
no setter
-
pixelBounds
→ Bounds<
double> -
Calculates the pixel bounds of this MapCamera. This value is cached.
no setter
-
pixelOrigin
→ Point<
int> -
The offset of the top-left corner of the bounding rectangle of this
camera. This will not equal the offset of the top-left visible pixel when
the map is rotated.
no setter
- rotation → double
-
The rotation, in degrees, of the camera. See rotationRad for the same
value in radians.
final
- rotationRad → double
-
The current rotation value in radians
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
size
→ Point<
double> -
The size of bounding box of this camera taking in to account its
rotation. When the rotation is zero this will equal nonRotatedSize,
otherwise it will be the size of the rectangle which contains this
camera.
no setter
- visibleBounds → LatLngBounds
-
This is the LatLngBounds corresponding to four corners of this camera.
This takes rotation in to account.
no setter
- zoom → double
-
How far zoomed this camera is.
final
Methods
-
clampZoom(
double zoom) → double -
Clamps the provided
zoom
to the range specified by minZoom and maxZoom, if set. -
focusedZoomCenter(
Point< num> cursorPos, double zoom) → LatLng -
Calculate the center point which would keep the same point of the map
visible at the given
cursorPos
with the zoom set tozoom
. -
getNewPixelOrigin(
LatLng center, [double? zoom]) → Point< int> -
Calculates the pixel origin of this MapCamera at the given
center
/zoom
. -
getOffsetFromOrigin(
LatLng pos) → Offset -
Calculates the Offset from the
pos
to this camera's pixelOrigin. -
getPixelWorldBounds(
double? zoom) → Bounds< num> ? - Calculates the pixel bounds of this camera's crs.
-
getScaleZoom(
double scale) → double - Calculates the scale for this camera's zoom.
-
getZoomScale(
double toZoom, double fromZoom) → double -
Calculates the scale for a zoom from
fromZoom
totoZoom
using this camera\s crs. -
latLngToScreenPoint(
LatLng latLng) → Point< double> - This will convert a latLng to a position that we could use with a widget outside of FlutterMap layer space. Eg using a Positioned Widget.
-
layerPointToLatLng(
Point< num> point) → LatLng -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offsetToCrs(
Offset offset, [double? zoom]) → LatLng -
pixelBoundsAtZoom(
double zoom) → Bounds< double> -
Calculates the pixel bounds of this MapCamera at the given
zoom
. -
pointToLatLng(
Point< num> localPoint) → LatLng -
project(
LatLng latlng, [double? zoom]) → Point< double> -
Calculates point value for the given
latLng
using this camera's crs andzoom
(or the providedzoom
). -
rotatePoint(
Point< double> mapCenter, Point<double> point, {bool counterRotation = true}) → Point<double> - Sometimes we need to make allowances that a rotation already exists, so it needs to be reversed (pointToLatLng), and sometimes we want to use the same rotation to create a new position (latLngToScreenpoint). counterRotation just makes allowances this for this.
-
toString(
) → String -
A string representation of this object.
inherited
-
unproject(
Point< num> point, [double? zoom]) → LatLng -
Calculates the
LatLng
for the givenpoint
using this camera's crs andzoom
(or the providedzoom
). -
withNonRotatedSize(
Point< double> nonRotatedSize) → MapCamera -
Returns a new instance of MapCamera with the given
nonRotatedSize
. -
withOptions(
MapOptions options) → MapCamera -
Returns a new instance of MapCamera with the given
options
. -
withPosition(
{LatLng? center, double? zoom}) → MapCamera -
Returns a new instance of MapCamera with the given
center
/zoom
. -
withRotation(
double rotation) → MapCamera -
Returns a new instance of MapCamera with the given
rotation
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
calculateRotatedSize(
double rotation, Point< double> nonRotatedSize) → Point<double> -
Calculates the size of a bounding box which surrounds a box of size
nonRotatedSize
which is rotated byrotation
. -
maybeOf(
BuildContext context) → MapCamera? - The camera of the closest FlutterMap ancestor. If this is called from a context with no FlutterMap ancestor null, is returned.
-
of(
BuildContext context) → MapCamera - The camera of the closest FlutterMap ancestor. If this is called from a context with no FlutterMap ancestor a StateError will be thrown.
Constants
-
kImpossibleSize
→ const Point<
double> - During Flutter startup the native platform resolution is not immediately available which can cause constraints to be zero before they are updated in a subsequent build to the actual constraints. We set the size to this impossible (negative) value initially and only change it once Flutter provides real constraints.