Py.Cafe

giswqs/

leafmap-ftw

Visualizing Fields of The World (FTW)

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import ipyleaflet
import leafmap
import solara

zoom = solara.reactive(2)
center = solara.reactive((20, 0))


class Map(leafmap.Map):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.add_basemap("SATELLITE")
        self.add_ftw_data()
    
    def add_ftw_data(self):

        url = "https://data.source.coop/kerner-lab/fields-of-the-world/ftw-sources.pmtiles"
        style = {
            "version": 8,
            "sources": {
                "example_source": {
                    "type": "vector",
                    "url": "pmtiles://" + url,
                    "attribution": "PMTiles",
                }
            },
            "layers": [
                {
                    "id": "ftw",
                    "source": "example_source",
                    "source-layer": "ftw-sources",
                    "type": "line",
                    "paint": {
                        "line-color": "#ff0000",
                        "line-width": 2,
                    },
                    "maxzoom": 24,
                },
            ],
        }
        self.add_pmtiles(url, style=style, layer_name="Field boundary", zoom_to_layer=False)


@solara.component
def Page():
    with solara.Column(style={"min-width": "500px"}):
        Map.element(
            zoom=zoom.value,
            on_zoom=zoom.set,
            center=center.value,
            on_center=center.set,
            scroll_wheel_zoom=True,
            toolbar_control=False,
            draw_control=False,
            height="900px"
        )