Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.2.dll

NuGet Package: DevExpress.Wpf.Map

#Declaration

public class GpxFileDataAdapter :
    MapGeoDataAdapter,
    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.
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 };
                }
            }
        }
    }
}

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

See Also