Py.Cafe

hemanya2003/

solara-leafmap-interactive-map

Solara and Leafmap Interactive Map

DocsPricing
  • app.py
  • requirements.txt
  • web
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

# Define reactive zoom and center values
zoom = solara.reactive(17)
center = solara.reactive((19.959987564207466, 85.45383423792339))

class MyMap(leafmap.Map):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.add("layer_manager")

# URLs for the images with correct access to raw content
before = "https://github.com/hemanya2003/datasets/raw/main/Before.jp2"
after = "https://github.com/hemanya2003/datasets/raw/main/After.jp2"

# Create an instance of MyMap and add tile layers with attribution
map_instance = MyMap(center=center.value, zoom=zoom.value)
map_instance.add_tile_layer(url=before, name="Before", attribution="Source: Example Attribution")
map_instance.add_tile_layer(url=after, name="After", attribution="Source: Example Attribution")

@solara.component
def Page():
    solara.lab.theme.dark = False
    return map_instance.element(
        center=center.value,
        zoom=zoom.value,
        on_center=center.set,
        on_zoom=zoom.set,
        height="750px"
    )