lonboard
lonboard copied to clipboard
Add a layer control for toggling layer on/off
It would be nice to have a layer control for toggling layers on/off, similar to ipyleaflet and folium. This is particularly useful when multiple layers are rendered on the map.
Reference: https://github.com/visgl/deck.gl/issues/4565
At this point, I don't have the development bandwidth to make customized JS-based layer controls.
But the good news is, you can make a widget-based layer control yourself pretty easily, and it should work out of the box with lonboard 0.2.
If you look at the ColorPicker example, you'll see that I create another widget that I link to the map widget. You can use a series of ipywidgets.checkbox, grouped together in a vbox, and where each checkbox is linked using link to layer.visible. Then you can show/hide the layer by clicking on the widget checkboxes.
I'd consider a PR that generates a widget-based layer control from a map object.
(that deck.gl issue is irrelevant)
Is there still an appetite for a widget-based layer control from a map object.
I've got some code that goes beyond making a set of check boxes to control layer visibility. It also generates a button along side the visibility check box which toggles a set of widgets that are used for manipulating the layer's traits as well (the settings widgets can also be toggled off when creating the table of contents as well, leaving just the visibility check boxes).
To create the the settings for the layers it iterates thru the layers traits ignoring the visible, and selected_index traits, and depending on the trait's type it generates the appropriate widget type to manipulate the layer's trait. For the ColorAccessors I've wired up a bidirectional syncing for the layer's color to the ipywidgets color picker. For the numeric traits that have a min/max I've wired up bounded int/float widgets that enforce the min/max values (other than substituting 999999999999 for infinity since ipywidgets doesnt like infinity). For the traits that are None, the properties simply will not create/display a widget for the property because the widgets don't (to my knowledge) work with None values.
In the code I currently have, I'm adding a trait to the layer to hold a βtitleβ for the layer that can be displayed in the TOC using
layer.add_traits(**{"title":traitlets.CUnicode(default_value="Layer", read_only = False)})
I think if we were to incorporate this into the Lonboard code, we'd want to formalize that trait into the lonboad._layer to ensure all layers have the trait.
Furthermore, the way I implemented the make_TOC() which generates the VBox for the TOC, it also observes the map's layers trait, so if a layer is added or removed from the map after the maps is created, the TOC will regenerate itself to match the map's current state.
Just glanced at the screenshots but π― π― π― that is exactly what I imagined we should be able to make via ipywidgets without making custom JS
excellent, I still need to clean up the code with some type hints, and add docstrings and whatnot, but hopefully I'll be able to push a PR tonight or sometime early this week π