Using the set_map_event_handlers function it is possible to define event callbacks for the on_hover
and on_click
events. These events can return the data from the layer points or polygons if the user clicks or hovers on them.
This notebook requires the following Python dependencies:
unfolded.map-sdk
: The Unfolded Map SDKIf running this notebook in Binder, these dependencies should already be installed. If running in Colab, the next cell will install these dependencies.
# If in Colab, install this notebook's required dependencies
import sys
if "google.colab" in sys.modules:
!pip install 'unfolded.map_sdk>=1.0'
from unfolded.map_sdk import create_map
import ipywidgets as widgets
unfolded_map = create_map()
unfolded_map
We define the on_hover
callback function:
output = widgets.Output()
@output.capture(clear_output=True)
def on_hover_output(info):
print('Hover event')
print(info)
output
Output()
We define the on_click
callback function:
output = widgets.Output()
@output.capture(clear_output=True)
def on_click_output(info):
print('Click event')
print(info)
output
Output()
Here we register the defined callback functions. These functions will be called once you hover or click on the points or on the empty part of the map for the corresponding function.
unfolded_map.set_event_handlers({
'on_hover': on_hover_output,
'on_click': on_click_output
})