Skip to content

Commit

Permalink
add clicked point example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
ATL2001 authored Oct 5, 2024
1 parent d46ce3c commit bf26763
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions examples/clicked-point.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e328a21f-5254-42ee-9683-136561d96886",
"metadata": {},
"source": [
"# Clicked point\n",
"\n",
"This notebook demonstrates how you can access the coordinate of the most recent click on a Lonboard map and update a set of widgets to display the x and y coordinates using the [`ipywidgets.observe`](https://ipywidgets.readthedocs.io/en/8.1.5/examples/Widget%20Events.html#traitlet-events) method."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f986a64e-269f-4966-93b0-cfa5bf1ba882",
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"import traitlets\n",
"\n",
"from lonboard import Map\n",
"\n",
"## Create a Lonboard map and two widgets to display the coordinate\n",
"m = Map(layers=[])\n",
"clicked_x_display = widgets.FloatText(description=\"last clicked x:\")\n",
"clicked_y_display = widgets.FloatText(description=\"last clicked y:\")\n",
"\n",
"## create a function that accepts the event which fires when we single click in\n",
"## the map while we are not in bounding box selection mode\n",
"def on_map_click(event: traitlets.utils.bunch.Bunch) -> None:\n",
" x,y = event.get(\"new\")\n",
" clicked_x_display.value = x\n",
" clicked_y_display.value = y\n",
"m.observe(on_map_click, \"clicked_point\")\n",
"\n",
"## show the widgets\n",
"widgets.VBox([\n",
" m,\n",
" clicked_x_display,\n",
" clicked_y_display\n",
"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "lonboard",
"language": "python",
"name": "lonboard"
},
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit bf26763

Please sign in to comment.