mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-01-10 10:41:26 +01:00
Updated sample to 100.x design
Can't believe I didn't notice this was still using 10.x until now 🤦♂️
This commit is contained in:
parent
826d062569
commit
168b2d0040
|
|
@ -8,47 +8,46 @@ You can also check out the Desktop Sample app in the [Github Repo]( https://gith
|
|||
**Usage:**
|
||||
```csharp
|
||||
NmeaParser.NmeaDevice device = new NmeaParser.NmeaFileDevice("NmeaSampleData.txt");
|
||||
mapView.LocationDisplay.LocationProvider = new NmeaLocationProvider(device);
|
||||
mapView.LocationDisplay.DataSource = new NmeaLocationProvider(device);
|
||||
mapView.LocationDisplay.InitialZoomScale = 20000;
|
||||
mapView.LocationDisplay.IsEnabled = true;
|
||||
```
|
||||
|
||||
**NmeaLocationProvider.cs**
|
||||
```csharp
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Esri.ArcGISRuntime.Geometry;
|
||||
using Esri.ArcGISRuntime.Location;
|
||||
using NmeaParser;
|
||||
|
||||
namespace NmeaParser.ArcGIS
|
||||
{
|
||||
public class NmeaLocationProvider : ILocationProvider
|
||||
public class NmeaLocationProvider : LocationDataSource
|
||||
{
|
||||
public event EventHandler<LocationInfo> LocationChanged;
|
||||
private readonly NmeaParser.NmeaDevice device;
|
||||
|
||||
public NmeaLocationProvider(NmeaParser.NmeaDevice device)
|
||||
{
|
||||
this.device = device;
|
||||
device.MessageReceived += device_MessageReceived;
|
||||
device.MessageReceived += NmeaMessageReceived;
|
||||
}
|
||||
|
||||
void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
|
||||
private void NmeaMessageReceived(object sender, NmeaMessageReceivedEventArgs e)
|
||||
{
|
||||
var message = e.Message;
|
||||
if (message is NmeaParser.Messages.Rmc rmc && rmc.Active)
|
||||
{
|
||||
LocationChanged?.Invoke(this, new LocationInfo()
|
||||
{
|
||||
Course = double.IsNaN(rmc.Course) ? 0 : rmc.Course, // Current ArcGIS Runtime limitation that course can't be NaN
|
||||
Speed = double.IsNaN(rmc.Speed) ? 0 : rmc.Speed,
|
||||
Location = new MapPoint(rmc.Longitude, rmc.Latitude, SpatialReferences.Wgs84)
|
||||
});
|
||||
base.UpdateLocation(new Location(
|
||||
new MapPoint(rmc.Longitude, rmc.Latitude, SpatialReferences.Wgs84),
|
||||
horizontalAccuracy: double.NaN,
|
||||
velocity: double.IsNaN(rmc.Speed) ? 0 : rmc.Speed,
|
||||
course: double.IsNaN(rmc.Course) ? 0 : rmc.Course, // Current ArcGIS Runtime limitation that course can't be NaN
|
||||
isLastKnown: false));
|
||||
}
|
||||
}
|
||||
protected override Task OnStartAsync() => device.OpenAsync();
|
||||
|
||||
public Task StartAsync() => device.OpenAsync();
|
||||
|
||||
public Task StopAsync() => device.CloseAsync();
|
||||
protected override Task OnStopAsync() => device.CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue