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

Add on_zoom #1214

Closed
wants to merge 1 commit into from
Closed

Conversation

lopezvoliver
Copy link
Contributor

This new on_zoom feature is useful for implementing zoom-dependent logic, e.g. adding or removing components to the map based on zoom level.

For example:

def handle_zoom(**kwargs):
    z = kwargs["zoom"]
    legend_on_map = legend_control.model_id in m._control_ids
    if (z>9):
        if not legend_on_map:
            m.add(legend_control)
    else:
        if legend_on_map:
            m.remove(legend_control)

m.on_zoom(handle_zoom)

where legend_control is a control that I want shown only on zoom 10 or above:

@martinRenou
Copy link
Member

Thanks! I believe this was already possible using traitlets:

m = Map()

m.observe(handle_zoom, 'zoom')

@lopezvoliver
Copy link
Contributor Author

Thanks! I believe this was already possible using traitlets:

m = Map()

m.observe(handle_zoom, 'zoom')

This works, I can access the 'new' zoom in my handle_zoom function. Thanks!

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