LuciadCPillar 2024.0.04
luciad::LayerList Class Referencefinal

Represents an ordered list of layers. More...

#include <luciad/layers/LayerList.h>

Public Member Functions

 LayerList ()
 Constructs an empty layer list. More...
 
 ~LayerList ()
 
void add (std::shared_ptr< Layer > layer)
 Adds the given layer to this layer list. More...
 
void add (std::shared_ptr< Layer > layer, size_t targetIndex)
 Adds the given layer to this layer list. More...
 
void addObserver (std::shared_ptr< ILayerListObserver > observer, bool seedObserver=false)
 Adds an observer to be notified of changes to this layer list. More...
 
std::shared_ptr< LayerfindLayerById (LayerId layerId) const
 Searches for the layer with a provided id in the layer list. More...
 
std::vector< std::shared_ptr< Layer > > getLayers () const
 Returns the vector that represents the ordering of all layers in this layer list. More...
 
void move (LayerId layerId, size_t targetIndex)
 Moves the layer with the given id to the target index. More...
 
void remove (LayerId layerId)
 Removes the layer with the given id. More...
 
void removeObserver (const std::shared_ptr< ILayerListObserver > &observer)
 Removes the given observer. More...
 

Detailed Description

Represents an ordered list of layers.

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

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 & Destructor Documentation

◆ LayerList()

luciad::LayerList::LayerList ( )

Constructs an empty layer list.

◆ ~LayerList()

luciad::LayerList::~LayerList ( )

Member Function Documentation

◆ add() [1/2]

void luciad::LayerList::add ( std::shared_ptr< Layer layer)

Adds the given layer to this layer list.

Parameters
layera layer
Exceptions
luciad::InvalidArgumentExceptionwhen the layer has already been added.
luciad::NullArgumentExceptionwhen the layer is nullptr.

◆ add() [2/2]

void luciad::LayerList::add ( std::shared_ptr< Layer layer,
size_t  targetIndex 
)

Adds the given layer to this layer list.

Parameters
layera layer
targetIndexthe index at which to add the layer
Exceptions
luciad::InvalidArgumentExceptionexception when the layer has already been added or when the target index is not in range.
luciad::NullArgumentExceptionwhen the layer is nullptr.

◆ addObserver()

void luciad::LayerList::addObserver ( std::shared_ptr< ILayerListObserver observer,
bool  seedObserver = false 
)

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
observeran observer, must not be nullptr
seedObserverwhether to inform the observer about the layers that are currently present
Exceptions
luciad::InvalidArgumentExceptionwhen the observer was already added.
luciad::NullArgumentExceptionwhen the observer is nullptr.

◆ findLayerById()

std::shared_ptr< Layer > luciad::LayerList::findLayerById ( LayerId  layerId) const

Searches for the layer with a provided id in the layer list.

Parameters
layerIda layer id
Returns
the layer that corresponds with the given id, or nullptr.

◆ getLayers()

std::vector< std::shared_ptr< Layer > > luciad::LayerList::getLayers ( ) const

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.

◆ move()

void luciad::LayerList::move ( LayerId  layerId,
size_t  targetIndex 
)

Moves the layer with the given id to the target index.

Parameters
layerIdthe id of the layer to move
targetIndexa target index
Exceptions
luciad::InvalidArgumentExceptionwhen this LayerList does not contain a layer with the given id or when the target index is not in range

◆ remove()

void luciad::LayerList::remove ( LayerId  layerId)

Removes the layer with the given id.

Parameters
layerIdthe id of the layer to remove
Exceptions
luciad::InvalidArgumentExceptionwhen this LayerList does not contain a layer with the given id

◆ removeObserver()

void luciad::LayerList::removeObserver ( const std::shared_ptr< ILayerListObserver > &  observer)

Removes the given observer.

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

Parameters
observeran observer, must not be nullptr
Exceptions
luciad::InvalidArgumentExceptionwhen the observer is not known.
luciad::NullArgumentExceptionwhen the observer is nullptr.