MapItemMappingInfo.Type Property

Gets or sets the name of the data field that stores the type of the map item.

Namespace: DevExpress.XtraMap

Assembly: DevExpress.XtraMap.v20.1.dll

Declaration

[DefaultValue("")]
public string Type { get; set; }
<DefaultValue("")>
Public Property Type As String

Property Value

Type Default Description
String

String.Empty

A string value that specifies the name of the bound data field.

Remarks

When a map control is bound to a datasource, you will need to map properties of the Map class descendant object to the corresponding data source fields via its ListSourceDataAdapter.Mappings property. This will automatically generate map items of different types on a map.

Use the Type property to define the type of created map items. The column in a bound datasource should have the int type and store values corresponding to the MapItemType enumeration.

The MapItemType members are enumerated as follows:

  • Unknown = 0,
  • Dot = 1,
  • Ellipse = 2,
  • Line = 3 ,
  • Path = 4,
  • Polygon = 5,
  • Polyline = 6,
  • Rectangle = 7,
  • Pushpin = 8,
  • Custom = 9,
  • Callout = 10

If the Type mapping is not defined, a custom map item (default value) is created.

The following example shows how to specify mappings for the "Latitude", "Longitude", and "Type" data fields.


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using System.Xml.Linq;
using DevExpress.XtraMap;

namespace DataMapping {
    public partial class Form1 : Form {

        public Form1() {
            InitializeComponent();
        }

        VectorItemsLayer itemsLayer;
        const string xmlFilePath = @"..\..\Data\Ships.xml";

        private void Form1_Load(object sender, EventArgs e) {

            // Create a map control with initial settings and add it to the form.
            MapControl map = new MapControl() { ZoomLevel = 6, Dock = DockStyle.Fill };
            map.CenterPoint = new GeoPoint(-35, 145);
            this.Controls.Add(map);

            // Create a layer to load image tiles from the provider.
            ImageTilesLayer tileLayer = new ImageTilesLayer();
            OpenStreetMapDataProvider openStreetProvider = new OpenStreetMapDataProvider();
            openStreetProvider.WebRequest += OnWebRequest;
            tileLayer.DataProvider = openStreetProvider;
            map.Layers.Add(tileLayer);

            // Create a vector items layer.
            itemsLayer = new VectorItemsLayer();

            // Specify mappings for Latitude and Longitude coordinates.
            itemsLayer.Mappings.Latitude = "Latitude";
            itemsLayer.Mappings.Longitude = "Longitude";
            itemsLayer.Mappings.Type = "Type";

            // Specify a datasource. 
            itemsLayer.DataSource = LoadShipsFromXML(xmlFilePath);

            // Add a vector items layer to the map control.
            map.Layers.Add(itemsLayer);
        }

        public class ShipInfo {
            public double Latitude { get; set; }
            public double Longitude { get; set; }
            public int Type { get; set; }
        }

        private List<ShipInfo> LoadShipsFromXML(string filePath) {
            List<ShipInfo> ships = new List<ShipInfo>();

            // Load an XML document from the specified file path.
            XDocument document = XDocument.Load(filePath);
            if (document != null) {
                foreach (XElement element in document.Element("Ships").Elements()) {
                    // Load ShipInfo values and add them to the list.
                    double latitude = Convert.ToDouble(element.Element("Latitude").Value, CultureInfo.InvariantCulture);
                    double longitude = Convert.ToDouble(element.Element("Longitude").Value, CultureInfo.InvariantCulture);
                    int type = Convert.ToInt32(element.Element("Type").Value, CultureInfo.InvariantCulture);
                    ships.Add(new ShipInfo() { Latitude = latitude, Longitude = longitude, Type = type });
                }
            }

            return ships;
        }
        private void OnWebRequest(object sender, MapWebRequestEventArgs e) {
            e.UserAgent = "DevExpress Example";
        }
    }
}

See the How to: Automatically Generate Vector Items from a Datasource for more details.

See Also