Skip to content

How to retrieve the coordinates on-click and save it as a variable? #1213

Answered by giswqs
hamiddashti asked this question in Q&A
Discussion options

You must be logged in to vote

You can create an attribute for the Map (.e.g., Map.points = []), and append points to the list with mouse click events. Then retrieve the points using Map.points

import ee
import geemap
import ipywidgets as widgets
from ipyleaflet import WidgetControl
Map = geemap.Map()
Map.points = []

# Add an output widget to the map
output_widget = widgets.Output(layout={'border': '1px solid black'})
output_control = WidgetControl(widget=output_widget, position='bottomright')
Map.add_control(output_control)

# Capture user interaction with the map
def handle_interaction(**kwargs):
    latlon = kwargs.get('coordinates')
    if kwargs.get('type') == 'click':
        Map.default_style = {'cursor': 'wait'}…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by giswqs
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants