windowsforms-113973-controls-and-libraries-map-control-examples-vector-data-customize-data-appearance-how-to-specify-a-map-projection.md
This example demonstrates how to specify the map projection that is used to display geographical data for a Map Control.
To configure a map projection, specify the GeoMapCoordinateSystem.Projection property of the GeoMapCoordinateSystem object. Assign it to the MapControl.CoordinateSystem property.
One of the following predefined map projections can be used.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace MapProjections {
public partial class Form1 : Form {
const string filepath = @"..\..\Data\Countries.shp";
List<ProjectionBase> mapProjections = new List<ProjectionBase>() {
new BraunStereographicProjection(),
new EllipticalMercatorProjection(),
new EqualAreaProjection(),
new EquidistantProjection(),
new EquirectangularProjection(),
new KavrayskiyProjection(),
new LambertCylindricalEqualAreaProjection(),
new MillerProjection(),
new SinusoidalProjection(),
new SphericalMercatorProjection(),
new Etrs89LambertAzimuthalEqualAreaProjection()
};
GeoMapCoordinateSystem CoordinateSystem { get { return mapControl.CoordinateSystem as GeoMapCoordinateSystem; } }
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
lbProjection.DataSource = mapProjections;
lbProjection.SetSelected(0, true);
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
Uri uri = new Uri(baseUri, filepath);
mapControl.Layers.Add(new VectorItemsLayer() {
Data = new ShapefileDataAdapter() {
FileUri = uri
}
});
}
private void lbProjection_SelectedIndexChanged(object sender, EventArgs e) {
CoordinateSystem.Projection = lbProjection.SelectedValue as ProjectionBase;
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports DevExpress.XtraMap
Namespace MapProjections
Partial Public Class Form1
Inherits Form
Private Const filepath As String = "..\..\Data\Countries.shp"
Private mapProjections As New List(Of ProjectionBase)() From {
New BraunStereographicProjection(),
New EllipticalMercatorProjection(),
New EqualAreaProjection(),
New EquidistantProjection(),
New EquirectangularProjection(),
New KavrayskiyProjection(),
New LambertCylindricalEqualAreaProjection(),
New MillerProjection(),
New SinusoidalProjection(),
New SphericalMercatorProjection(),
New Etrs89LambertAzimuthalEqualAreaProjection()
}
Private ReadOnly Property CoordinateSystem() As GeoMapCoordinateSystem
Get
Return TryCast(mapControl.CoordinateSystem, GeoMapCoordinateSystem)
End Get
End Property
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
lbProjection.DataSource = mapProjections
lbProjection.SetSelected(0, True)
Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
Dim uri As New Uri(baseUri, filepath)
mapControl.Layers.Add(New VectorItemsLayer() With { _
.Data = New ShapefileDataAdapter() With {.FileUri = uri} _
})
End Sub
Private Sub lbProjection_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lbProjection.SelectedIndexChanged
CoordinateSystem.Projection = TryCast(lbProjection.SelectedValue, ProjectionBase)
End Sub
End Class
End Namespace