All Implemented Interfaces:
Serializable, Identifiable, ExecutableFunctions

public class LayersControl extends LeafletControl
The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the detailed example). Extends Control.

The baseLayers and overlays parameters are object literals with layer names as keys and Layer objects as values.

The layer names can contain HTML, which allows you to add additional styling to the items.
Since:
2020-05-29
Version:
1.0
Author:
Gabor Kokeny Email: kokeny19@gmail.com
See Also:
  • Constructor Details

    • LayersControl

      public LayersControl()
      Creates a new layers control with empty base layers and overlays and default options.
    • LayersControl

      public LayersControl(LayersControlOptions options)
      Creates a new layers control with empty base layers and overlays and the given options.
      Parameters:
      options - the options for the layers control
    • LayersControl

      public LayersControl(Map<String,Layer> baseLayers)
      Creates a new layers control with the given base layers and default options.
      Parameters:
      baseLayers - the base layers keyed by their display name
    • LayersControl

      public LayersControl(Map<String,Layer> baseLayers, Map<String,Layer> overlays)
      Creates a new layers control with the given base layers and overlays and default options.
      Parameters:
      baseLayers - the base layers keyed by their display name
      overlays - the overlays keyed by their display name
    • LayersControl

      public LayersControl(Map<String,Layer> baseLayers, Map<String,Layer> overlays, LayersControlOptions options)
      Creates a new layers control with the given base layers, overlays and options.
      Parameters:
      baseLayers - the base layers keyed by their display name
      overlays - the overlays keyed by their display name
      options - the options for the layers control
  • Method Details

    • onBaseLayerChange

      public void onBaseLayerChange(LeafletEventListener<LayersControlEvent> listener)
      Fired when the base layer is changed through the layer control.
      Parameters:
      listener - the listener to call when the event occurs, not null
    • onOverlayAdd

      public void onOverlayAdd(LeafletEventListener<LayersControlEvent> listener)
      Fired when an overlay is selected through the layer control.
      Parameters:
      listener - the listener to call when the event occurs, not null
    • onOverlayRemove

      public void onOverlayRemove(LeafletEventListener<LayersControlEvent> listener)
      Fired when an overlay is selected through the layer control.
      Parameters:
      listener - the listener to call when the event occurs, not null
    • onLayerAdd

      public void onLayerAdd(LeafletEventListener<LayersControlEvent> listener)
      Fired when a new layer is added to the map.
      Parameters:
      listener - the listener to call when the event occurs, not null
    • onLayerRemove

      public void onLayerRemove(LeafletEventListener<LayersControlEvent> listener)
      Fired when some layer is removed from the map
      Parameters:
      listener - the listener to call when the event occurs, not null
    • expand

      public void expand()
      Expand the control container if collapsed.
    • collapse

      public void collapse()
      Collapse the control container if expanded.
    • addBaseLayer

      public void addBaseLayer(Layer layer, String name)
      Adds a base layer (radio button entry) with the given name to the control.
      Parameters:
      layer - the layer to be added to map as a base layer
      name - the name of the base layer
    • addOverlay

      public void addOverlay(Layer layer, String name)
      Adds an overlay (checkbox entry) with the given name to the control. *
      Parameters:
      layer - the layer to be added to map as an overlay
      name - the name of the overlay
    • removeLayer

      public void removeLayer(Layer layer)
      Remove the given layer from the control.
      Parameters:
      layer - the layer which should be removed from the LayersControl
    • isCollapsed

      public boolean isCollapsed()
      Gets whether the control is initially collapsed into an icon.
      Returns:
      true if the control is collapsed, false otherwise
    • isAutoZIndex

      public boolean isAutoZIndex()
      Gets whether the z-index of the layers is set automatically based on their order in the control.
      Returns:
      true if the z-index is set automatically, false otherwise
    • isHideSingleBase

      public boolean isHideSingleBase()
      Gets whether the base layers section is hidden when there is only a single base layer.
      Returns:
      true if a single base layer is hidden, false otherwise
    • isSortLayers

      public boolean isSortLayers()
      Gets whether the layers are sorted by name in the control.
      Returns:
      true if the layers are sorted, false otherwise
    • getBaseLayers

      public Map<String,Layer> getBaseLayers()
      Gets the base layers of the control keyed by their display name.
      Returns:
      the base layers keyed by their display name
    • getOverlays

      public Map<String,Layer> getOverlays()
      Gets the overlays of the control keyed by their display name.
      Returns:
      the overlays keyed by their display name