<jupyter_start><jupyter_text>Handling hover and click map events[![open_in_colab][colab_badge]][colab_notebook_link][![open_in_binder][binder_badge]][binder_notebook_link][colab_badge]: https://colab.research.google.com/assets/colab-badge.svg[colab_notebook_link]: https://colab.research.google.com/github/UnfoldedInc/examples/blob/master/notebooks/08%20-%20Eventhandling.ipynb[binder_badge]: https://mybinder.org/badge_logo.svg[binder_notebook_link]: https://mybinder.org/v2/gh/UnfoldedInc/examples/master?urlpath=lab/tree/notebooks/08%20-%20Eventhandling.ipynbUsing the [set_map_event_handlers](https://docs.unfolded.ai/map-sdk/api/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.  DependenciesThis 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.<jupyter_code># If in Colab, install this notebook's required dependencies
import sys
if "google.colab" in sys.modules:
    !pip install 'unfolded.map_sdk>=0.6.0'<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>from unfolded.map_sdk import UnfoldedMap
import ipywidgets as widgets<jupyter_output><empty_output><jupyter_text>Handling event callbacks<jupyter_code>unfolded_map = UnfoldedMap(mapUUID='fb6aad80-eb4c-4f33-86eb-668772cc5fc4')
unfolded_map<jupyter_output><empty_output><jupyter_text>We define the `on_hover` callback function:<jupyter_code>output = widgets.Output()
@output.capture(clear_output=True)
def on_hover_output(info):
    print('Hover event')
    print(info)
output<jupyter_output><empty_output><jupyter_text>We define the `on_click` callback function:<jupyter_code>output = widgets.Output()
@output.capture(clear_output=True)
def on_click_output(info):
    print('Click event')
    print(info)
output<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>unfolded_map.set_map_event_handlers({
    'on_hover': on_hover_output,
    'on_click': on_click_output
})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10168793742280774, 'fraction_numerical': 0.013585837793330589, 'mean_word_length': 7.741007194244604, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '145708', 'license': 'MIT', 'n_tokens_mistral': 846, 'n_tokens_neox': 814, 'n_words': 170, 'path': 'notebooks/08 - Eventhandling.ipynb', 'repo_name': 'RandomFractals/examples', 'size': '2429'}