flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.5k stars 449 forks source link

TileLayer Error using Mapping (on_image_error) #4353

Closed Michel7GitHub closed 1 week ago

Michel7GitHub commented 1 week ago

Duplicate Check

Describe the bug

I use Windows 11 (Flet 0.24.1) and IOS mobiles (Ipad & Iphone) with Flet App version 0.24.1. When I drag or zoom-in /zoom-out quickly, I have frequent errors from "Event handler for image error events." Once, I get an error, refreshing becomes quite slow. I get the error on all environments : Windows, Iphone and Ipad. I tried to use few different tile providers (OpenStreetMap, OnTopoMap, Google, MapTile) and have same problem with all. However, using OpenTopoMap gives more frequent errors.

import flet as ft
import flet.map as map

def main(page: ft.Page):

    def handle_event(e: map.MapEvent):
        if e.source == map.MapEventSource.DRAG_END:
            print("Drag_END ............. \n", e.source)

    page.add(
        map.Map(
            expand=True,
            configuration=map.MapConfiguration(
                initial_center=map.MapLatitudeLongitude(27.66, -15.58),
                initial_zoom=10,
                interaction_configuration=map.MapInteractionConfiguration(
                    flags=map.MapInteractiveFlag.ALL
                ),
                on_event=handle_event
            ),
            layers=[
                map.TileLayer(
                    #url_template="http://mt1.google.com/vt/lyrs=p&hl=en&x={x}&y={y}&z={z}",
                    url_template="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
                    url_template="http://c.tile.opentopomap.org/{z}/{x}/{y}.png",
                    on_image_error=lambda e: print("TileLayer Error"),
                ),
                map.MarkerLayer(
                    markers=[
                        map.Marker(
                            content=ft.Icon(ft.icons.LOCATION_ON),
                            coordinates=map.MapLatitudeLongitude(15, 10), rotate=False
                        ),
                    ],
                )
            ],
        ),
    )

ft.app(target=main, view=ft.AppView.WEB_BROWSER)

Code sample

Code ```python [Paste your code here] ```

To reproduce

Try the code I sent. Quickly Drag / zoom-in zoom-out in different regions of the map. You should have an error...

Expected behavior

No response

Screenshots / Videos

Captures [Upload media here]

Operating System

Windows

Operating system details

Windows 11

Flet version

0.24.1

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ```

Additional details

No response