-
Notifications
You must be signed in to change notification settings - Fork 1
/
deckgl.py
59 lines (45 loc) · 1.41 KB
/
deckgl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
'''
Deck.gl visualizations in Jupyter Notebook
'''
'''
importing ipython
'''
from importlib import import_module
ipython_display = import_module('IPython.display')
'''
Displaying
'''
from IPython.display import Javascript
import json
def draw_hexagon_layer(lngs, lats):
text_to_insert = include_mapbox()
text_to_insert += "<div id=\"root\"></div>"
text_to_insert += insert_coords(lngs, lats)
text_to_insert += load_hexagon_layer_from_file()
display_bundle = {
"text/html": text_to_insert
}
ipython_display.display(display_bundle, raw=True)
def insert_coords(lngs, lats):
return """
<script type=\"text/javascript\">
window.coords={0}
</script>
""".format(convert_coords(lngs, lats))
def convert_coords(lngs, lats):
return json.dumps(list(zip(lngs, lats)))
import os
import fnmatch
def load_hexagon_layer_from_file():
heatmap_js_dir = "./hexagon-layer/build/static/js/"
try:
filename = fnmatch.filter(os.listdir(heatmap_js_dir), "main.*.js")[0]
except:
print("There was an error loading the external JS files.")
raise
with open(heatmap_js_dir + filename, "r") as f:
react_js_app = f.read()
return "<script type=\"text/javascript\">" + react_js_app + "</script>"
def include_mapbox():
return "<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.42.2/mapbox-gl.css' rel='stylesheet' />"