|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 | 5 | "execution_count": null,
|
6 |
| - "id": "1d3b8b34", |
| 6 | + "id": "f2fda73d-1e28-41a8-bf5b-901e3f38866c", |
7 | 7 | "metadata": {},
|
8 | 8 | "outputs": [],
|
9 | 9 | "source": [
|
10 | 10 | "import piplite\n",
|
11 |
| - "await piplite.install('ipyleaflet');" |
| 11 | + "await piplite.install('ipyleaflet')" |
12 | 12 | ]
|
13 | 13 | },
|
14 | 14 | {
|
15 | 15 | "cell_type": "code",
|
16 | 16 | "execution_count": null,
|
17 |
| - "id": "48a5cc23", |
| 17 | + "id": "644c9514-a50f-4e9e-b95f-f8560f1052de", |
18 | 18 | "metadata": {},
|
19 | 19 | "outputs": [],
|
20 | 20 | "source": [
|
21 |
| - "from ipyleaflet import Map, basemaps, basemap_to_tiles\n", |
| 21 | + "from ipyleaflet import Map, Marker\n", |
| 22 | + "center = (52.204793, 360.121558)\n", |
| 23 | + "map = Map(center=center, zoom=12)\n", |
22 | 24 | "\n",
|
23 |
| - "m = Map(\n", |
24 |
| - " basemap=basemap_to_tiles(basemaps.OpenStreetMap.Mapnik),\n", |
25 |
| - " center=(48.204793, 350.121558),\n", |
26 |
| - " zoom=3\n", |
27 |
| - " )\n", |
28 |
| - "m" |
| 25 | + "# Add a draggable marker to the map\n", |
| 26 | + "# Dragging the marker updates the marker.location value in Python\n", |
| 27 | + "marker = Marker(location=center, draggable=True)\n", |
| 28 | + "map.add_control(marker)\n", |
| 29 | + "\n", |
| 30 | + "display(map)" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": null, |
| 36 | + "id": "790628ed-dfd6-4ac4-af2c-6ea91d1d16ef", |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "# We can also update the marker location from Python\n", |
| 41 | + "marker.location = (52.2, 360.1)" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": null, |
| 47 | + "id": "253e96c1-7673-43c8-86dc-9d5244ff10d0", |
| 48 | + "metadata": {}, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "# We can run a python function when the marker location changes\n", |
| 52 | + "# Here we'll adjust the center of the map to follow the marker\n", |
| 53 | + "def on_location_changed(value):\n", |
| 54 | + " map.center = value.new\n", |
| 55 | + "\n", |
| 56 | + "# Call the on_location_changed function when marker.location changes\n", |
| 57 | + "marker.observe(on_location_changed, 'location')" |
29 | 58 | ]
|
30 | 59 | }
|
31 | 60 | ],
|
|
45 | 74 | "name": "python",
|
46 | 75 | "nbconvert_exporter": "python",
|
47 | 76 | "pygments_lexer": "ipython3",
|
48 |
| - "version": "3.9.12" |
| 77 | + "version": "3.10.5" |
49 | 78 | }
|
50 | 79 | },
|
51 | 80 | "nbformat": 4,
|
|
0 commit comments