[Python] Can't load TileLayer from local file in web mode

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I have own raster tiles created from QGIS. They are okey, and work on windows app mode by starting python server at http://localhost:8000 and attribute looks like this url_template="http://localhost:8000/{z}/{x}/{y}.jpg",, but this solution doesn't work at web mode and i am putting my script on github pages. It will be perfect to use local path like in leafmap "./{z}/{x}/{y}.jpg", but this also not working.

    This is my Map config for flet map:

    main_map = map.Map(
    expand=True,
    initial_center=map.MapLatitudeLongitude(50.965125,18.286120),
    initial_zoom=12,
    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",
    # url_template="./{z}/{x}/{y}.jpg", <-- I wanna something like this
    # url_template="http://localhost:8000/{z}/{x}/{y}.jpg",
    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(50.965125,18.286120),
    ),
    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(50.965125,18.306120),
    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),
    ],
    ),
    ],
    ),
    ],
    )


    Full srcipt and example tiles (assets folder) is in this github project and there are deploy page

    That's how it look with OSM TiledLayer

    [​IMG]

    That's i wanna to look on web, this is from exe mode for flet app

    [​IMG]

    Continue reading...

Compartilhe esta Página