Back to Devexpress

GpxFileDataAdapter Class

wpf-devexpress-dot-xpf-dot-map-da59a47f.md

latest6.9 KB
Original Source

GpxFileDataAdapter Class

A data adapter that loads data from GPX files, and displays it on vector layers.

Namespace : DevExpress.Xpf.Map

Assembly : DevExpress.Xpf.Map.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public class GpxFileDataAdapter :
    MapGeoDataAdapter,
    IListSource,
    IGpxOptionsProvider
vb
Public Class GpxFileDataAdapter
    Inherits MapGeoDataAdapter
    Implements IListSource,
               IGpxOptionsProvider

Remarks

Tip

To try out the GpxFileDataAdapter , see the GPX Data Adapter demo.

GPX files store coordinate-based data such as waypoints, routes, and tracks in an XML-like format.

The Map Control converts GPX file elements as follows:

  • <wpt> (waypoint) is displayed as MapDot.
  • <rte> (route) is converted to a MapPolyline.
  • <trk> (track) is represented by a MapPath.

Routes and tracks are built based on trkpt coordinates nested inside <rte> or <trk> elements. If you enable the CreateRoutePoints property, map dots are generated for each trkpt element.

Follow the steps below to load data from a .GPX file:

  1. Add a VectorLayer object to the MapControl.Layers collection.
  2. Create a GpxFileDataAdapter object.
  3. Specify the path to a GPX file via the MapGeoDataAdapter.FileUri property.
  4. Assign the GpxFileDataAdapter to the VectorItemsLayer.Data property.
xaml
<Window xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FileDataAdapters"
        x:Class="FileDataAdapters.MainWindow"
        xmlns:sys="clr-namespace:System;assembly=System"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <dxm:MapControl x:Name="mapControl">
            <dxm:ImageLayer>
                <dxm:BingMapDataProvider Kind="Road" BingKey="Your-BingKey-here"/>
            </dxm:ImageLayer>
            <dxm:VectorLayer x:Name="vectorLayer" DataLoaded="OnVectorLayerDataLoaded">
                <dxm:VectorLayer.Data>
                    <dxm:GpxFileDataAdapter ShapesLoaded="OnDataAdapterShapesLoaded" CreateRoutePoints="True">
                        <dxm:GpxFileDataAdapter.FileUri>
                            <sys:Uri>pack://application:,,,/FileDataAdapters;component/Data/boston-marathon-course.gpx</sys:Uri>
                        </dxm:GpxFileDataAdapter.FileUri>
                    </dxm:GpxFileDataAdapter>                    
                </dxm:VectorLayer.Data>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Map;
using System.Windows;
using System.Windows.Media;
namespace FileDataAdapters {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
        private void OnVectorLayerDataLoaded(object sender, DataLoadedEventArgs e) {
            mapControl.ZoomToFitLayerItems(new LayerBase[] { vectorLayer });
        }
        private void OnDataAdapterShapesLoaded(object sender, ShapesLoadedEventArgs e) {
            foreach (MapItem item in e.Shapes) {
                if (item is MapDot) {
                    ((MapDot)item).Fill = Brushes.Coral;
                    ((MapDot)item).Stroke = Brushes.Coral;
                    ((MapDot)item).Size = 8;
                }
                if (item is MapPath) {
                    ((MapPath)item).Stroke = Brushes.Black;
                    ((MapPath)item).StrokeStyle = new StrokeStyle { Thickness = 2 };
                }
            }
        }
    }
}
vb
Imports DevExpress.Xpf.Map
Imports System.Windows
Imports System.Windows.Media
Namespace FileDataAdapters
    Public Partial Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub OnVectorLayerDataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
            mapControl.ZoomToFitLayerItems(New LayerBase() {vectorLayer})
        End Sub
        Private Sub OnDataAdapterShapesLoaded(ByVal sender As Object, ByVal e As ShapesLoadedEventArgs)
            For Each item As MapItem In e.Shapes

                If TypeOf item Is MapDot Then
                    CType(item, MapDot).Fill = Brushes.Coral
                    CType(item, MapDot).Stroke = Brushes.Coral
                    CType(item, MapDot).Size = 8
                End If

                If TypeOf item Is MapPath Then
                    CType(item, MapPath).Stroke = Brushes.Black
                    CType(item, MapPath).StrokeStyle = New StrokeStyle With {
                        .Thickness = 2
                    }
                End If
            Next
        End Sub
    End Class
End Namespace

Note : In the example above, the GPX file’s Build Action is set to Resource.

Inheritance

Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase MapGeoDataAdapter GpxFileDataAdapter

See Also

GpxFileDataAdapter Members

Load Vector Items from Vector Format Source

DevExpress.Xpf.Map Namespace