layer_sliderο
- util.layer_slider(m, layers=None, pos=None, txt_patch_props=None, exclude_layers=None, name=None, **kwargs)ο
Get a slider-widget that can be used to switch between layers.
By default, the widget will auto-update itself if new layers are created!
Note
In general, layers are only drawn βon demandβ, so if you switch to a layer that has not been shown yet, it needs to be drawn first.
Depending on the complexity (WebMaps, Overlays, very large datasets etc.) this might take a few seconds.
Once the layer has been drawn, it is cached and switching even between layers with many features should be fast.
If the extent of the map changes (e.g. pan/zoom) or new features are added to the layer, it will be re-drawn.
- Parameters:
layers (list or None, optional) β
A list of layer-names (or tuples of layer-names to combine) that are be used in the slider. For details on how to use combined layers, check the docstring of m.show_layer()
If None, all available layers (except the βallβ layer) are shown, and the layers are automatically updated whenever a new layer is created on the map. (check the βexclude_layersβ parameter for excluding specific layers) The default is None.
pos (list or None, optional) β The position of the slider in figure-coordinates, provided as: (x0, y0, width, height). If None, the slider will be added at the bottom of the current axis. The default is None.
txt_patch_props (dict or None) β
A dict used to style the background-patch of the text (e.g. the layer-names)
For example:
>>> dict(fc="w", ec="none", alpha=0.75, boxstyle="round, pad=.25")
If None, no background patch will be added to the text.
The default is None.
exclude_layers (list or None) β A list of layer-names that should be excluded. Only relevant if layers=None is used. The default is None in which case only the βallβ layer is excluded. (Same as exclude = [βallβ]. Use exclude=[] to get all available layers.)
name (str) β The name of the slider (used to identify the object) If None, a unique identifier is used.
kwargs β
Additional kwargs are passed to matplotlib.widgets.Slider
The default is
>>> dict(initcolor="none", >>> handle_style=dict(facecolor=".8", edgecolor="k", size=7), >>> label=None, >>> track_color="0.8", >>> color="0.2" >>> )
Examples
>>> from eomaps import Maps >>> m = Maps(layer="coastline") >>> m2 = m.new_layer(layer="ocean") >>> m.add_feature.preset.coastline() >>> m2.add_feature.preset.ocean() >>> s = m.util.layer_slider( >>> layers=["ocean", "coastline", >>> (("ocean", .5), "coastline")])
To remove the widget (s), simply use:
>>> s.remove()