{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, GeoData, basemaps, LayersControl\n", "import geopandas\n", "import json\n", "\n", "countries = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n", "rivers = geopandas.read_file(\n", " \"https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip\"\n", ")\n", "\n", "m = Map(center=(28.6019917, 70.9121356), zoom=3, basemap=basemaps.Esri.WorldTopoMap)\n", "\n", "geo_data = GeoData(\n", " geo_dataframe=countries,\n", " style={\n", " \"color\": \"black\",\n", " \"fillColor\": \"#366370\",\n", " \"opacity\": 0.05,\n", " \"weight\": 1.9,\n", " \"dashArray\": \"2\",\n", " \"fillOpacity\": 0.6,\n", " },\n", " hover_style={\"fillColor\": \"#b08a3e\", \"fillOpacity\": 0.9},\n", " name=\"Countries\",\n", ")\n", "\n", "\n", "m.add(geo_data)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import Text, HTML\n", "from ipyleaflet import WidgetControl, GeoJSON\n", "\n", "\n", "html = HTML(\"\"\"Hover over a state\"\"\")\n", "html.layout.margin = \"0px 20px 20px 20px\"\n", "control = WidgetControl(widget=html, position=\"topright\")\n", "m.add(control)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def update_html(feature, **kwargs):\n", " html.value = \"\"\"\n", "

{}

\n", "

Population: {:.2e} people

\n", "

Continent: {}

\n", " \"\"\".format(\n", " feature[\"properties\"][\"name\"],\n", " feature[\"properties\"][\"pop_est\"],\n", " feature[\"properties\"][\"continent\"],\n", " )\n", "\n", "\n", "geo_data.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.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }