Class LayerCollection
Represents a collection of map layers with support for grouping, ordering, and change notifications.
Inherited Members
Namespace: Mapsui.Layers
Assembly: Mapsui.dll
Syntax
public class LayerCollection : IEnumerable<ILayer>, IEnumerable
Properties
| Edit this page View SourceCount
Gets the number of layers in the collection.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceAdd(ILayer, int)
Adds a layer to a specific group.
Declaration
public void Add(ILayer layer, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to add. |
| int | group | The group identifier (default is 0). |
Add(IEnumerable<ILayer>, int)
Adds multiple layers to a specific group.
Declaration
public void Add(IEnumerable<ILayer> layers, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<ILayer> | layers | The layers to add. |
| int | group | The group identifier (default is 0). |
AddOnBottom(ILayer, int)
Adds a layer at the bottom of the collection in a specific group.
Declaration
public void AddOnBottom(ILayer layer, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to add. |
| int | group | The group identifier (default is 0). |
AddOnTop(ILayer, int)
Adds a layer on top of the collection in a specific group.
Declaration
public void AddOnTop(ILayer layer, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to add. |
| int | group | The group identifier (default is 0). |
Clear(int)
Clears layers from a specific group.
Declaration
public void Clear(int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | group | The group identifier (default is 0). |
ClearAllGroups()
Clears all layers from all groups.
Declaration
public void ClearAllGroups()
FindLayer(string)
Finds layers in the collection by their name.
Declaration
public IEnumerable<ILayer> FindLayer(string layerName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | layerName | The name of the layer to find. |
Returns
| Type | Description |
|---|---|
| IEnumerable<ILayer> | The layers with the specified name. |
Get(int, int)
Gets a layer at a specific index in a group.
Declaration
public ILayer Get(int index, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The index of the layer. |
| int | group | The group identifier (default is 0). |
Returns
| Type | Description |
|---|---|
| ILayer | The layer at the specified index and group. |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<ILayer> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<ILayer> | An enumerator for the layers in the collection. |
GetLayers(int)
Retrieves all layers in a specific group.
Declaration
public IEnumerable<ILayer> GetLayers(int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | group | The group identifier (default is 0). |
Returns
| Type | Description |
|---|---|
| IEnumerable<ILayer> | All the layers in the specified group. |
GetLayersOfAllGroups()
Retrieves all layers from all groups.
Declaration
public IEnumerable<ILayer> GetLayersOfAllGroups()
Returns
| Type | Description |
|---|---|
| IEnumerable<ILayer> | All the layers of all groups. |
Insert(int, ILayer, int)
Inserts a layer at a specific index in a group.
Declaration
public void Insert(int index, ILayer layer, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The target index. |
| ILayer | layer | The layer to insert. |
| int | group | The group identifier (default is 0). |
Insert(int, IEnumerable<ILayer>, int)
Inserts multiple layers at a specific index in a group.
Declaration
public void Insert(int index, IEnumerable<ILayer> layers, int group = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The target index. |
| IEnumerable<ILayer> | layers | The layers to insert. |
| int | group | The group identifier (default is 0). |
Modify(IEnumerable<ILayer>, IEnumerable<ILayer>)
Modifies the layer collection by removing specified layers and adding new layers.
Declaration
public void Modify(IEnumerable<ILayer> layersToRemove, IEnumerable<ILayer> layersToAdd)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<ILayer> | layersToRemove | The layers to remove from the collection. |
| IEnumerable<ILayer> | layersToAdd | The layers to add to the collection. |
Modify(Func<ILayer, bool>, IEnumerable<ILayer>)
Modifies the layer collection by removing layers that match a specified predicate and adding new layers.
Declaration
public void Modify(Func<ILayer, bool> removePredicate, IEnumerable<ILayer> layersToAdd)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<ILayer, bool> | removePredicate | The predicate to determine which layers to remove from the collection. |
| IEnumerable<ILayer> | layersToAdd | The layers to add to the collection. |
Move(int, ILayer)
Moves a layer to a specific index in the collection.
Declaration
public void Move(int index, ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The target index. |
| ILayer | layer | The layer to move. |
MoveDown(ILayer)
Declaration
public void MoveDown(ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer |
MoveToBottom(ILayer)
Moves a layer to the bottom of it's current group. This means the other layers will be drawn on top of it.
Declaration
public void MoveToBottom(ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to move. |
MoveToTop(ILayer)
Moves a layer to the top of it's current group. This means this layer will be drawn on top of the other layers.
Declaration
public void MoveToTop(ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to move. |
MoveUp(ILayer)
Declaration
public void MoveUp(ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer |
Remove(ILayer)
Removes a specific layer from the collection.
Declaration
public bool Remove(ILayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer | layer | The layer to remove. |
Returns
| Type | Description |
|---|---|
| bool | True if the layer was removed successfully; otherwise, false. |
Remove(ILayer[])
Removes multiple layers from the collection.
Declaration
public bool Remove(ILayer[] layers)
Parameters
| Type | Name | Description |
|---|---|---|
| ILayer[] | layers | The layers to remove. |
Returns
| Type | Description |
|---|---|
| bool | True if all layers were removed successfully; otherwise, false. |
Remove(Func<ILayer, bool>)
Removes layers that match a specific predicate.
Declaration
public bool Remove(Func<ILayer, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<ILayer, bool> | predicate | The condition to match for removal. |
Returns
| Type | Description |
|---|---|
| bool | True if all matching layers were removed successfully; otherwise, false. |
Events
| Edit this page View SourceChanged
Occurs when the layer collection has changed (layers are added, removed, or moved).
Declaration
public event LayerCollection.LayerCollectionChangedEventHandler? Changed
Event Type
| Type | Description |
|---|---|
| LayerCollection.LayerCollectionChangedEventHandler |