diff --git a/docs/examples/airports/app.html b/docs/examples/airports/app.html
new file mode 100644
index 00000000..2c498ef9
--- /dev/null
+++ b/docs/examples/airports/app.html
@@ -0,0 +1,167 @@
+
+
+
+
Pymaplibregl
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/examples/airports/app.py b/docs/examples/airports/app.py
index 39e2d94d..d754a3ba 100644
--- a/docs/examples/airports/app.py
+++ b/docs/examples/airports/app.py
@@ -1,3 +1,5 @@
+import sys
+
import pandas as pd
from maplibre import (
Layer,
@@ -64,6 +66,23 @@ def get_color(airport_type: str) -> str:
popup_options = PopupOptions(close_button=False)
+
+def create_map() -> Map:
+ m = Map(map_options)
+ m.add_layer(airport_circles)
+ for _, r in airports_data.iterrows():
+ marker = Marker(
+ lng_lat=r["coordinates"],
+ options=MarkerOptions(color=get_color(r["type"])),
+ popup=Popup(
+ text=r["name"],
+ options=popup_options,
+ ),
+ )
+ m.add_marker(marker)
+ return m
+
+
app_ui = ui.page_fluid(
ui.panel_title("Airports"),
output_maplibregl("maplibre", height=600),
@@ -73,22 +92,14 @@ def get_color(airport_type: str) -> str:
def server(input, output, session):
@render_maplibregl
def maplibre():
- m = Map(map_options)
- for _, r in airports_data.iterrows():
- marker = Marker(
- lng_lat=r["coordinates"],
- options=MarkerOptions(color=get_color(r["type"])),
- popup=Popup(
- text=r["name"],
- options=popup_options,
- ),
- )
- m.add_marker(marker)
- m.add_layer(airport_circles)
- return m
+ return create_map()
app = App(app_ui, server)
if __name__ == "__main__":
- app.run()
+ if len(sys.argv) == 2:
+ with open(sys.argv[1], "w") as f:
+ f.write(create_map().to_html())
+ else:
+ app.run()
diff --git a/docs/examples/airports/index.md b/docs/examples/airports/index.md
index 031c511d..cd813974 100644
--- a/docs/examples/airports/index.md
+++ b/docs/examples/airports/index.md
@@ -1,3 +1,5 @@
+
+
```python
-8<-- "airports/app.py"
```
diff --git a/docs/examples/earthquake_clusters/app.html b/docs/examples/earthquake_clusters/app.html
new file mode 100644
index 00000000..d550851d
--- /dev/null
+++ b/docs/examples/earthquake_clusters/app.html
@@ -0,0 +1,167 @@
+
+
+
+Pymaplibregl
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/examples/earthquake_clusters/app.py b/docs/examples/earthquake_clusters/app.py
index bba6fe29..1342b8ee 100644
--- a/docs/examples/earthquake_clusters/app.py
+++ b/docs/examples/earthquake_clusters/app.py
@@ -1,3 +1,5 @@
+import sys
+
from maplibre import (
Layer,
LayerType,
@@ -69,6 +71,17 @@
map_options = MapOptions(style=Carto.POSITRON, center=CENTER, zoom=3, hash=True)
+
+def create_map() -> Map:
+ m = Map(map_options)
+ m.add_source(EARTHQUAKE_SOURCE, earthquakes_source)
+ m.add_layer(earthquake_clusters)
+ m.add_layer(earthquake_circles)
+ m.add_tooltip(EARTHQUAKE_CLUSTERS, "maxMag")
+ m.add_layer(earthquake_labels)
+ return m
+
+
app_ui = ui.page_fluid(
ui.panel_title("Earthquakes Cluster"),
output_maplibregl("maplibre", height=500),
@@ -78,13 +91,7 @@
def server(input, output, session):
@render_maplibregl
def maplibre():
- m = Map(map_options)
- m.add_source(EARTHQUAKE_SOURCE, earthquakes_source)
- m.add_layer(earthquake_clusters)
- m.add_layer(earthquake_circles)
- m.add_tooltip(EARTHQUAKE_CLUSTERS, "maxMag")
- m.add_layer(earthquake_labels)
- return m
+ return create_map()
@reactive.Effect
@reactive.event(input.maplibre)
@@ -95,4 +102,9 @@ async def result():
app = App(app_ui, server)
if __name__ == "__main__":
- app.run()
+ if len(sys.argv) == 2:
+ file_name = sys.argv[1]
+ with open(file_name, "w") as f:
+ f.write(create_map().to_html())
+ else:
+ app.run()
diff --git a/docs/examples/earthquake_clusters/index.md b/docs/examples/earthquake_clusters/index.md
index 2c56003d..77f57d29 100644
--- a/docs/examples/earthquake_clusters/index.md
+++ b/docs/examples/earthquake_clusters/index.md
@@ -1,3 +1,5 @@
+
+
```python
-8<-- "earthquake_clusters/app.py"
```
diff --git a/docs/examples/every_person_in_manhattan/app.html b/docs/examples/every_person_in_manhattan/app.html
new file mode 100644
index 00000000..734fdd37
--- /dev/null
+++ b/docs/examples/every_person_in_manhattan/app.html
@@ -0,0 +1,167 @@
+
+
+
+Pymaplibregl
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/examples/every_person_in_manhattan/app.py b/docs/examples/every_person_in_manhattan/app.py
index 164ef77f..89ea6278 100644
--- a/docs/examples/every_person_in_manhattan/app.py
+++ b/docs/examples/every_person_in_manhattan/app.py
@@ -1,4 +1,5 @@
import json
+import sys
import pandas as pd
import shapely
@@ -52,6 +53,14 @@
fit_bounds_options={"padding": 20},
)
+
+def create_map() -> Map:
+ m = Map(map_options)
+ m.add_control(ScaleControl(), position="bottom-left")
+ m.add_layer(every_person_in_manhattan_circles)
+ return m
+
+
app_ui = ui.page_fluid(
ui.panel_title("Every Person in Manhattan"),
output_maplibregl("maplibre", height=600),
@@ -62,10 +71,7 @@
def server(input, output, session):
@render_maplibregl
def maplibre():
- m = Map(map_options)
- m.add_control(ScaleControl(), position="bottom-left")
- m.add_layer(every_person_in_manhattan_circles)
- return m
+ return create_map()
@reactive.Effect
@reactive.event(input.radius, ignore_init=True)
@@ -77,4 +83,9 @@ async def radius():
app = App(app_ui, server)
if __name__ == "__main__":
- app.run()
+ if len(sys.argv) == 2:
+ file_name = sys.argv[1]
+ with open(file_name, "w") as f:
+ f.write(create_map().to_html())
+ else:
+ app.run()
diff --git a/docs/examples/every_person_in_manhattan/index.md b/docs/examples/every_person_in_manhattan/index.md
index b3e6fcd6..411b88a9 100644
--- a/docs/examples/every_person_in_manhattan/index.md
+++ b/docs/examples/every_person_in_manhattan/index.md
@@ -1,3 +1,5 @@
+
+
```python
-8<-- "every_person_in_manhattan/app.py"
```
diff --git a/docs/examples/geopandas/index.md b/docs/examples/geopandas/index.md
index fffccb96..516f4995 100644
--- a/docs/examples/geopandas/index.md
+++ b/docs/examples/geopandas/index.md
@@ -1,4 +1,6 @@
-See example in action
+
+
+
```python
-8<-- "geopandas/app.py"
diff --git a/docs/examples/road_safety/app.py b/docs/examples/road_safety/app.py
index 2e8b9c8d..a2a73176 100644
--- a/docs/examples/road_safety/app.py
+++ b/docs/examples/road_safety/app.py
@@ -51,21 +51,28 @@ def create_h3_grid(res=RESOLUTION) -> dict:
source = GeoJSONSource(data=create_h3_grid())
+map_options = MapOptions(
+ center=(-1.415727, 52.232395),
+ zoom=7,
+ pitch=40,
+ bearing=-27,
+)
+
+h3_layer = Layer(
+ id="road-safety",
+ type=LayerType.FILL_EXTRUSION,
+ source=source,
+ paint={
+ "fill-extrusion-color": ["get", "color"],
+ "fill-extrusion-opacity": 0.7,
+ "fill-extrusion-height": ["*", 100, ["get", "count"]],
+ },
+)
+
def create_map() -> Map:
- m = Map(MapOptions(center=(-1.415727, 52.232395), zoom=7, pitch=40, bearing=-27))
- m.add_layer(
- Layer(
- id="road-safety",
- type=LayerType.FILL_EXTRUSION,
- source=source,
- paint={
- "fill-extrusion-color": ["get", "color"],
- "fill-extrusion-opacity": 0.7,
- "fill-extrusion-height": ["*", 100, ["get", "count"]],
- },
- )
- )
+ m = Map(map_options)
+ m.add_layer(h3_layer)
m.add_tooltip("road-safety", "count")
return m
diff --git a/mkdocs.yml b/mkdocs.yml
index 95e5a0d3..4772d05e 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -29,7 +29,7 @@ nav:
- 3D Indoor mapping: examples/3d_indoor_mapping/index.md
- Custom basemap: examples/custom_basemap/index.md
- GeoPandas: examples/geopandas/index.md
- - UK Road Safety: examples/road_safety/index.md
+ - H3 Grid UK Road Safety: examples/road_safety/index.md
- Where is the ISS: examples/where_is_the_iss/index.md
plugins: