Skip to content

Add leaflet_method decorator #2157

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

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

Conversation

hansthen
Copy link
Collaborator

@hansthen hansthen commented Jun 7, 2025

This allows javascript method calls to be generated using an empty method body and a signature. Useful for writing plugins.

As an example (and the driving motivation) I implemented this on the geoman plugin.

This allows javascript method calls to be generated using
an empty method body and a signature. Useful for writing plugins.

As an example (and the driving motivation) I implemented this on
the geoman plugin.
@hansthen hansthen requested a review from ocefpaf June 7, 2025 11:31
@ocefpaf
Copy link
Member

ocefpaf commented Jun 9, 2025

Interesting. I don't grasp everything here and the only feedback I can give you is that I would like more tests before we merge this one.

@hansthen
Copy link
Collaborator Author

hansthen commented Jun 9, 2025

I added a small snapshot test. What the decorator does is generate javascript code whenever a python method is called. So writing the following python client code:

# For manual testing of the global options
gm.set_global_options(
    {
        "snappable": True,
        "snapDistance": 20,
    }
)

# Make rectangles green
gm.enable_draw("Rectangle", path_options={"color": "green"})
gm.disable_draw()

will generate the following javascript code:

<name>.setGlobalOptions(
    {
        "snappable": true,
        "snapDistance": 20,
    }
)
<name>.enableDraw("Rectangle", {pathOptions: {"color": "green"}})
<name>.disableDraw()

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