|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": { |
| 7 | + "scrolled": false |
| 8 | + }, |
| 9 | + "outputs": [], |
| 10 | + "source": [ |
| 11 | + "from ipyleaflet import Map, GeoData, basemaps, LayersControl\n", |
| 12 | + "import geopandas\n", |
| 13 | + "import json\n", |
| 14 | + "\n", |
| 15 | + "countries = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", |
| 16 | + "rivers = geopandas.read_file(\"https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_lake_centerlines.zip\")\n", |
| 17 | + "\n", |
| 18 | + "m = Map(center=(28.6019917,70.9121356), zoom = 3, basemap= basemaps.Esri.WorldTopoMap)\n", |
| 19 | + "\n", |
| 20 | + "geo_data = GeoData(geo_dataframe = countries,\n", |
| 21 | + " style={'color': 'black', 'fillColor': '#366370', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},\n", |
| 22 | + " hover_style={'fillColor': '#b08a3e' , 'fillOpacity': 0.9},\n", |
| 23 | + " name = 'Countries')\n", |
| 24 | + "\n", |
| 25 | + "\n", |
| 26 | + "m.add_layer(geo_data)\n", |
| 27 | + "m" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": null, |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "from ipywidgets import Text, HTML\n", |
| 37 | + "from ipyleaflet import WidgetControl, GeoJSON \n", |
| 38 | + "\n", |
| 39 | + "\n", |
| 40 | + "html = HTML('''\n", |
| 41 | + " <h4> population density</h4>\n", |
| 42 | + " Hover over a state\n", |
| 43 | + "''')\n", |
| 44 | + "html.layout.margin = '0px 20px 20px 20px'\n", |
| 45 | + "control = WidgetControl(widget=html, position='topright')\n", |
| 46 | + "m.add_control(control)" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": null, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
| 55 | + "def update_html(feature, **kwargs):\n", |
| 56 | + " html.value = '''\n", |
| 57 | + " <h5>Population density</h5>\n", |
| 58 | + " <h5><b>{}</b></h5>\n", |
| 59 | + " {} people \n", |
| 60 | + " <h5><b> Continent : {} </b></h5>\n", |
| 61 | + " <h15> GDP : {} </h15> \n", |
| 62 | + " '''.format(feature['properties']['name'],\n", |
| 63 | + " feature['properties']['pop_est'],\n", |
| 64 | + " feature['properties']['continent'],\n", |
| 65 | + " feature['properties']['gdp_md_est'])\n", |
| 66 | + "\n", |
| 67 | + "geo_data.on_hover(update_html)" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": null, |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "from ipyleaflet import FullScreenControl, LayersControl\n", |
| 77 | + "m.add_control(FullScreenControl())" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "metadata": {}, |
| 84 | + "outputs": [], |
| 85 | + "source": [] |
| 86 | + } |
| 87 | + ], |
| 88 | + "metadata": { |
| 89 | + "kernelspec": { |
| 90 | + "display_name": "Python 3", |
| 91 | + "language": "python", |
| 92 | + "name": "python3" |
| 93 | + }, |
| 94 | + "language_info": { |
| 95 | + "codemirror_mode": { |
| 96 | + "name": "ipython", |
| 97 | + "version": 3 |
| 98 | + }, |
| 99 | + "file_extension": ".py", |
| 100 | + "mimetype": "text/x-python", |
| 101 | + "name": "python", |
| 102 | + "nbconvert_exporter": "python", |
| 103 | + "pygments_lexer": "ipython3", |
| 104 | + "version": "3.7.3" |
| 105 | + } |
| 106 | + }, |
| 107 | + "nbformat": 4, |
| 108 | + "nbformat_minor": 2 |
| 109 | +} |
0 commit comments