This sample demonstrates how to use the FileGpsCoordinateWatcher to
playback NMEA sentences from a log file to show a location on a
map using code.
Download Sample Application
<UserControl x:Class="ArcGISWPFSDK.FileGpsLayerCodebehind"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
<Grid>
<esri:Map x:Name="MyMap">
<esri:ArcGISLocalTiledLayer ID="localTiledLayer" Path="..\Data\TPKs\Campus.tpk"/>
</esri:Map>
</Grid>
</UserControl>
using System;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client.Toolkit.DataSources;
using ESRI.ArcGIS.Client.Local;
namespace ArcGISWPFSDK
{
/// <summary>
/// Interaction logic for FileGpsLayerCodebehind.xaml
/// </summary>
public partial class FileGpsLayerCodebehind : UserControl
{
GpsLayer _gpsLayer;
public FileGpsLayerCodebehind()
{
InitializeComponent();
Application.Current.Exit += new ExitEventHandler(Current_Exit);
//Create and add new file based GPS layer
_gpsLayer = new GpsLayer();
_gpsLayer.GeoPositionWatcher = new ESRI.ArcGIS.Client.Local.Gps.FileGpsCoordinateWatcher()
{
Path = @"..\Data\GPS\campus.txt",
LoopPlayback = true
};
MyMap.Layers.Add(_gpsLayer);
}
void Current_Exit(object sender, ExitEventArgs e)
{
//Cleanup GpsCoordinateWatcher resource
IDisposable fileGpsWatcher = _gpsLayer.GeoPositionWatcher as IDisposable;
if (fileGpsWatcher != null)
fileGpsWatcher.Dispose();
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Shapes
Imports ESRI.ArcGIS.Client.Toolkit.DataSources
Imports ESRI.ArcGIS.Client.Local
''' <summary>
''' Interaction logic for FileGpsLayerCodebehind.xaml
''' </summary>
Namespace ArcGISWPFSDK
Partial Public Class FileGpsLayerCodebehind
Inherits UserControl
Private _gpsLayer As GpsLayer
Public Sub New()
InitializeComponent()
AddHandler Application.Current.[Exit], New ExitEventHandler(AddressOf Current_Exit)
'Create and add new file based GPS layer
_gpsLayer = New GpsLayer()
_gpsLayer.GeoPositionWatcher = New ESRI.ArcGIS.Client.Local.Gps.FileGpsCoordinateWatcher() With { _
.Path = "..\Data\GPS\campus.txt", _
.LoopPlayback = True _
}
MyMap.Layers.Add(_gpsLayer)
End Sub
Private Sub Current_Exit(sender As Object, e As ExitEventArgs)
'Cleanup GeoPositionWatcher resource
Dim fileGpsWatcher As IDisposable = TryCast(_gpsLayer.GeoPositionWatcher, IDisposable)
If fileGpsWatcher IsNot Nothing Then
fileGpsWatcher.Dispose()
End If
End Sub
End Class
End Namespace
5/16/2014