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

Clicked point to Lonboard map #671

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ATL2001
Copy link
Contributor

@ATL2001 ATL2001 commented Oct 5, 2024

This PR adds a new property to the Lonboard map that holds a tuple for the coordinate where the user last clicked on the map. It is not implemented as an .on_click(), as was discussed, but I think it accomplishes the same functionality (and may actually have more utility this way). hopefully this is an acceptable pattern, but if not, let me know and I'll see what I can do.

@kylebarron
Copy link
Member

I think the main question is whether we want to have this as a property or as an event.

In general, I think the right way to think about the traitlets is as serializing state. The data state should be the same on each side, so it makes sense for all the data properties to be traitlets. But stuff like the clicked point potentially should be an event handler instead.

@ATL2001
Copy link
Contributor Author

ATL2001 commented Oct 6, 2024

yeah, that's fair (and what I was originally going for). I think I got excited to get the information from the javascript side into somewhere I could access it from the python side and ran with it :). I'll poke around some more when I get some more free time to see if I can wire it up as a legit "on_click" event. With me being totally new to this sort of work, if you happen to have any pointers where to read anything about doing something like this, I'm all ears, my random searching the internet hasn't been as productive as I'd like

@kylebarron
Copy link
Member

see if I can wire it up as a legit "on_click" event

You can use custom messages. See https://ipywidgets.readthedocs.io/en/8.1.5/examples/Widget%20Events.html

You can use model.send from the JS side, like so https://github.com/developmentseed/lonboard/pull/413/files#diff-828f90355c3084df59b9704cc4339f114728cf2f2bfc2e9e977d7f96508e7525R48-R52

Then register an on_message handler on the Python side: https://github.com/developmentseed/lonboard/pull/413/files#diff-ab269100f27648760a02f3304913cbb24dbb1b8b2a7a3dc8b514aac5c15ff34dR543

And we'd probably have a wrapper to ensure that only messages with an ID of something like on-click get passed to the function the user passes in:
https://github.com/developmentseed/lonboard/pull/413/files#diff-ab269100f27648760a02f3304913cbb24dbb1b8b2a7a3dc8b514aac5c15ff34dR525

@ATL2001
Copy link
Contributor Author

ATL2001 commented Oct 7, 2024

Thanks Kyle, that helped a lot! I appear to have it all working on my end but need to get to work. I should be able to get it cleaned up and checked in tonight though!

@ATL2001
Copy link
Contributor Author

ATL2001 commented Oct 7, 2024

ok, all checked in, let me know what you think!

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

Successfully merging this pull request may close these issues.

2 participants