Map
An interactive map that displays various layers.
Inherits: LayoutControl
Properties
animation_curve- The default animation curve to be used for map-animations when calling instance methods like zoom_in, rotate_from, move_to etc.animation_duration- The default animation duration to be used for map-animations when calling instance methods like zoom_in, rotate_from, move_to etc.bgcolor- The background color of this control.initial_camera_fit- Defines the visible bounds when the map is first loaded.initial_center- The initial center of the map.initial_rotation- The rotation (in degrees) when the map is first loaded.initial_zoom- The zoom when the map is first loaded.interaction_configuration- The interaction configuration.keep_alive- Whether to enable the built in keep-alive functionality.layers- A list of layers to be displayed (stack-like) on the map.max_zoom- The maximum (highest) zoom level of every layer.min_zoom- The minimum (smallest) zoom level of every layer.
Events
on_event- Fires when any map events occurs.on_hover- Fires when a hover event occurs.on_init- Fires when the map is initialized.on_long_press- Fires when a long press event occurs.on_pointer_cancel- Fires when a pointer cancel event occurs.on_pointer_down- Fires when a pointer down event occurs.on_pointer_up- Fires when a pointer up event occurs.on_position_change- Fires when the map position changes, e.g.on_secondary_tap- Fires when a secondary tap event occurs.on_tap- Fires when a tap event occurs.
Methods
center_on- Centers the map on the given point.get_camera- Gets the current camera snapshot of the map.move_to- Moves to a specific location.reset_rotation- Resets the map's rotation to 0 degrees.rotate_from- Applies a rotation ofdegreeto the current rotation.zoom_in- Zooms in by one zoom-level from the current one.zoom_out- Zooms out by one zoom-level from the current one.zoom_to- Zoom the map to a specific zoom level.
Properties
animation_curveclass-attributeinstance-attribute
animation_curve: AnimationCurve = AnimationCurve.FAST_OUT_SLOWINThe default animation curve to be used for map-animations when calling instance methods like zoom_in, rotate_from, move_to etc.
animation_durationclass-attributeinstance-attribute
animation_duration: DurationValue = field(default_factory=(lambda: Duration(milliseconds=500)))The default animation duration to be used for map-animations when calling instance methods like zoom_in, rotate_from, move_to etc.
bgcolorclass-attributeinstance-attribute
bgcolor: ColorValue = Colors.GREY_300The background color of this control.
initial_camera_fitclass-attributeinstance-attribute
initial_camera_fit: Optional[CameraFit] = NoneDefines the visible bounds when the map is first loaded. Takes precedence over initial_center/initial_zoom.
initial_centerclass-attributeinstance-attribute
initial_center: MapLatitudeLongitude = field(default_factory=(lambda: MapLatitudeLongitude(latitude=50.5, longitude=30.51)))The initial center of the map.
initial_rotationclass-attributeinstance-attribute
initial_rotation: Number = 0.0The rotation (in degrees) when the map is first loaded.
initial_zoomclass-attributeinstance-attribute
initial_zoom: Number = 13.0The zoom when the map is first loaded. If initial_camera_fit is defined this has no effect.
interaction_configurationclass-attributeinstance-attribute
interaction_configuration: InteractionConfiguration = field(default_factory=(lambda: InteractionConfiguration()))The interaction configuration.
keep_aliveclass-attributeinstance-attribute
keep_alive: bool = FalseWhether to enable the built in keep-alive functionality.
If the map is within a complex layout, such as a ListView, the map will reset to its initial position after it appears back into view. To ensure this doesn't happen, enable this flag to prevent it from rebuilding.
layersinstance-attribute
layers: list[MapLayer]A list of layers to be displayed (stack-like) on the map.
Events
on_eventclass-attributeinstance-attribute
on_event: Optional[EventHandler[MapEvent]] = NoneFires when any map events occurs.
on_hoverclass-attributeinstance-attribute
on_hover: Optional[EventHandler[MapHoverEvent]] = NoneFires when a hover event occurs.
on_initclass-attributeinstance-attribute
on_init: Optional[ControlEventHandler[Map]] = NoneFires when the map is initialized.
on_long_pressclass-attributeinstance-attribute
on_long_press: Optional[EventHandler[MapTapEvent]] = NoneFires when a long press event occurs.
on_pointer_cancelclass-attributeinstance-attribute
on_pointer_cancel: Optional[EventHandler[MapPointerEvent]] = NoneFires when a pointer cancel event occurs.
on_pointer_downclass-attributeinstance-attribute
on_pointer_down: Optional[EventHandler[MapPointerEvent]] = NoneFires when a pointer down event occurs.
on_pointer_upclass-attributeinstance-attribute
on_pointer_up: Optional[EventHandler[MapPointerEvent]] = NoneFires when a pointer up event occurs.
on_position_changeclass-attributeinstance-attribute
on_position_change: Optional[EventHandler[MapPositionChangeEvent]] = NoneFires when the map position changes, e.g. when the user pans or zooms the map.
on_secondary_tapclass-attributeinstance-attribute
on_secondary_tap: Optional[EventHandler[MapTapEvent]] = NoneFires when a secondary tap event occurs.
on_tapclass-attributeinstance-attribute
on_tap: Optional[EventHandler[MapTapEvent]] = NoneFires when a tap event occurs.
Methods
center_onasync
center_on(point: MapLatitudeLongitude, zoom: Optional[Number], animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Centers the map on the given point.
Parameters:
- point (MapLatitudeLongitude) - The point on which to center the map.
- zoom (Optional[Number]) - The zoom level to be applied.
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. IfNone(the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
get_cameraasync
get_camera()Gets the current camera snapshot of the map.
Returns:
- Current (Camera) - class:
~flet_map.Camerastate.
move_toasync
move_to(destination: Optional[MapLatitudeLongitude] = None, zoom: Optional[Number] = None, rotation: Optional[Number] = None, animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, offset: OffsetValue = (0, 0), cancel_ongoing_animations: bool = False)Moves to a specific location.
Parameters:
- destination (Optional[MapLatitudeLongitude], default:
None) - The destination point to move to. - zoom (Optional[Number], default:
None) - The zoom level to be applied. If provided, must be greater than or equal to0.0. - rotation (Optional[Number], default:
None) - Rotation (in degrees) to be applied. - offset (OffsetValue, default:
(0, 0)) - The offset to be used. Only works whenrotationisNone. - animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. If None (the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
Raises:
- ValueError - If
zoomis notNoneand is negative.
reset_rotationasync
reset_rotation(animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Resets the map's rotation to 0 degrees.
Parameters:
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. If None (the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
rotate_fromasync
rotate_from(degree: Number, animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Applies a rotation of degree to the current rotation.
Parameters:
- degree (Number) - The number of degrees to increment to the current rotation.
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. If None (the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
zoom_inasync
zoom_in(animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Zooms in by one zoom-level from the current one.
Parameters:
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. If None (the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
zoom_outasync
zoom_out(animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Zooms out by one zoom-level from the current one.
Parameters:
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. IfNone(the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.
zoom_toasync
zoom_to(zoom: Number, animation_curve: Optional[AnimationCurve] = None, animation_duration: Optional[DurationValue] = None, cancel_ongoing_animations: bool = False)Zoom the map to a specific zoom level.
Parameters:
- zoom (Number) - The zoom level to zoom to.
- animation_curve (Optional[AnimationCurve], default:
None) - The curve of the animation. IfNone(the default), flet_map.Map.animation_curve will be used. - animation_duration (Optional[DurationValue], default:
None) - The duration of the animation. If None (the default), flet_map.Map.animation_duration will be used. - cancel_ongoing_animations (bool, default:
False) - Whether to cancel/stop all ongoing map-animations before starting this new one.