windowsforms-15078-controls-and-libraries-map-control-layers.md
The Map Control uses layers to visualize different types of information, such as raster or vector geographical tiles, geo images, vector shapes, or heatmap data. You can combine multiple layers of different types on the same map.
To add a layer to the map, add the layer object to the MapControl.Layers collection. Layers are displayed on the map in the following order:
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 located behind all additional layers. To change the Z-order of layer within one layer type, use its LayerBase.ZIndex property.
To load data to a layer, assign a compatible data provider or adapter.
Also, you can show additional information on top of a map in semitransparent text boxes called overlays. For more information, refer to the following help topic: Overlays.
The following sections describe available layers.
Image layers allow you to show raster and vector tiled maps, georeferenced map images from Web map services, and heatmaps. To show tiles, the Map Control utilizes the spherical Mercator projection as default. Refer to the following topic for more information: Geographical Projections.
The ImageLayer class implements the image layer functionality. To load data to the layer, specify the ImageLayer.DataProvider property. For the list of available data providers, refer to the following section: Data Providers for Image Item Layers.
The following code creates an image layer, adds it to the map, and loads Azure Maps image tiles to the layer:
mapControl1.Layers.Add(new ImageLayer() {
DataProvider = new AzureMapDataProvider() {
AzureKey = "YOUR KEY",
Tileset = AzureTileset.BaseLabelsRoad,
}
});
mapControl1.Layers.Add(New ImageLayer() With {
.DataProvider = New AzureMapDataProvider() With {
.BingKey = "YOUR BING KEY",
.Tileset = AzureTileset.BaseLabelsRoad
}
})
For a step-by-step tutorial on how to create a map application with Azure Map tiles, refer to the following topic: Lesson 1 - Load Image Tiles to a Map.
The following list contains data providers that allow you to supply image layers with data:
AzureMapDataProviderAllows you to obtain raster image tiles from the Azure Maps service.OpenStreetMapDataProviderAllows you to load raster image tiles from the OpenStreetMap service.ImageTileDataProviderAllows you to load tiles from in-memory sources.MapboxDataProviderAllows you to render tiles based on vector tile data from the Mapbox service.MbTilesDataProviderLoads vector tiles from an MbTiles database.UriBasedVectorTileDataProviderLoads map data from a set of PBF or MVT files.HeatmapProviderAllows you to visualize heatmap data over the map.WmsDataProviderAllows you to receive geographical data images from a WMS server.
Vector item layers are intended to display vector shapes (for example, pushpins, polygons, or lines). The Map Control can adapt vector shape data loaded from various sources.
The following image shows vector items (bubbles) on top of a geographical map:
The VectorItemsLayer class implements the vector layer functionality. To load data to the layer, specify the VectorItemsLayer.Data property. For the list of available data adapters, refer to the following section: Data Adapters for Vector Item Layers.
The following example loads vector polygons from a shapefile:
public partial class Form1 : Form {
const string filename = "../../Data/Countries.shp";
VectorItemsLayer MapLayer { get { return (VectorItemsLayer)mapControl1.Layers["MapLayer"]; } }
public Form1() {
InitializeComponent();
MapLayer.Data = CreateData();
}
private MapDataAdapterBase CreateData() {
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
// Create an adapter to load data from the shapefile.
ShapefileDataAdapter adapter = new ShapefileDataAdapter() {
FileUri = new Uri(baseUri, filename)
};
return adapter;
}
}
Public Partial Class Form1
Inherits Form
Const filename As String = "../../Data/Countries.shp"
Private ReadOnly Property MapLayer As VectorItemsLayer
Get
Return CType(mapControl1.Layers("MapLayer"), VectorItemsLayer)
End Get
End Property
Public Sub New()
InitializeComponent()
MapLayer.Data = CreateData()
End Sub
Private Function CreateData() As MapDataAdapterBase
Dim baseUri As Uri = New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
Dim adapter As ShapefileDataAdapter = New ShapefileDataAdapter() With {
.FileUri = New Uri(baseUri, filename)
}
Return adapter
End Function
End Class
For a step-by-step tutorial on how to load vector items from a shapefile, refer to the following topic: Lesson 2 - Load a Vector Cartesian Map.
The following list contains data adapters that allow you to supply vector layers with data:
MapItemStorageStores vector items that you manually added to the map.GeoJsonFileDataAdapterLoads vector items from a GeoJSON file.GpxFileDataAdapterLoads vector items from a GPX file.SqlGeometryDataAdapterLoads data from an SQL geometry data source.SqlGeometryItemStorageStores manually created SQL geometry vector items.KmlFileDataAdapterLoads vector items from a KML/KMZ file.SvgFileDataAdapterLoads vector items from an SVG file.ShapefileDataAdapterLoads vector items from a shapefile.BubbleChartDataAdapterAllows you to show bubble charts on the map.PieChartDataAdapterAllows you to show pie charts on the map.ListSourceDataAdapterAllows you to create items from lists or list sources.
Information layers are used to show map vector items that the Map Control creates based on data obtained from Geographic Information System services (GIS services).
The following image shows traffic incident information loaded from the Azure Maps Traffic service:
The InformationLayer class implements the information layer functionality. To load data to the layer, specify the InformationLayer.DataProvider property. For the list of available data providers, refer to the following section: Data Providers for Information Layers.
The following example allows users to search locations. A search query adds pushpins at found locations:
using DevExpress.XtraMap;
using System.Windows.Forms;
namespace ConnectBingSearchProvider {
public partial class Form1 : Form {
const string azureKey = "YOUR AZURE KEY HERE";
InformationLayer SearchLayer {
get {
return (InformationLayer)mapControl1.Layers["SearchLayer"];
}
}
public Form1() {
InitializeComponent();
AzureSearchDataProvider searchProvider = new AzureSearchDataProvider() {
AzureKey = azureKey
};
searchProvider.SearchOptions.ResultsCount = 5;
SearchLayer.DataProvider = searchProvider;
}
}
}
Imports DevExpress.XtraMap
Imports System.Windows.Forms
Namespace ConnectBingSearchProvider
Partial Public Class Form1
Inherits Form
Private Const bingKey As String = "YOUR BING KEY HERE"
Private ReadOnly Property SearchLayer() As InformationLayer
Get
Return CType(mapControl1.Layers("SearchLayer"), InformationLayer)
End Get
End Property
Public Sub New()
InitializeComponent()
Dim searchProvider As New AzureSearchDataProvider() With {.AzureKey = bingKey}
searchProvider.SearchOptions.ResultsCount = 5
SearchLayer.DataProvider = searchProvider
End Sub
End Class
End Namespace
The following list contains data providers that allow you to supply information layers with GIS data:
AzureSearchDataProviderContains settings that are used by requests to the Azure Maps Search service.AzureGeocodeDataProviderThe class that sends requests to the Azure Maps Geocode service.AzureRouteDataProviderThe class that communicates with Azure Maps Route service.AzureTrafficIncidentDataProviderCommunicates with the Azure Maps service to obtain information about traffic incidents and display them on the map.AzureRouteIsochroneDataProviderAllows you to use the Azure Maps service to calculate an isochrone and display it on the map.OsmGeocodeDataProviderGets geographical coordinates for a location by its address.OsmSearchDataProviderAllows you to use the Open Street Map to search for locations by the specified address or keyword. See Also