Skip to content

Commit 45283e4

Browse files
committed
Add Raster Tile Source Example App
1 parent ddd0037 commit 45283e4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

config/site.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[site]
22
title = "MapLibre for Python"
33
subtitle = "Shinylive"
4-
apps = [{ title = "Getting Started", dir = "getting-started" }]
4+
apps = [
5+
{ title = "Getting Started", dir = "getting-started" },
6+
{ title = "Raster Tile Source", dir = "raster-tile-source" },
7+
]

raster-tile-source/app.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from maplibre import Layer, LayerType, Map, MapLibreRenderer, MapOptions
2+
from maplibre.basemaps import background, construct_basemap_style
3+
from maplibre.controls import GlobeControl, NavigationControl
4+
from maplibre.sources import RasterTileSource
5+
from shiny import reactive
6+
from shiny.express import input, render, ui
7+
8+
layer_id = "osm"
9+
10+
raster_tiles = RasterTileSource(
11+
tiles=["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"],
12+
tile_size=256,
13+
attribution="© OpenStreetMap Contributors",
14+
max_zoom=19,
15+
)
16+
style = construct_basemap_style(
17+
sources={"osm": raster_tiles},
18+
layers=[Layer(id=layer_id, type=LayerType.RASTER, source="osm")],
19+
)
20+
21+
22+
@MapLibreRenderer
23+
def my_map():
24+
m = Map(
25+
MapOptions(style=style, zoom=2, hash=True),
26+
controls=[NavigationControl(), GlobeControl()],
27+
)
28+
return m
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
maplibre[shiny]
2+
pydantic
3+
jinja2
4+
branca
5+

0 commit comments

Comments
 (0)