FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add GeoJSON example · QuantStack/quantstack-talks@2318778 · GitHub

Repository navigation

Commit 2318778

Browse files
committed
Add GeoJSON example
1 parent 91496f6 commit 2318778

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎2019-06-26-GeoPython/notebooks/2.ipyleaflet.ipynb‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,56 @@
198198
"slider"
199199
]
200200
},
201+
{
202+
"cell_type": "markdown",
203+
"metadata": {},
204+
"source": [
205+
"## GeoJSON Layer with mouse events"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"metadata": {},
212+
"outputs": [],
213+
"source": [
214+
"from ipywidgets import Text, HTML, HBox\n",
215+
"from ipyleaflet import GeoJSON, WidgetControl, Map \n",
216+
"import json"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": null,
222+
"metadata": {},
223+
"outputs": [],
224+
"source": [
225+
"m = Map(center = (43,-100), zoom = 4)\n",
226+
"\n",
227+
"geo_json_data = json.load(open('src/us-states-density.json'))\n",
228+
"geojson = GeoJSON(data=geo_json_data, hover_style={'color': 'black', 'dashArray': '5, 5', 'weight': 2})\n",
229+
"m.add_layer(geojson)\n",
230+
"\n",
231+
"html = HTML('''\n",
232+
" <h4>US population density</h4>\n",
233+
" Hover over a state\n",
234+
"''')\n",
235+
"html.layout.margin = '0px 20px 20px 20px'\n",
236+
"control = WidgetControl(widget=html, position='topright')\n",
237+
"m.add_control(control)\n",
238+
"\n",
239+
"def update_html(properties, **kwargs):\n",
240+
" html.value = '''\n",
241+
" <h4>US population density</h4>\n",
242+
" <h2><b>{}</b></h2>\n",
243+
" {} people / mi^2\n",
244+
" '''.format(properties['name'], properties['density'])\n",
245+
"\n",
246+
"geojson.on_hover(update_html)\n",
247+
"\n",
248+
"m"
249+
]
250+
},
201251
{
202252
"cell_type": "markdown",
203253
"metadata": {},

‎2019-06-26-GeoPython/notebooks/src/us-states-density.json‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL