Back to Devexpress

MapSpline Class

windowsforms-devexpress-dot-xtramap-d6b6bad7.md

latest7.8 KB
Original Source

MapSpline Class

Draws a spline on the map.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public class MapSpline :
    MapPolylineBase
vb
Public Class MapSpline
    Inherits MapPolylineBase

The following members return MapSpline objects:

Remarks

The Map Control uses vector layers to display vector items such as map splines.

The following image shows a spline that is plotted based on four geographical points.

Create a Map Spline

The following code creates a MapSpline and adds it to a vector layer’s item storage.

csharp
using DevExpress.XtraMap;
using System;
using System.Drawing;
using System.Windows.Forms;
//...
private void Form1_Load(object sender, EventArgs e) {

    VectorItemsLayer itemLayer = new VectorItemsLayer();
    mapControl1.Layers.Add(itemLayer);            

    MapSpline mapSpline = new MapSpline();
    mapSpline.Points.AddRange ( new GeoPoint[] {
        new GeoPoint(64.1, -40.5),
        new GeoPoint(65.4, -33.8),
        new GeoPoint(64.5, -28.5),
        new GeoPoint(65.5, -24.5)
    });        

    MapItemStorage storage = new MapItemStorage();
    storage.Items.Add(mapSpline);            

    itemLayer.Data = storage;
    itemLayer.DataLoaded += OnItemLayerDataLoaded;            
}

private void OnItemLayerDataLoaded(object sender, DataLoadedEventArgs e) {
    // You can call the MapControl.ZoomToFitLayerItems method in the DataLoaded event handler
    // to zoom the map so that it displays all vector items according to their bounding box.
    mapControl1.ZoomToFitLayerItems(new LayerBase[] { mapControl1.Layers[1] });
}
vb
Imports DevExpress.XtraMap
Imports System.Drawing
Imports System.Windows.Forms
'...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim layer As ImageLayer = New ImageLayer()
    layer.DataProvider = New BingMapDataProvider With {
        .BingKey = "Your-BingKey-here",
        .Kind = BingMapKind.Road
    }
    mapControl1.Layers.Add(layer)
    Dim itemLayer As VectorItemsLayer = New VectorItemsLayer()
    mapControl1.Layers.Add(itemLayer)
    Dim mapSpline As MapSpline = New MapSpline()
    mapSpline.Points.AddRange(New GeoPoint() {New GeoPoint(64.1, -40.5), New GeoPoint(65.4, -33.8), New GeoPoint(64.5, -28.5), New GeoPoint(65.5, -24.5)})
    Dim storage As MapItemStorage = New MapItemStorage()
    storage.Items.Add(mapSpline)
    itemLayer.Data = storage
    itemLayer.DataLoaded += AddressOf OnItemLayerDataLoaded
End Sub

Private Sub OnItemLayerDataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
    ' You can call the MapControl.ZoomToFitLayerItems method in the DataLoaded event handler
    ' to zoom the map so that it displays all vector items according to their bounding box.
    mapControl1.ZoomToFitLayerItems(New LayerBase() {mapControl1.Layers(1)})
End Sub

You can add multiple MapSplines to a vector layer. For more information on how to load vector items to a map, see the Vector Items topic.

Customize Spline Appearance

Use the following properties to specify spline color and style at normal, highlighted and selected states.

|

State

|

APIs

| | --- | --- | |

Normal

|

MapItem.Stroke, MapItem.StrokeWidth

| |

Highlighted

|

MapItem.HighlightedStroke, MapItem.HighlightedStrokeWidth

| |

Selected

|

MapItem.SelectedStroke, MapItem.StrokeWidth

|

The following example shows how to create a red spline. When the spline is highlighted or selected, its color is changed to blue/black respectively.

csharp
mapSpline.Stroke = Color.Red;
mapSpline.StrokeWidth = 4;
mapSpline.HighlightedStroke = Color.Blue;
mapSpline.HighlightedStrokeWidth = 4;
mapSpline.SelectedStroke = Color.Black;
mapSpline.SelectedStrokeWidth = 4;
vb
mapSpline.Stroke = Color.Red
mapSpline.StrokeWidth = 4
mapSpline.HighlightedStroke = Color.Blue
mapSpline.HighlightedStrokeWidth = 4
mapSpline.SelectedStroke = Color.Black
mapSpline.SelectedStrokeWidth = 4

Add Spline Caps

You can display shapes at the beginning and at the end of splines. Use the StartLineCap and EndLineCap properties for this purpose.

The following example specifies the end cap template and shows the default arrow for the spline start cap:

csharp
MapSpline spline = new MapSpline() { StrokeWidth = 2, Stroke = System.Drawing.Color.Blue };
spline.Points.AddRange(new GeoPoint[] { new GeoPoint(-6, -4),
                                        new GeoPoint(-3, -10),
                                        new GeoPoint(-6, -20) });

spline.StartLineCap.Visible = true;
spline.StartLineCap.Length = 20;
spline.StartLineCap.Width = 10;

spline.EndLineCap.Visible = true;
spline.EndLineCap.Template = new MapUnit[] { new MapUnit(-0.5, 0),
                                             new MapUnit(0, 0.5),
                                             new MapUnit(0.5, 0),
                                             new MapUnit(0, -0.5)};
spline.EndLineCap.Length = 10;
spline.EndLineCap.Width = 10;

mapItemStorage1.Items.Add(spline);
vb
Dim spline As MapSpline = New MapSpline() With {.StrokeWidth = 2,
                                                .Stroke = Drawing.Color.Blue}
spline.Points.AddRange(New GeoPoint() { New GeoPoint(-6, -4), 
                                        New GeoPoint(-3, -10),
                                        New GeoPoint(-6, -20)})

spline.StartLineCap.Visible = True
spline.StartLineCap.Length = 20
spline.StartLineCap.Width = 10

spline.EndLineCap.Visible = True
spline.EndLineCap.Template = New MapUnit() { New MapUnit(-0.5, 0),
                                             New MapUnit(0, 0.5),
                                             New MapUnit(0.5, 0),
                                             New MapUnit(0, -0.5)}
spline.EndLineCap.Length = 10
spline.EndLineCap.Width = 10

mapItemStorage1.Items.Add(spline)

Implements

IColorizerElement

IEditableItem

Inheritance

Object MapItem MapShape MapPolylineBase MapSpline

See Also

MapSpline Members

DevExpress.XtraMap Namespace