Map control for Flet
Project description
Map control for Flet
Map
control for Flet.
Usage
Add flet-map
as dependency (pyproject.toml
or requirements.txt
) to your Flet project.
Example
import random
import flet as ft
import flet_map as map
def main(page: ft.Page):
marker_layer_ref = ft.Ref[map.MarkerLayer]()
circle_layer_ref = ft.Ref[map.CircleLayer]()
def handle_tap(e: map.MapTapEvent):
print(e)
if e.name == "tap":
marker_layer_ref.current.markers.append(
map.Marker(
content=ft.Icon(
ft.Icons.LOCATION_ON, color=ft.cupertino_colors.DESTRUCTIVE_RED
),
coordinates=e.coordinates,
)
)
elif e.name == "secondary_tap":
circle_layer_ref.current.circles.append(
map.CircleMarker(
radius=random.randint(5, 10),
coordinates=e.coordinates,
color=ft.Colors.random_color(),
border_color=ft.Colors.random_color(),
border_stroke_width=4,
)
)
page.update()
def handle_event(e: map.MapEvent):
print(e)
page.add(
ft.Text("Click anywhere to add a Marker, right-click to add a CircleMarker."),
map.Map(
expand=True,
initial_center=map.MapLatitudeLongitude(15, 10),
initial_zoom=4.2,
interaction_configuration=map.MapInteractionConfiguration(
flags=map.MapInteractiveFlag.ALL
),
on_init=lambda e: print(f"Initialized Map"),
on_tap=handle_tap,
on_secondary_tap=handle_tap,
on_long_press=handle_tap,
on_event=lambda e: print(e),
layers=[
map.TileLayer(
url_template="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
on_image_error=lambda e: print("TileLayer Error"),
),
map.RichAttribution(
attributions=[
map.TextSourceAttribution(
text="OpenStreetMap Contributors",
on_click=lambda e: e.page.launch_url(
"https://openstreetmap.org/copyright"
),
),
map.TextSourceAttribution(
text="Flet",
on_click=lambda e: e.page.launch_url("https://flet.dev"),
),
]
),
map.SimpleAttribution(
text="Flet",
alignment=ft.alignment.top_right,
on_click=lambda e: print("Clicked SimpleAttribution"),
),
map.MarkerLayer(
ref=marker_layer_ref,
markers=[
map.Marker(
content=ft.Icon(ft.Icons.LOCATION_ON),
coordinates=map.MapLatitudeLongitude(30, 15),
),
map.Marker(
content=ft.Icon(ft.Icons.LOCATION_ON),
coordinates=map.MapLatitudeLongitude(10, 10),
),
map.Marker(
content=ft.Icon(ft.Icons.LOCATION_ON),
coordinates=map.MapLatitudeLongitude(25, 45),
),
],
),
map.CircleLayer(
ref=circle_layer_ref,
circles=[
map.CircleMarker(
radius=10,
coordinates=map.MapLatitudeLongitude(16, 24),
color=ft.Colors.RED,
border_color=ft.Colors.BLUE,
border_stroke_width=4,
),
],
),
map.PolygonLayer(
polygons=[
map.PolygonMarker(
label="Popular Touristic Area",
label_text_style=ft.TextStyle(
color=ft.Colors.BLACK,
size=15,
weight=ft.FontWeight.BOLD,
),
color=ft.Colors.with_opacity(0.3, ft.Colors.BLUE),
coordinates=[
map.MapLatitudeLongitude(10, 10),
map.MapLatitudeLongitude(30, 15),
map.MapLatitudeLongitude(25, 45),
],
),
],
),
map.PolylineLayer(
polylines=[
map.PolylineMarker(
border_stroke_width=3,
border_color=ft.Colors.RED,
gradient_colors=[ft.Colors.BLACK, ft.Colors.BLACK],
color=ft.Colors.with_opacity(0.6, ft.Colors.GREEN),
coordinates=[
map.MapLatitudeLongitude(10, 10),
map.MapLatitudeLongitude(30, 15),
map.MapLatitudeLongitude(25, 45),
],
),
],
),
],
),
)
ft.app(main)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flet_map-0.1.0.tar.gz
(31.5 kB
view details)
Built Distribution
flet_map-0.1.0-py3-none-any.whl
(42.1 kB
view details)
File details
Details for the file flet_map-0.1.0.tar.gz
.
File metadata
- Download URL: flet_map-0.1.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
26689be07ea27aa225a2cc3dbbe394bb3f61151462cac6cb955136964fd40003
|
|
MD5 |
956ee2e4de1abdbd9056e8836c1d842c
|
|
BLAKE2b-256 |
16ea959d196f5e8008cad70e5c05887acf385c93083c06c2911df5af4b873a33
|
File details
Details for the file flet_map-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: flet_map-0.1.0-py3-none-any.whl
- Upload date:
- Size: 42.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
8e818153a6a608f29d0d2c5cb56047e7eedc6737389c8f32a93ac6eb79864a45
|
|
MD5 |
13c887c78c1e6ecd5b424a0b2e463f5f
|
|
BLAKE2b-256 |
7ff596cf406211e5aa82ad35527adf4a1aead450a869c8618a342c03ecb56bad
|