{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2395000484b445ca8a84934119bd192f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map(center=[52, 10], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_tex…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "m = Map(center=(52, 10), zoom=8, basemap=basemaps.OpenStreetMap.Mapnik)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2395000484b445ca8a84934119bd192f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map(bottom=21848.0, center=[52, 10], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "strava_all = basemap_to_tiles(basemaps.Strava.All)\n", "m.add(strava_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", "\n", "def handle_interaction(**kwargs):\n", " if kwargs.get(\"type\") == \"mousemove\":\n", " label.value = str(kwargs.get(\"coordinates\"))\n", "\n", "\n", "m.on_interaction(handle_interaction)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "strava_water = basemap_to_tiles(basemaps.Strava.Water)\n", "m.substitute_layer(strava_all, strava_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(geo)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Adding the control\n", "m.add(LayersControl())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Creating two maps side by side\n", "import ipywidgets\n", "\n", "ipywidgets.HBox([m, Map(center=[43.6, 1.44], zoom=10)])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.5" } }, "nbformat": 4, "nbformat_minor": 4 }