Class LayerList

java.lang.Object
com.luciad.layers.LayerList
All Implemented Interfaces:
AutoCloseable

public final class LayerList extends Object implements AutoCloseable
Represents an ordered list of layers.

The order within this list determines the order in which layers are painted.

A LayerList should be active on only one Map at a time. Either by being set directly or indirectly via a IController.

Note that this class tracks on which thread it is constructed. This is done so that, in subsequent calls, it can verify that the same threads are used consistently. When an inconsistency is detected, an assertion is triggered. This means that all functions on LayerList must be called on the thread on which the Map was constructed (the "UI" thread). The only exception is adding and removing observers. Related article: Threading rules for the Map

  • Constructor Details

    • LayerList

      public LayerList()
      Constructs an empty layer list.
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getLayers

      @NotNull public List<@NotNull Layer> getLayers()
      Returns the vector that represents the ordering of all layers in this layer list.

      The order is defined as bottom-to-top. This means that the first layer in this vector is painted first (and appears at the bottom), and that the last layer of this vector is painted last (and appears at the top).

      Returns:
      the vector that represents the ordering of all layers in this layer list.
    • findLayerById

      @Nullable public Layer findLayerById(long layerId)
      Searches for the layer with a provided id in the layer list.
      Parameters:
      layerId - a layer id
      Returns:
      the layer that corresponds with the given id, or null.
    • indexOf

      @Nullable public Long indexOf(long layerId)
      Returns the index of the given layer in the LayerList, or null if it's not part of the LayerList.
      Parameters:
      layerId - a layer id.
      Returns:
      the index that corresponds with the given id, or null
      Since:
      2024.1.
    • add

      public void add(@NotNull Layer layer) throws IllegalArgumentException, NullPointerException
      Adds the given layer to this layer list.
      Parameters:
      layer - a layer
      Throws:
      IllegalArgumentException - when the layer has already been added to a LayerList.
      NullPointerException - when the layer is null.
    • add

      public void add(@NotNull Layer layer, long targetIndex) throws IllegalArgumentException, NullPointerException
      Adds the given layer to this layer list.
      Parameters:
      layer - a layer
      targetIndex - the index at which to add the layer
      Throws:
      IllegalArgumentException - exception when the layer has already been added to a LayerList or when the target index is not in range.
      NullPointerException - when the layer is null.
    • remove

      public void remove(long layerId) throws IllegalArgumentException
      Removes the layer with the given id.
      Parameters:
      layerId - the id of the layer to remove
      Throws:
      IllegalArgumentException - when this LayerList does not contain a layer with the given id
    • move

      public void move(long layerId, long targetIndex) throws IllegalArgumentException
      Moves the layer with the given id to the target index.
      Parameters:
      layerId - the id of the layer to move
      targetIndex - a target index
      Throws:
      IllegalArgumentException - when this LayerList does not contain a layer with the given id or when the target index is not in range
    • addObserver

      public void addObserver(@NotNull ILayerListObserver observer, boolean seedObserver) throws IllegalArgumentException, NullPointerException
      Adds an observer to be notified of changes to this layer list.

      Adding the same observer twice is forbidden, and will cause an exception to be thrown.

      Parameters:
      observer - an observer, must not be null
      seedObserver - whether to inform the observer about the layers that are currently present
      Throws:
      IllegalArgumentException - when the observer was already added.
      NullPointerException - when the observer is null.
    • addObserver

      public void addObserver(@NotNull ILayerListObserver observer) throws IllegalArgumentException, NullPointerException
      Adds an observer to be notified of changes to this layer list.

      Adding the same observer twice is forbidden, and will cause an exception to be thrown.

      Parameters:
      observer - an observer, must not be null
      Throws:
      IllegalArgumentException - when the observer was already added.
      NullPointerException - when the observer is null.
    • removeObserver

      public void removeObserver(@NotNull ILayerListObserver observer) throws IllegalArgumentException, NullPointerException
      Removes the given observer.

      If the given observer was never added, an exception is thrown.

      Parameters:
      observer - an observer, must not be null
      Throws:
      IllegalArgumentException - when the observer is not known.
      NullPointerException - when the observer is null.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object