{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, Marker, Circle, CircleMarker, LayerGroup, basemaps" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0f5e7ac8166645cab6c30d220d6246ab", "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)\n", "m" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Create a few layers\n", "marker = Marker(location=(52, 10))\n", "circle = Circle(location=(52, 12), radius=50000)\n", "circle_marker = CircleMarker(location=(52, 9), radius=10, color=\"red\", fill_color=\"red\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0f5e7ac8166645cab6c30d220d6246ab", "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": [ "# Create a group of layers and add it to the Map\n", "group = LayerGroup(layers=(marker,))\n", "m.add(group)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Add new layers to the group\n", "group.add(circle)\n", "group.add(circle_marker)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Remove one layer from the group\n", "group.remove(marker)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Remove layers from the group\n", "group.clear()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }