How to: Load Data from a KML File
This example demonstrates how to load vector items from a KML file.
To accomplish this, do the following.
- Create a VectorItemsLayer object and add it to the Map control’s LayerCollection with the MapControl.Layers property.
- Create a KmlFileDataAdapter object, specify its FileDataAdapterBase.FileUri property value as a KML file Uri, and assign the object to the VectorItemsLayer.Data property.
using DevExpress.XtraMap;
using System;
using System.Windows.Forms;
namespace WinForms_MapControl_KmlFileDataAdapter {
public partial class Form1 : Form {
const string filePath = "../../kmlFile.kml";
VectorItemsLayer KmlLayer { get { return (VectorItemsLayer)mapControl1.Layers["KmlLayer"]; } }
public Form1() {
InitializeComponent();
#region #KmlFileDataAdapter
// Create a KML file data adapter.
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
KmlLayer.Data = new KmlFileDataAdapter() {
FileUri = new Uri(baseUri, filePath)
};
#endregion #KmlFileDataAdapter
}
}
}