Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,98 +1,43 @@
|
|
1 |
-
|
2 |
-
Checkout https://awesome-panel.org/resources/lonboard_dashboard/
|
3 |
-
"""
|
4 |
-
# pip install panel colorcet ipywidgets_bokeh geopandas palettable lonboard
|
5 |
-
import colorcet as cc
|
6 |
-
import geopandas as gpd
|
7 |
|
8 |
-
|
9 |
-
from lonboard.colormap import apply_continuous_cmap
|
10 |
-
from palettable.palette import Palette
|
11 |
|
12 |
import panel as pn
|
13 |
|
14 |
-
|
15 |
-
path = "ne_10m_roads_north_america.zip"
|
16 |
|
17 |
try:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
def to_rgb(hex: str) -> list:
|
30 |
-
h = hex.strip("#")
|
31 |
-
return list(int(h[i : i + 2], 16) for i in (0, 2, 4))
|
32 |
-
|
33 |
-
|
34 |
-
def to_palette(cmap) -> Palette:
|
35 |
-
"""Returns the ColorCet colormap as a palettable Palette"""
|
36 |
-
colors = [to_rgb(item) for item in cmap]
|
37 |
-
return Palette(name="colorcet", map_type="colorcet", colors=colors)
|
38 |
|
|
|
39 |
|
40 |
-
|
41 |
-
palette = to_palette(cmap)
|
42 |
-
data = gdf[gdf["state"] == state]
|
43 |
-
layer = PathLayer.from_geopandas(data, width_min_pixels=0.8)
|
44 |
-
normalized_scale_rank = (data["scalerank"] - 3) / 9
|
45 |
-
layer.get_color = apply_continuous_cmap(normalized_scale_rank, palette, alpha=alpha)
|
46 |
-
map_ = Map(layers=[layer], _height=650)
|
47 |
-
return map_
|
48 |
|
|
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
state = pn.widgets.Select(
|
60 |
-
value="California",
|
61 |
-
options=state_options,
|
62 |
-
width=150,
|
63 |
-
name="State",
|
64 |
-
sizing_mode="stretch_width",
|
65 |
-
)
|
66 |
-
cmap = pn.widgets.ColorMap(
|
67 |
-
value=cc.fire,
|
68 |
-
options=cc.palette,
|
69 |
-
ncols=3,
|
70 |
-
swatch_width=100,
|
71 |
-
name="cmap by Colorcet",
|
72 |
-
sizing_mode="stretch_width",
|
73 |
-
)
|
74 |
-
alpha = pn.widgets.FloatSlider(
|
75 |
-
value=0.8, start=0, end=1, name="Alpha", min_width=100, sizing_mode="stretch_width"
|
76 |
-
)
|
77 |
-
logo = pn.pane.Image(
|
78 |
-
"https://github.com/developmentseed/lonboard/raw/main/assets/dalle-lonboard.jpg"
|
79 |
-
)
|
80 |
-
def title(state):
|
81 |
-
return f"# North America Roads: {state}"
|
82 |
|
83 |
-
settings = pn.Column(state, cmap, alpha)
|
84 |
-
description = pn.Column(pn.pane.Markdown(description, margin=5), logo)
|
85 |
-
component = pn.Column(
|
86 |
-
pn.bind(title, state=state),
|
87 |
-
pn.panel(
|
88 |
-
pn.bind(create_map, state=state, cmap=cmap, alpha=alpha.param.value_throttled),
|
89 |
-
sizing_mode="stretch_both",
|
90 |
-
),
|
91 |
-
sizing_mode="stretch_both",
|
92 |
-
)
|
93 |
pn.template.FastListTemplate(
|
94 |
logo="https://panel.holoviz.org/_static/logo_horizontal_dark_theme.png",
|
95 |
-
title="Works with
|
96 |
main=[component],
|
97 |
-
sidebar=[description
|
98 |
).servable()
|
|
|
1 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import mapwidget.cesium as mapwidget
|
|
|
|
|
4 |
|
5 |
import panel as pn
|
6 |
|
7 |
+
pn.extension("ipywidgets")
|
|
|
8 |
|
9 |
try:
|
10 |
+
token = os.environ["CESIUM_TOKEN"]
|
11 |
+
except KeyError as ex:
|
12 |
+
raise EnvironmentError(
|
13 |
+
"CESIUM_TOKEN environment variable not set. "
|
14 |
+
"Sign up for free and get a free Cesium token here https://ion.cesium.com/signup/"
|
15 |
+
) from ex
|
16 |
+
|
17 |
+
cesium_map = mapwidget.Map(
|
18 |
+
center=[40.70605, -74.01177], height="650px", altitude=600, token=token
|
19 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
component = pn.panel(cesium_map, sizing_mode="stretch_width")
|
22 |
|
23 |
+
description = """# MapWidget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
Custom Jupyter widgets for creating interactive 2D/3D maps using popular JavaScript libraries with bidirectional communication, such as `Cesium`, `Mapbox`, `MapLibre`, `Leaflet`, and `OpenLayers`.
|
26 |
|
27 |
+
By **Qiusheng Wu**
|
28 |
|
29 |
+
<img src="https://avatars.githubusercontent.com/u/5016453?v=4" style="width:100%;">
|
30 |
|
31 |
+
# Cesium
|
32 |
|
33 |
+
Cesium is the open platform for software applications designed to unleash the power of 3D data.
|
34 |
|
35 |
+
<img src="https://images.prismic.io/cesium/a4dc3936-e083-4337-ba48-bb5bba78b2a1_ion_color_white.png" style="width:100%;">
|
36 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
pn.template.FastListTemplate(
|
39 |
logo="https://panel.holoviz.org/_static/logo_horizontal_dark_theme.png",
|
40 |
+
title="Works with mapwidget.cesium",
|
41 |
main=[component],
|
42 |
+
sidebar=[description],
|
43 |
).servable()
|