Clicked point¶
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
method.
In [ ]:
Copied!
from typing import Tuple
import ipywidgets as widgets
from lonboard import Map
## Create a Lonboard map and two widgets to display the coordinate
m = Map(layers=[])
clicked_x_display = widgets.FloatText(description="last clicked x:")
clicked_y_display = widgets.FloatText(description="last clicked y:")
def on_map_click(coordinate: Tuple[float, float]) -> None:
x, y = coordinate
clicked_x_display.value = x
clicked_y_display.value = y
m.on_click(on_map_click)
## show the widgets
widgets.VBox(
[
m,
clicked_x_display,
clicked_y_display,
],
)
from typing import Tuple
import ipywidgets as widgets
from lonboard import Map
## Create a Lonboard map and two widgets to display the coordinate
m = Map(layers=[])
clicked_x_display = widgets.FloatText(description="last clicked x:")
clicked_y_display = widgets.FloatText(description="last clicked y:")
def on_map_click(coordinate: Tuple[float, float]) -> None:
x, y = coordinate
clicked_x_display.value = x
clicked_y_display.value = y
m.on_click(on_map_click)
## show the widgets
widgets.VBox(
[
m,
clicked_x_display,
clicked_y_display,
],
)