Skip to content

Commit d393780

Browse files
committed
Update ipyleaflet main example to show interactivity
1 parent c96e4f5 commit d393780

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

docs/source/ipyleaflet.ipynb

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,58 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "1d3b8b34",
6+
"id": "f2fda73d-1e28-41a8-bf5b-901e3f38866c",
77
"metadata": {},
88
"outputs": [],
99
"source": [
1010
"import piplite\n",
11-
"await piplite.install('ipyleaflet');"
11+
"await piplite.install('ipyleaflet')"
1212
]
1313
},
1414
{
1515
"cell_type": "code",
1616
"execution_count": null,
17-
"id": "48a5cc23",
17+
"id": "644c9514-a50f-4e9e-b95f-f8560f1052de",
1818
"metadata": {},
1919
"outputs": [],
2020
"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",
2224
"\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')"
2958
]
3059
}
3160
],
@@ -45,7 +74,7 @@
4574
"name": "python",
4675
"nbconvert_exporter": "python",
4776
"pygments_lexer": "ipython3",
48-
"version": "3.9.12"
77+
"version": "3.10.5"
4978
}
5079
},
5180
"nbformat": 4,

0 commit comments

Comments
 (0)