Skip to content

Commit 3959490

Browse files
committed
Support h3 deck layers in shiny apps
1 parent 5c671bd commit 3959490

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

_experimental/h3_deck_layer.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from maplibre import MapOptions
1+
from maplibre import MapOptions, render_maplibregl
22
from maplibre.basemaps import Carto
33
from maplibre.controls import NavigationControl
44
from maplibre.ipywidget import MapWidget as Map
5+
from maplibre.ui import use_deckgl, use_h3
6+
from shiny.express import app, ui
57

68
m = Map(
79
MapOptions(
@@ -27,4 +29,15 @@
2729
}
2830

2931
m.add_deck_layers([h3_hexagon_layer], tooltip="{{ hex }} count: {{ count }}")
30-
m.save("/tmp/py-maplibre-express.html")
32+
33+
use_h3()
34+
use_deckgl()
35+
36+
37+
@render_maplibregl
38+
def render_map():
39+
return m
40+
41+
42+
if __name__ == "__main__":
43+
m.save("/tmp/py-maplibre-express.html", preview=True)

maplibre/ui.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ def output_maplibregl(id_: str, height: [int | str] = 200) -> Tag:
4343

4444

4545
DECKGL_VERSION = "9.0.16"
46+
H3_VERSION = "4.1.0"
47+
48+
h3_dep = HTMLDependency(
49+
name="h3",
50+
version=H3_VERSION,
51+
source={"href": f"https://unpkg.com/h3-js@{H3_VERSION}/dist/"},
52+
script={"src": "h3-js.umd.js"},
53+
)
54+
55+
56+
def use_h3() -> Tag:
57+
return ui.div(h3_dep)
58+
4659

4760
deckgl_dep = HTMLDependency(
4861
name="deckgl",
@@ -51,8 +64,6 @@ def output_maplibregl(id_: str, height: [int | str] = 200) -> Tag:
5164
script={"src": "dist.min.js", "type": "module"},
5265
)
5366

54-
# TODO: Remove duplicated constant
55-
# DECKGL_VERSION = "9.0.16"
5667

5768
deckgl_json_dep = HTMLDependency(
5869
name="deckgljson",

0 commit comments

Comments
 (0)