windowsforms-devexpress-dot-xtramap-bf0124d5.md
A geographical point on the map.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
public sealed class GeoPoint :
CoordPoint
Public NotInheritable Class GeoPoint
Inherits CoordPoint
The following members return GeoPoint objects:
Show 24 links
The GeoPoint structure introduces the GeoPoint.Latitude and GeoPoint.Longitude properties that defines a geographical point on the map.
The following example calculates a route based on two or more RouteWaypoint objects.
Right-click on a map surface to specify waypoints: origin, destination, and points between. ListBox entries display geographical points (GeoPoint.Longitude and GeoPoint.Latitude). The “Calculate Route” button initiates the routing request by obtaining the waypoint information and passing it to the CalculateRoute method. The ComboBoxEdit and CheckedListBox editors specify route options (AzureRouteOptions.AvoidTypes and AzureRouteOptions.TravelMode properties).
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace AzureRouting {
public partial class Form1 : Form {
const string azureKey = "your key";
ObservableCollection<GeoPoint> geoPoints = new ObservableCollection<GeoPoint>();
MapItemStorage itemData;
InformationLayer routeInfoLayer;
AzureRouteDataProvider azureRoute;
public Form1() {
InitializeComponent();
mapControl.Layers.AddRange(
new LayerBase[] {
new ImageLayer() {
DataProvider = new AzureMapDataProvider() {
AzureKey = azureKey,
Tileset = AzureTileset.Imagery,
},
},
new ImageLayer() {
DataProvider = new AzureMapDataProvider() {
AzureKey = azureKey,
Tileset = AzureTileset.BaseHybridRoad,
},
},
routeInfoLayer = new InformationLayer() {
DataProvider = azureRoute = new AzureRouteDataProvider() {
AzureKey = azureKey,
},
},
new VectorItemsLayer() {
Data = itemData = new MapItemStorage(),
}
}
);
routeInfoLayer.ItemStyle.StrokeWidth = 2;
routeInfoLayer.ItemStyle.Stroke = Color.DeepSkyBlue;
routeInfoLayer.Error += RouteInfoLayer_Error;
waypointsListBoxControl.DataSource = geoPoints;
mapControl.Zoom(6);
mapControl.SetCenterPoint(new GeoPoint(40.714627, -74.002863), false);
mapControl.EnableRotation = false;
}
private void RouteInfoLayer_Error(object sender, MapErrorEventArgs e) {
throw new System.NotImplementedException();
}
private void mapControl_Click(object sender, System.EventArgs e) {
MouseEventArgs mouseEventArgs = (MouseEventArgs)e;
if(mouseEventArgs.Button == MouseButtons.Right) {
GeoPoint mousePoint = mapControl.ScreenPointToCoordPoint(mouseEventArgs.Location) as GeoPoint;
geoPoints.Add(mousePoint);
itemData.Items.Add(new MapPushpin() {
Location = mousePoint,
});
}
}
private void calculateRouteButton_Click(object sender, System.EventArgs e) {
if (geoPoints.Count <= 1) {
MessageBox.Show("Specify at least two Waypoints to calculate a route.");
return;
}
azureRoute.CalculateRoute(geoPoints.Select(point => new RouteWaypoint("", point)).ToList(), new AzureRouteOptions() {
TravelMode = GetTravelMode(),
AvoidTypes = GetAvoidTypes()
});
geoPoints.Clear();
itemData.Items.Clear();
}
AzureTravelMode GetTravelMode() {
return (AzureTravelMode)Enum.Parse(typeof(AzureTravelMode), (string)travelModeComboBox.SelectedItem);
}
AzureRouteAvoidType GetAvoidTypes() {
var avoidTypes = AzureRouteAvoidType.None;
foreach (string item in avoidTypesCheckedListBox.CheckedItems) {
var avoidType = (AzureRouteAvoidType)Enum.Parse(typeof(AzureRouteAvoidType), item);
avoidTypes |= avoidType;
}
return avoidTypes;
}
}
}
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Drawing
Imports System.Linq
Imports System.Windows.Forms
Imports DevExpress.XtraMap
Namespace AzureRouting
Partial Public Class Form1
Inherits Form
Private Const azureKey As String = "your key"
Private geoPoints As New ObservableCollection(Of GeoPoint)()
Private itemData As MapItemStorage
Private routeInfoLayer As InformationLayer
Private azureRoute As AzureRouteDataProvider
Public Sub New()
InitializeComponent()
mapControl.Layers.AddRange(New LayerBase() {
New ImageLayer() With {
.DataProvider = New AzureMapDataProvider() With {
.AzureKey = azureKey,
.Tileset = AzureTileset.Imagery
}
},
New ImageLayer() With {
.DataProvider = New AzureMapDataProvider() With {
.AzureKey = azureKey,
.Tileset = AzureTileset.BaseHybridRoad
}
},
routeInfoLayer = New InformationLayer() With {
.DataProvider = azureRoute = New AzureRouteDataProvider() With {.AzureKey = azureKey}
},
New VectorItemsLayer() With {.Data = itemData = New MapItemStorage()}
})
routeInfoLayer.ItemStyle.StrokeWidth = 2
routeInfoLayer.ItemStyle.Stroke = Color.DeepSkyBlue
AddHandler routeInfoLayer.Error, AddressOf RouteInfoLayer_Error
waypointsListBoxControl.DataSource = geoPoints
mapControl.Zoom(6)
mapControl.SetCenterPoint(New GeoPoint(40.714627, -74.002863), False)
mapControl.EnableRotation = False
End Sub
Private Sub RouteInfoLayer_Error(ByVal sender As Object, ByVal e As MapErrorEventArgs)
Throw New System.NotImplementedException()
End Sub
Private Sub mapControl_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mouseEventArgs As MouseEventArgs = CType(e, MouseEventArgs)
If mouseEventArgs.Button = MouseButtons.Right Then
Dim mousePoint As GeoPoint = TryCast(mapControl.ScreenPointToCoordPoint(mouseEventArgs.Location), GeoPoint)
geoPoints.Add(mousePoint)
itemData.Items.Add(New MapPushpin() With {.Location = mousePoint})
End If
End Sub
Private Sub calculateRouteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If geoPoints.Count <= 1 Then
MessageBox.Show("Specify at least two Waypoints to calculate a route.")
Return
End If
azureRoute.CalculateRoute(geoPoints.Select(Function(point) New RouteWaypoint("", point)).ToList(), New AzureRouteOptions() With {
.TravelMode = GetTravelMode(),
.AvoidTypes = GetAvoidTypes()
})
geoPoints.Clear()
itemData.Items.Clear()
End Sub
Private Function GetTravelMode() As AzureTravelMode
Return DirectCast(System.Enum.Parse(GetType(AzureTravelMode), CStr(travelModeComboBox.SelectedItem)), AzureTravelMode)
End Function
Private Function GetAvoidTypes() As AzureRouteAvoidType
Dim avoidTypes = AzureRouteAvoidType.None
For Each item As String In avoidTypesCheckedListBox.CheckedItems
Dim avoidType = DirectCast(System.Enum.Parse(GetType(AzureRouteAvoidType), item), AzureRouteAvoidType)
avoidTypes = avoidTypes Or avoidType
Next item
Return avoidTypes
End Function
End Class
End Namespace
Object CoordPoint GeoPoint
See Also