{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "m = Map(center=(52, 10), zoom=8, basemap=basemaps.Hydda.Full)\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "strata_all = basemap_to_tiles(basemaps.Strava.All)\n", "m.add_layer(strata_all)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# mouse interaction handling\n", "\n", "from ipywidgets import Label\n", "\n", "label = Label()\n", "display(label)\n", "\n", "def handle_interaction(**kwargs):\n", " if kwargs.get('type') == 'mousemove':\n", " label.value = str(kwargs.get('coordinates'))\n", "\n", "m.on_interaction(handle_interaction)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "strata_water = basemap_to_tiles(basemaps.Strava.Water)\n", "m.substitute_layer(strata_all, strata_water)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Adding an overlay layer\n", "import json\n", "\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", "geo = GeoJSON(data=data, hover_style={'fillColor': 'red'}, name='Countries')\n", "m.add_layer(geo)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Adding the control\n", "m.add_control(LayersControl())" ] } ], "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }