{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, GeoJSON\n", "import json\n", "import os\n", "import requests\n", "\n", "if not os.path.exists('europe_110.geo.json'):\n", " url = 'https://github.com/jupyter-widgets/ipyleaflet/raw/master/examples/europe_110.geo.json'\n", " r = requests.get(url)\n", " with open('europe_110.geo.json', 'w') as f:\n", " f.write(r.content.decode(\"utf-8\"))\n", "\n", "with open('europe_110.geo.json', 'r') as f:\n", " data = json.load(f)\n", "\n", "m = Map(center=(50.6252978589571, 0.34580993652344), zoom=3)\n", "geo_json = GeoJSON(data=data, style = {'color': 'green', 'opacity':1, 'weight':1.9, 'dashArray':'9', 'fillOpacity':0.1})\n", "m.add_layer(geo_json)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import Text, HTML\n", "from ipyleaflet import WidgetControl, GeoJSON \n", "\n", "html1 = HTML('''\n", "

EU population density

\n", " Hover over a state\n", "''')\n", "html1.layout.margin = '0px 20px 20px 20px'\n", "control1 = WidgetControl(widget=html1, position='bottomright')\n", "m.add_control(control1)\n", "\n", "def update_html(feature, **kwargs):\n", " html1.value = '''\n", "

EU population density

\n", "

{}

\n", " {} people / mi^2\n", " '''.format(feature['properties']['name'], feature['properties']['pop_est'])\n", "\n", "geo_json.on_hover(update_html)" ] } ], "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.8.1" } }, "nbformat": 4, "nbformat_minor": 2 }