Py.Cafe

bbbaaa/

leafmap-solara

Libya flooding maps

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import solara
import leafmap

zoom = solara.reactive(14)
center = solara.reactive(([120.35735890260743, 23.823015420956853]))

class Map(leafmap.Map):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        before = "https://github.com/b6baa/HW20241119/raw/refs/heads/main/2024-03-20-00_00_2024-03-20-23_59_Sentinel-2_L2A_NDWI.tiff"
        after = "https://github.com/b6baa/HW20241119/raw/refs/heads/main/2024-08-22-00_00_2024-08-22-23_59_Sentinel-2_L2A_NDWI.tiff"

        self.add_cog_layer(before, name="before")
        self.add_cog_layer(after, name="after")
        self.add("layer_manager")
        
        self.split_map(before, after, left_label="Before", right_label="After", add_close_button=True)

@solara.component
def Page():
    solara.lab.theme.dark = False

    Map.element(
        center = center.value,
        zoom = zoom.value,
        on_center = center.set,
        on_zoom = zoom.set,
        height="750px"

    )

    solara.Text(f"Center: {center.value}")
    solara.Text(f"Zoom: {zoom.value}")