Back to Devexpress

MapControl.Layers Property

windowsforms-devexpress-dot-xtramap-dot-mapcontrol.md

latest8.6 KB
Original Source

MapControl.Layers Property

Provides access to the collection of layers to be displayed within the MapControl.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public LayerCollection Layers { get; }
vb
Public ReadOnly Property Layers As LayerCollection

Property Value

TypeDescription
LayerCollection

A LayerCollection object containing map layers.

|

Remarks

The Map Control uses layers, such as raster or vector geographical tiles, geo images, vector shapes, or heatmap data to visualize different types of information. You can combine multiple layers of various types on the same map.

Layers are displayed on the map in the following order:

  1. Image Layers (bottom)
  2. Vector Layers (middle)
  3. Information Layers (top)

The order of layer objects in the collection determines their Z-order. Each additional layer of one type is drawn over its preceding layer, the first layer is behind all additional layers. To change the Z-order of layer within one layer type, use its LayerBase.ZIndex property.

Example: Azure Maps

The following example connects a map control to Azure Maps and specifies map layers:

csharp
using DevExpress.XtraMap;
// ...
const string azureKey = "your key";
// ...
private void Form1_Load(object sender, EventArgs e) {
    // Create a map control.
    MapControl map = new MapControl();
    // Specify the map position on the form.           
    map.Dock = DockStyle.Fill;
    // Create a layer.
    ImageLayer layer1 = new ImageLayer();
    layer1.DataProvider = new AzureMapDataProvider() {
        AzureKey = azureKey,
        // Set Imagery tileset to display a satellite or aerial imagery on a layer.
        Tileset = AzureTileset.Imagery,
    };
    // Create a layer.
    ImageLayer layer2 = new ImageLayer();
    layer2.DataProvider = new AzureMapDataProvider(){
        AzureKey = azureKey,
        // Set BaseLabelsRoad tileset to display boundaries and label data in the Azure Map style on a layer.
        Tileset = AzureTileset.BaseLabelsRoad,
    };

    // Specify the map zoom level and center point. 
    map.ZoomLevel = 3;
    map.CenterPoint = new GeoPoint(40, -100);
    // Add the created layers to the collection.
    map.Layers.AddRange(new LayerBase[] {
        layer1, layer2});
    // Add the map control to the window.
    this.Controls.Add(map);
}
vb
Imports DevExpress.XtraMap
'...
Private Const azureKey As String = "your key"
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    ' Create a map control.
    Dim map As New MapControl()
    ' Specify the map position on the form.           
    map.Dock = DockStyle.Fill
    ' Create a layer.
    Dim layer1 As New ImageLayer()
    layer1.DataProvider = New AzureMapDataProvider() With {
        .AzureKey = azureKey,
        .Tileset = AzureTileset.Imagery
    }
    ' Create a layer.
    Dim layer2 As New ImageLayer()
    layer2.DataProvider = New AzureMapDataProvider() With {
        .AzureKey = azureKey,
        .Tileset = AzureTileset.BaseLabelsRoad
    }

    ' Specify the map zoom level and center point. 
    map.ZoomLevel = 3
    map.CenterPoint = New GeoPoint(40, -100)
    ' Add the created layers to the collection.
    map.Layers.AddRange(New LayerBase() { layer1, layer2})
    ' Add the map control to the window.
    Me.Controls.Add(map)
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Layers property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-map-create-choropleth-map-based-on-shapefile/CS/XtraMap_ShapefileDataAdapter/Form1.cs#L10

csharp
VectorItemsLayer MapLayer { get { return (VectorItemsLayer)mapControl1.Layers["MapLayer"]; } }

winforms-map-convert-a-cartesian-data-shapefile-to-geo-coordinates/CS/MapSample/Form1.cs#L30

csharp
{
    VectorItemsLayer vl = this.mapControl1.Layers[0] as VectorItemsLayer;
    if (vl != null)

winforms-map-load-data-from-a-kml-file/CS/WinForms_MapControl_KmlFileDataAdapter/Form1.cs#L9

csharp
VectorItemsLayer KmlLayer { get { return (VectorItemsLayer)mapControl1.Layers["KmlLayer"]; } }

winforms-map-show-the-progress-of-loading-image-tiles/CS/TilesLoaded/Form1.cs#L8

csharp
int requestsCounter = 0;
ImageLayer Layer { get { return (ImageLayer)mapControl1.Layers[0]; } }

winforms-map-execute-the-search-operation-for-multiple-locations/CS/GetSearchLocationAdditionalInfo/Form1.cs#L69

csharp
VectorItemsLayer layer = (VectorItemsLayer)this.map.Layers[2];

winforms-map-create-choropleth-map-based-on-shapefile/VB/XtraMap_ShapefileDataAdapter/Form1.vb#L15

vb
Get
    Return CType(Me.mapControl1.Layers("MapLayer"), DevExpress.XtraMap.VectorItemsLayer)
End Get

winforms-map-convert-a-cartesian-data-shapefile-to-geo-coordinates/VB/MapSample/Form1.vb#L27

vb
If dialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    Dim vl As VectorItemsLayer = TryCast(Me.mapControl1.Layers(0), VectorItemsLayer)
    If vl IsNot Nothing Then

winforms-map-load-data-from-a-kml-file/VB/WinForms_MapControl_KmlFileDataAdapter/Form1.vb#L14

vb
Get
    Return CType(mapControl1.Layers("KmlLayer"), VectorItemsLayer)
End Get

winforms-map-show-the-progress-of-loading-image-tiles/VB/TilesLoaded/Form1.vb#L14

vb
Get
    Return CType(mapControl1.Layers(0), ImageLayer)
End Get

winforms-map-execute-the-search-operation-for-multiple-locations/VB/GetSearchLocationAdditionalInfo/Form1.vb#L64

vb
pin.Location = geoPoint
Dim layer As VectorItemsLayer = CType(map.Layers(2), VectorItemsLayer)
CType(layer.Data, MapItemStorage).Items.Add(pin)

See Also

MapControl Class

MapControl Members

DevExpress.XtraMap Namespace