Skip to content

Instantly share code, notes, and snippets.

@bobhaffner
Created May 16, 2022 12:51
Show Gist options
  • Save bobhaffner/697314bb7f34773ef13dec3f4045a48a to your computer and use it in GitHub Desktop.
Save bobhaffner/697314bb7f34773ef13dec3f4045a48a to your computer and use it in GitHub Desktop.
ipyleaflet on_interaction example
from ipywidgets import Label
from ipyleaflet import Map
m = Map(center=[42,-90], zoom=4)
label = Label()
display(label)
def handle_interaction(**kwargs):
if kwargs.get('type') == 'click':
print(str(kwargs.get('coordinates')))
if kwargs.get('type') == 'mousemove':
label.value = str(kwargs.get('coordinates'))
m.on_interaction(handle_interaction)
m
@bobhaffner
Copy link
Author

Coordinates will print when you click and coordinates will display in label when you move the mouse over the map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment