In [ ]:
from ipyleaflet import Map, GeoJSON
import json
import os
import requests
if not os.path.exists('europe_110.geo.json'):
url = 'https://github.com/jupyter-widgets/ipyleaflet/raw/master/examples/europe_110.geo.json'
r = requests.get(url)
with open('europe_110.geo.json', 'w') as f:
f.write(r.content.decode("utf-8"))
with open('europe_110.geo.json', 'r') as f:
data = json.load(f)
m = Map(center=(50.6252978589571, 0.34580993652344), zoom=3)
geo_json = GeoJSON(data=data, style = {'color': 'green', 'opacity':1, 'weight':1.9, 'dashArray':'9', 'fillOpacity':0.1})
m.add_layer(geo_json)
m
In [ ]:
from ipywidgets import Text, HTML
from ipyleaflet import WidgetControl, GeoJSON
html1 = HTML('''
<h4>EU population density</h4>
Hover over a state
''')
html1.layout.margin = '0px 20px 20px 20px'
control1 = WidgetControl(widget=html1, position='bottomright')
m.add_control(control1)
def update_html(feature, **kwargs):
html1.value = '''
<h4>EU population density</h4>
<h4><b>{}</b></h4>
{} people / mi^2
'''.format(feature['properties']['name'], feature['properties']['pop_est'])
geo_json.on_hover(update_html)