From cb517650cb85cd49a2556add336e7fb71f468216 Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Fri, 24 May 2024 16:24:32 +0200 Subject: [PATCH] Add layer order example --- docs/examples/layer_order/app.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 docs/examples/layer_order/app.py diff --git a/docs/examples/layer_order/app.py b/docs/examples/layer_order/app.py new file mode 100644 index 00000000..7d8c7c8a --- /dev/null +++ b/docs/examples/layer_order/app.py @@ -0,0 +1,35 @@ +import requests as req +from maplibre import Layer, LayerType, Map, MapOptions, render_maplibregl +from maplibre.basemaps import Carto, construct_carto_basemap_url +from maplibre.sources import GeoJSONSource +from shiny.express import input, render, ui + +style = req.get(construct_carto_basemap_url(Carto.VOYAGER)).json() + + +symbol_ids = [layer["id"] for layer in style["layers"] if layer["type"] == "symbol"] +# print(symbol_ids) + +urban_areas = GeoJSONSource( + data="https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson" +) + +m = Map( + MapOptions(style=style, center=(-88.13734351262877, 35.137451890638886), zoom=4) +) +m.add_layer( + Layer( + id="urban-areas-fill", + type=LayerType.FILL, + source=urban_areas, + paint={"fill-color": "#f08", "fill-opacity": 1.0}, + ), + before_id=symbol_ids[0], +) +for symbol_id in symbol_ids: + m.set_paint_property(symbol_id, "text-color", "darkblue") + + +@render_maplibregl +def render_map(): + return m