Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor position #332

Closed
pllim opened this issue Apr 11, 2019 · 6 comments
Closed

Cursor position #332

pllim opened this issue Apr 11, 2019 · 6 comments

Comments

@pllim
Copy link
Contributor

pllim commented Apr 11, 2019

Hi. How do I get the cursor position out of the map? Thank you.

@martinRenou
Copy link
Member

martinRenou commented Apr 11, 2019

There is a notebook on the repo that does it for displaying the cursor position in a Label widget:

from ipywidgets import Label
from ipyleaflet import Map

m = Map()

label = Label()
display(label)

def handle_interaction(**kwargs):
    if kwargs.get('type') == 'mousemove':
        label.value = str(kwargs.get('coordinates'))

m.on_interaction(handle_interaction)

m

@pllim
Copy link
Contributor Author

pllim commented Apr 15, 2019

Thanks for the quick response. What if I don't want the Earth coordinates, but rather raw offset values from the viewer's (0, 0) (i.e., lower left corner)?

@martinRenou
Copy link
Member

I guess you would need to compute them yourself, given the cursor position, the south, north, east and west Map attributes. If what you want is pixel coordinates it would also depend on the Map size in the DOM.

@pllim
Copy link
Contributor Author

pllim commented Apr 15, 2019

@eteq just told me about #327 and I think that is closer to what I actually need. Thank you!

@martinRenou
Copy link
Member

Oh yeah, definitely!

@stepsbystep
Copy link

This is just great, amazing, so simple, thank you @martinRenou!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants