All docs
V21.2
21.2
21.1
The page you are viewing does not exist in version 21.1. This link will take you to the root page.
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

MapPolylinePointCollectionMapping Class

Allows you to specify data members used to create map polylines.

Namespace: DevExpress.XtraMap

Assembly: DevExpress.XtraMap.v21.2.dll

Declaration

public class MapPolylinePointCollectionMapping :
    MapMultipointItemMappingBase<MapPolyline>

Remarks

Use MapPolylinePointCollectionMapping to specify mappings that ListSourceDataAdapter uses to generate map polylines from collections of coordinate points.

The following properties allow you to specify data source fields that store polyline data:

PointSourceMember
Specifies the data member that stores polylines points.
XCoordinateMember
Specifies the point source data member that contains x-coordinates of points (latitudes for geo points).
YCoordinateMember
Specifies the point source data member that contains y-coordinates of points (latitudes for geo points).

Example

Create Polylines From a Collection of Points

The following example shows how to create map polylines based on a collection of coordinates, and configure the polyline color and thickness.

Map polylines

Follow the steps below to create a vector layer with polylines:

  1. Create a VectorItemsLayer object and add it to the map’s Layers collection.

  2. Create a ListSourceDataAdapter object and assign it to the vector layer’s Data property.

  3. Specify the adapter’s DataSource. The example below uses a list of objects that store information about lines, such as coordinate points.

  4. Set the adapter’s DefaultMapItemType property to MapItemType.Polyline to create polylines based on the data that the adapter loads.

  5. Add a MapPolylinePointCollectionMapping object to the adapter’s PropertyMappings. Specify the following mapping properties to define source fields from which the adapter should obtain polyline point data:

    • PointSourceMember – Specifies the data member that stores polylines points.
    • XCoordinateMember – Specifies the point source data member that contains x-coordinates of points (longitudes for geo points).
    • YCoordinateMember – Specifies the point source data member that contains y-coordinates of points (latitudes for geo points).
  6. To customize polyline appearance settings, use mappings that correspond to map item properties. For example, add the following mappings to the adapter’s PropertyMappings collection to specify the MapItem.Stroke and MapItem.StrokeWidth properties:

    You can use a mapping’s DefaultValue property to explicitly specify a map item property value (for example, MapItem.Stroke), or you can use the mapping’s Member property to map the property to a source data member.

  7. Call the MapControl.ZoomToFitLayerItems() method in the vector layer’s DataLoaded event handler to specify the map viewport boundaries so that they include all polylines.

The code below creates two polylines:

using DevExpress.XtraMap;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace CreateMapLines {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            // Create a background image layer and add it to the map.
            ImageLayer imageLayer = new ImageLayer();
            imageLayer.DataProvider = new BingMapDataProvider {
                BingKey = "Insert your Bing Maps key here.",
                Kind = BingMapKind.RoadGray
            };
            mapControl1.Layers.Add(imageLayer);

            // Create a vector layer and add it to the map.
            VectorItemsLayer vectorLayer = new VectorItemsLayer();
            mapControl1.Layers.Add(vectorLayer);

            // Create a ListSourceDataAdapter.
            // Specify its data source.
            // Configure mappings.
            // Assign the adapter to the vector layer.
            ListSourceDataAdapter adapter = new ListSourceDataAdapter();
            adapter.DataSource = GetLines();
            adapter.DefaultMapItemType = MapItemType.Polyline;
            adapter.PropertyMappings.Add(new MapPolylinePointCollectionMapping {
                XCoordinateMember = "Longitude", 
                PointSourceMember = "PointSource", 
                YCoordinateMember= "Latitude"
            });
            adapter.PropertyMappings.Add(new MapItemStrokeMapping { Member = "Color" });
            adapter.PropertyMappings.Add(new MapItemStrokeWidthMapping { DefaultValue = 4 });
            vectorLayer.Data = adapter;
            vectorLayer.DataLoaded += OnVectorLayerDataLoaded;
        }

        private void OnVectorLayerDataLoaded(object sender, DataLoadedEventArgs e) {
            // Zooms the map to fit all created lines.
            mapControl1.ZoomToFitLayerItems();
        }
        public List<Line> GetLines() {
            List<Line> lines = new List<Line>();

            Line line1 = new Line();
            line1.PointSource.Add(new Coordinate(-5.93107, -35.112723));
            line1.PointSource.Add(new Coordinate(-10.13507, -25.15696));
            line1.PointSource.Add(new Coordinate(-5.183714, -8.911391));
            line1.PointSource.Add(new Coordinate(4.253438, 5.47072));
            line1.Color = Color.Green;
            lines.Add(line1);

            Line line2 = new Line();
            line2.PointSource.Add(new Coordinate(1, 0.5));
            line2.PointSource.Add(new Coordinate(-25, -15));
            line2.PointSource.Add(new Coordinate(-15, -25));
            line2.PointSource.Add(new Coordinate(-22.1531, -41.45984));
            line2.Color = Color.Red;
            lines.Add(line2);

            return lines;
        }
    }
    public struct Coordinate {
        public double Latitude { get; }
        public double Longitude { get; }
        public Coordinate(double lat, double lon) {
            Latitude = lat;
            Longitude = lon;
        }
    }
    public class Line {
        public Color Color { get; set; }
        public List<Coordinate> PointSource { get; } = new List<Coordinate>();
    }
}

Inheritance

Object
DevExpress.XtraMap.Native.MapItemMappingBase
MapItemPropertyMappingBase
DevExpress.XtraMap.MapItemPropertyMappingBase<MapPolyline>
MapMultipointItemMappingBase<MapPolyline>
MapPolylinePointCollectionMapping
See Also