Back to Devexpress

How to: Load Data from a KML File

windowsforms-17434-controls-and-libraries-map-control-examples-vector-data-providing-data-how-to-load-data-from-a-kml-file.md

latest2.5 KB
Original Source

How to: Load Data from a KML File

  • Nov 13, 2018

This example loads vector items from a KML file.

To accomplish this, do the following.

View Example

csharp
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
        }
    }
}
vb
Imports DevExpress.XtraMap
Imports System
Imports System.Windows.Forms

Namespace WinForms_MapControl_KmlFileDataAdapter
    Partial Public Class Form1
        Inherits Form

        Private Const filePath As String = "../../kmlFile.kml"

        Private ReadOnly Property KmlLayer() As VectorItemsLayer
            Get
                Return CType(mapControl1.Layers("KmlLayer"), VectorItemsLayer)
            End Get
        End Property

        Public Sub New()
            InitializeComponent()

' #Region "#KmlFileDataAdapter"
            ' Create a KML file data adapter.
            Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
            KmlLayer.Data = New KmlFileDataAdapter() With {.FileUri = New Uri(baseUri, filePath)}
' #End Region ' #KmlFileDataAdapter
        End Sub
    End Class
End Namespace