{ "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(\"https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip\")\n", "\n", "m = Map(center=(28.6019917,70.9121356), zoom = 3, basemap= basemaps.Esri.WorldTopoMap)\n", "\n", "geo_data = GeoData(geo_dataframe = countries,\n", " style={'color': 'black', 'fillColor': '#366370', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},\n", " hover_style={'fillColor': '#b08a3e' , 'fillOpacity': 0.9},\n", " name = 'Countries')\n", "\n", "\n", "m.add_layer(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(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(feature['properties']['name'],\n", " feature['properties']['pop_est'],\n", " feature['properties']['continent'])\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 }