{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipyleaflet as ipyl\n", "import ipywidgets as ipyw\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Map and label widgets\n", "map = ipyl.Map(center=[53.88, 27.45], zoom=4)\n", "label = ipyw.Label(layout=ipyw.Layout(width='100%'))\n", "\n", "# geojson layer with hover handler\n", "with open('./europe_110.geo.json') as f:\n", " data = json.load(f)\n", "for feature in data['features']:\n", " feature['properties']['style'] = {\n", " 'color': 'grey',\n", " 'weight': 1,\n", " 'fillColor': 'grey',\n", " 'fillOpacity': 0.5\n", " }\n", "layer = ipyl.GeoJSON(data=data, hover_style={'fillColor': 'red'})\n", "\n", "def hover_handler(event=None, feature=None, id=None, properties=None):\n", " label.value = properties['geounit']\n", "\n", "layer.on_hover(hover_handler)\n", "map.add_layer(layer)\n", "\n", "\n", "ipyw.VBox([map, label])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 1 }