{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "f2fda73d-1e28-41a8-bf5b-901e3f38866c", "metadata": {}, "outputs": [], "source": [ "import piplite\n", "await piplite.install('ipyleaflet')" ] }, { "cell_type": "code", "execution_count": null, "id": "644c9514-a50f-4e9e-b95f-f8560f1052de", "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, Marker\n", "center = (52.204793, 360.121558)\n", "map = Map(center=center, zoom=12)\n", "\n", "# Add a draggable marker to the map\n", "# Dragging the marker updates the marker.location value in Python\n", "marker = Marker(location=center, draggable=True)\n", "map.add_control(marker)\n", "\n", "display(map)" ] }, { "cell_type": "code", "execution_count": null, "id": "790628ed-dfd6-4ac4-af2c-6ea91d1d16ef", "metadata": {}, "outputs": [], "source": [ "# We can also update the marker location from Python\n", "marker.location = (52.2, 360.1)" ] }, { "cell_type": "code", "execution_count": null, "id": "253e96c1-7673-43c8-86dc-9d5244ff10d0", "metadata": {}, "outputs": [], "source": [ "# We can run a python function when the marker location changes\n", "# Here we'll adjust the center of the map to follow the marker\n", "def on_location_changed(value):\n", " map.center = value.new\n", "\n", "# Call the on_location_changed function when marker.location changes\n", "marker.observe(on_location_changed, 'location')" ] } ], "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": 5 }