All Implemented Interfaces:
Serializable, Evented, LayerGroupFunctions, Identifiable, LayerPopupFunctions, LayerTooltipFunctions, ExecutableFunctions
Direct Known Subclasses:
FeatureGroup

public class LayerGroup extends Layer implements LayerGroupFunctions
Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Extends Layer.
Since:
2020-02-06
Version:
1.1
Author:
Gabor Kokeny Email: kokeny19@gmail.com
See Also:
  • Constructor Details

    • LayerGroup

      public LayerGroup(Layer... layers)
      Creates a layer group containing the given layers.
      Parameters:
      layers - the layers to add to this group
    • LayerGroup

      public LayerGroup(List<Layer> layers)
      Creates a layer group containing the given layers.
      Parameters:
      layers - the layers to add to this group
  • Method Details

    • toGeoJSON

      public void toGeoJSON(int precision)
      precision is the number of decimal places for coordinates. The default value is 6 places. Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).
      Parameters:
      precision - the precision
    • addLayer

      public void addLayer(Layer layer)
      Adds the given layer to the group.
      Specified by:
      addLayer in interface LayerGroupFunctions
      Parameters:
      layer - the layer to be add
    • removeLayer

      public void removeLayer(Layer layer)
      Removes the given layer from the group.
      Specified by:
      removeLayer in interface LayerGroupFunctions
      Parameters:
      layer - the layer to remove
    • removeLayer

      public void removeLayer(String layerId)
      Removes the layer with the given internal ID from the group.
      Specified by:
      removeLayer in interface LayerGroupFunctions
      Parameters:
      layerId - the internal ID of the layer to remove
    • hasLayer

      public boolean hasLayer(Layer layer)
      Returns whether the given layer is currently in the group.
      Specified by:
      hasLayer in interface LayerGroupFunctions
      Parameters:
      layer - the layer to check
      Returns:
      true if the layer is in the group
    • hasLayer

      public boolean hasLayer(String layerId)
      Returns whether a layer with the given internal ID is currently in the group.
      Specified by:
      hasLayer in interface LayerGroupFunctions
      Parameters:
      layerId - the internal ID of the layer to check
      Returns:
      true if a matching layer is in the group
    • clearLayers

      public void clearLayers()
      Removes all layers from the group.
      Specified by:
      clearLayers in interface LayerGroupFunctions
    • invoke

      public void invoke(String functionName)
      Calls methodName on every layer contained in this group, passing any additional parameters. Has no effect if the layers contained do not implement methodName.
      Parameters:
      functionName - the function name to be invoke
    • eachLayer

      public void eachLayer(Consumer<Layer> action)
      Iterates over the layers of the group, optionally specifying context of the iterator function.
      Parameters:
      action - the callback function
    • getLayer

      public Optional<Layer> getLayer(String layerId)
      Returns the layer with the given internal ID.
      Parameters:
      layerId - layer to be check
      Returns:
      the layer with the given internal ID.
    • findLayer

      public Optional<Layer> findLayer(String layerId)
      Recursively searches this group and any nested layer groups for the layer with the given internal ID.
      Parameters:
      layerId - the internal ID of the layer to find
      Returns:
      the matching layer, or an empty optional if none is found
    • getLayers

      public List<Layer> getLayers()
      Returns an array of all the layers added to the group.
      Returns:
      an array of all the layers added to the group.
    • getLayerId

      public String getLayerId(Layer layer)
      Returns the internal ID for a layer
      Parameters:
      layer - a layer
      Returns:
      the id of the given layer
    • setZIndex

      public void setZIndex(int zIndex)
      Calls setZIndex on every layer contained in this group, passing the z-index.
      Parameters:
      zIndex - the z-index to be set on each layer