-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clicked point to Lonboard map (#671)
This PR adds a new property to the Lonboard map that holds a tuple for the coordinate where the user last clicked on the map. It is not implemented as an .on_click(), as was [discussed](#633), but I think it accomplishes the same functionality (and may actually have more utility this way). hopefully this is an acceptable pattern, but if not, let me know and I'll see what I can do.
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,67 @@ | ||
{ | ||
"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": [ | ||
"from typing import Tuple\n", | ||
"\n", | ||
"import ipywidgets as widgets\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", | ||
"def on_map_click(coordinate:Tuple[float, float]) -> None:\n", | ||
" x,y = coordinate\n", | ||
" clicked_x_display.value = x\n", | ||
" clicked_y_display.value = y\n", | ||
"m.on_click(on_map_click)\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 | ||
} |
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
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
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