import ipyleaflet as ipyl
import ipywidgets as ipyw
import json
# geojson layer with hover handler
with open('../../silvereye/app/public/data/geofabric_ahgf_catchments_level2.json.geojson') as f:
data = json.load(f)
for feature in data['features']:
feature['properties']['style'] = {
'color': 'grey',
'weight': 1,
'fillColor': 'grey',
'fillOpacity': 0.4
}
layer = ipyl.GeoJSON(data=data, hover_style={'fillColor': 'yellow'})
# Map and label widgets
map = ipyl.Map(center=[-30, 130], zoom=5)
map.layout.height = '800px'
label = ipyw.Label(layout=ipyw.Layout(width='100%'))
def hover_handler(event=None, id=None, properties=None):
label.value = properties['level2name']
def click_handler(event=None, id=None, properties=None):
label.value = properties['level2name']
layer.on_hover(hover_handler)
#layer.on_click(click_handler)
map.add_layer(layer)
ipyw.VBox([label, map])