windowsforms-devexpress-dot-xtramap-c0d82722.md
Draws a ruler on the map.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
public class MapRuler :
IMapRuler
Public Class MapRuler
Implements IMapRuler
The following members return MapRuler objects:
The Map Control uses rulers to measure distances and areas on a map. Two types of rulers are supported:
| Distance Ruler | Area Ruler |
|---|---|
Use the Measurements.CreateRuler method to add a ruler to the map. The following code displays a distance ruler on the map:
MapRuler ruler = mapControl1.Measurements.CreateRuler( RulerType.Distance,
new List<CoordPoint>(){
new GeoPoint(48.864716, 2.349014), // Paris
new GeoPoint(45.46427, 9.18951), // Milan
new GeoPoint(48.20849, 16.37208) }); // Vienna
Dim ruler As MapRuler = mapControl1.Measurements.CreateRuler(RulerType.Distance,
New List(Of CoordPoint)() From {
New GeoPoint(48.864716, 2.349014), ' Paris
New GeoPoint(45.46427, 9.18951), ' Milan
New GeoPoint(48.20849, 16.37208) }) ' Vienna
To modify a ruler, configure ruler points. You can use the following methods:
|
Name
|
Description
| | --- | --- | |
InsertPoint(MapRuler, CoordPoint, Int32)
|
Adds a new point to the ruler passed as a parameter.
| |
|
Removes the point with the specified index.
| |
UpdatePoint(MapRuler, CoordPoint, Int32)
|
Changes coordinates of the point with the specified index.
|
The example below creates a ruler to measure the distance between Paris, Milan and Vienna. After calculating this distance, the code updates the ruler as follows:
a point is added at Berlin’s coordinates;
the first point is moved from Paris to Dusseldorf;
the point at Milan’s coordinates is removed from the ruler.
MapRuler ruler = mapControl1.Measurements.CreateRuler(RulerType.Distance,
new List<CoordPoint>() {
new GeoPoint(48.864716, 2.349014), // Paris
new GeoPoint(45.46427, 9.18951), // Milan
new GeoPoint(48.20849, 16.37208) // Vienna
});
//The code below updates the ruler.
mapControl1.Measurements.InsertPoint(ruler, new GeoPoint(52.520008, 13.404954), 2); // Berlin
mapControl1.Measurements.UpdatePoint(ruler, new GeoPoint(51.2217200, 6.7761600), 0); // Dusseldorf
mapControl1.Measurements.RemovePoint(ruler, 1); // Milan
Dim ruler As MapRuler = mapControl1.Measurements.CreateRuler(RulerType.Distance,
New List(Of CoordPoint)() From {
New GeoPoint(48.864716, 2.349014),' Paris
New GeoPoint(45.46427, 9.18951), ' Milan
New GeoPoint(48.20849, 16.37208) ' Vienna })
'The code below updates the ruler.
mapControl1.Measurements.InsertPoint(ruler, New GeoPoint(52.520008, 13.404954), 2) ' Berlin
mapControl1.Measurements.UpdatePoint(ruler, New GeoPoint(51.2217200, 6.7761600), 0) ' Dusseldorf
mapControl1.Measurements.RemovePoint(ruler, 1) ' Milan
| Before Update | After Update |
|---|---|
The RemoveRuler(MapRuler) method removes the ruler passed as a parameter:
mapControl1.Measurements.RemoveRuler(ruler);
mapControl1.Measurements.RemoveRuler(ruler)
If you need to delete all rulers from the map, call the RemoveRulers() method:
mapControl1.Measurements.RemoveRulers();
mapControl1.Measurements.RemoveRulers()
Use the CreateRuler(RulerType, IList<CoordPoint>, MapRulerStyle) method to define the ruler’s appearance. The MapRulerStyle class contains ruler style options.
MapRulerStyle style = new MapRulerStyle();
style.Stroke = Color.Red;
style.StrokeWidth = 3;
MapRuler ruler1 = mapControl1.Measurements.CreateRuler(RulerType.Distance,
new List<CoordPoint>() {
new GeoPoint(51.2217200, 6.7761600), // Dusseldorf
new GeoPoint(52.520008, 13.404954), // Berlin
new GeoPoint(48.20849, 16.37208) // Vienna
}, style);
Dim style As MapRulerStyle = New MapRulerStyle()
style.Stroke = Color.Red
style.StrokeWidth = 3
Dim ruler1 As MapRuler = mapControl1.Measurements.CreateRuler(RulerType.Distance, New List(Of CoordPoint)() From {
New GeoPoint(51.2217200, 6.7761600), ' Dusseldorf
New GeoPoint(52.520008, 13.404954), ' Berlin
New GeoPoint(48.20849, 16.37208) ' Vienna
}, style)
Related API members:
|
Name
|
Description
| | --- | --- | |
CreateRuler(RulerType, IList<CoordPoint>, MapRulerStyle)
|
Creates a ruler with the specified style.
| |
|
Contains ruler style options.
| |
|
Gets or sets the ruler’s outline color.
| |
|
Gets or sets the ruler’s outline width.
|
Object MapRuler
See Also