Show / Hide Table of Contents

Method FromStreamCreator

FromStreamCreator(Func<NmeaLocationDataSource, Task<Stream>>, Func<NmeaLocationDataSource, Task>)

Returns a NmeaLocationDataSource that will create the NMEA stream on StartAsync(), and destroy on StopAsync() using the provided start/stop methods.

Declaration
public static NmeaLocationDataSource FromStreamCreator(Func<NmeaLocationDataSource, Task<Stream>> onStart, Func<NmeaLocationDataSource, Task> onStop = null)
Parameters
Type Name Description
System.Func<NmeaLocationDataSource, System.Threading.Tasks.Task<System.IO.Stream>> onStart

This method is called when the datasource starts, and should return a System.IO.Stream that points to the NMEA datasource.

System.Func<NmeaLocationDataSource, Task> onStop

This method is called when the datasource stops, and can be used to clean up resources.

Returns
Type Description
NmeaLocationDataSource
Remarks

This helper method is useful for only creating a datasource stream on start and stop, rather than always have the stream running regardless of the datasource state.

var port = new System.IO.Ports.SerialPort("COM1", 9600);
NmeaLocationDataSource serialPortDatasource = NmeaLocationDataSource.FromStreamCreator(
    onStart: (ds) =>
    {
        port.Open();
        return Task.FromResult(port.BaseStream);
    },
    onStop: (ds) =>
    {
        port.Close();
        return Task.CompletedTask;
    }
);
MyMapView.LocationDisplay.DataSource = serialPortDatasource;
MyMapView.LocationDisplay.IsEnabled = true; // This will trigger onStart to get called

As an alternative to this approach, you can also subclass NmeaLocationDataSource and override the OnStartAsync(), and OnStopAsync() methods.

Applies to

Platforms and versions
TargetVersions
.NET 6.0 Windows100.13 - 100.15
.NET Framework100.10 - 100.15
.NET 5100.10 - 100.12
.NET Core 3.1100.10 - 100.12
Xamarin.Android100.10 - 100.15
Xamarin.iOS100.10 - 100.15
UWP100.10 - 100.14
In This Article
Back to top Copyright © 2022 Esri.