MarcSkovMadsen commited on
Commit
67b299f
·
verified ·
1 Parent(s): 41f0ebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -34
app.py CHANGED
@@ -1,48 +1,54 @@
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
- site="Awesome Panel",
40
- site_url="https://awesome-panel.org",
41
- logo="https://panel.holoviz.org/_static/logo_horizontal_dark_theme.png",
42
- title="mapwidget.cesium",
43
- theme="dark",
44
- theme_toggle=False,
45
- main_layout=None,
46
- main=[component],
47
- sidebar=[description],
48
- ).servable()
 
1
+ import numpy as np
2
+ import holoviews as hv
3
+ import dask.dataframe as dd
4
 
5
+ from holoviews import opts
6
+ from holoviews.operation.datashader import aggregate
7
  import panel as pn
8
+ from utils import get_meta_data
9
+
10
+ pn.extension()
11
+
12
+ hv.extension('bokeh')
13
 
14
+ renderer = hv.renderer('bokeh')
15
 
16
+ opts.defaults(
17
+ opts.Curve(xaxis=None, yaxis=None, show_grid=False, show_frame=False,
18
+ color='orangered', framewise=True, width=100),
19
+ opts.Image(width=800, height=400, shared_axes=False, logz=True, colorbar=True,
20
+ xaxis=None, yaxis=None, axiswise=True, bgcolor='black'),
21
+ opts.HLine(color='white', line_width=1),
22
+ opts.Layout(shared_axes=False),
23
+ opts.VLine(color='white', line_width=1))
24
 
25
+ pandas_df = pn.cache(get_meta_data)()
26
+ df = dd.from_pandas(pandas_df).persist()
 
27
 
28
+ points = hv.Points(df, kdims=['centre_easting', 'centre_northing'], vdims=[])
29
 
30
+ agg = aggregate(points, link_inputs=True, x_sampling=0.0001, y_sampling=0.0001)
31
 
32
+ agg.opts(cmap="kr_r")
33
 
34
+ pointerx = hv.streams.PointerX(x=np.mean(points.range('centre_easting')), source=points)
35
+ pointery = hv.streams.PointerY(y=np.mean(points.range('centre_northing')), source=points)
36
+ box = hv.streams.BoundsXY(source=points, bounds=(0,0,0,0))
37
+ vline = hv.DynamicMap(lambda x: hv.VLine(x), streams=[pointerx])
38
+ hline = hv.DynamicMap(lambda y: hv.HLine(y), streams=[pointery])
39
 
40
+ tiles = hv.Tiles('https://tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="OSM").opts(width=600, height=550)
41
+ hvobj = tiles * agg * hline * vline
42
 
43
+ @pn.depends(pointerx.param.x, pointery.param.y)
44
+ def table(x,y):
45
+ return f"Easting: {x}, Northing: {y}"
46
 
47
+ @pn.depends(box.param.bounds)
48
+ def bbox(value):
49
+ return str(value)
50
 
51
+ pn.pane.HoloViews(hvobj).servable()
 
52
 
53
+ pn.panel(table).servable()
54
+ pn.panel(bbox).servable()