-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |