Map interaction client/Track layer interaction: Difference between revisions

From Maria GDK Wiki
Jump to navigation Jump to search
()
()
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:


{| class="wikitable"
{| class="wikitable"
! Interface
! Interface !! Accesed through
! Accesed through
|-
|-
| [http://maria.support2.teleplan.no/MariaGDKDoc/html/B2FB03E9.htm ''IMariaTrackLayer'']
| [http://codedocs.maria.teleplanglobe.com/release/managed/interface_t_p_g_1_1_maria_1_1_track_contracts_1_1_i_maria_track_layer.html ''IMariaTrackLayer'']
| *_trackLayer*
| ''_trackLayer''
|-
|-
| [http://maria.support2.teleplan.no/MariaGDKDoc/html/AA8CECEC.htm ''IMariaExtendedTrackLayer'']
| [http://codedocs.maria.teleplanglobe.com/release/managed/interface_t_p_g_1_1_maria_1_1_track_contracts_1_1_i_maria_extended_track_layer.html ''IMariaExtendedTrackLayer'']
| *_trackLayer.ExtendedTrackLayer*
| ''_trackLayer.ExtendedTrackLayer''
|}
|}


Line 107: Line 106:
     }
     }


     public static GeoPoint GetRandomGeoPoint(GeoRect geoRect, double minAlt, double maxAlt)
     public static GeoPoint GetRandomGeoPoint(GeoRect geoRect, double minAlt = 0.0, double maxAlt = 0.0)
     {
     {
         var pt = GetRandomPosition(geoRect);
         var pt = GetRandomPosition(geoRect);
Line 156: Line 155:
== Track selection ==
== Track selection ==


The Maria Control supports selection of tracks by user action in the map area, single select or area select. For additional info, see section “”.
The Maria Control supports selection of tracks by user action in the map area, single select or area select.


In addition, setting and getting selection state can be performed programmatically through the extended track layer interface.
In addition, setting and getting selection state can be performed programmatically through the extended track layer interface.

Latest revision as of 17:00, 2 November 2020

Track Layer preparations

How to connect to, and display tracks from, a track service was described in MariaBasicMapClient, .

Please note that creating, updating and removing tracks is performed towards the connected track service, and will have effect for all clients connected to this service, while selection handling and track display are performed locally on your client only.

We will now perform further interactions towards the track layer through the track layer interfaces:

Interface Accesed through
IMariaTrackLayer _trackLayer
IMariaExtendedTrackLayer _trackLayer.ExtendedTrackLayer

Create tracks

Use the TrackData class to create new track objects. Apply desired track info, and pass it to the track service with the SetTrackData method.

string list = . . . // e.g. "MyList" or  _trackLayer.ActiveTrackList;
string strId = . . . // Unique Id;
ItemId id = new ItemId(list, strId);
double speed = . . .
double course = . . .
GeoPos pos = . . . 

TrackData trackData =  new TrackData(itemId, pos, course, speed) 
{ ObservationTime = DateTime.UtcNow };
trackData.SetTrackDataField("name", strId);

_trackLayer.SetTrackData(trackData);

For your convinience, here here you have methods for adding basic tracks at a random possition (RandomProvider class) within the current screen area:

public void OnAddTrack()
{
    if (_trackLayer.ActiveTrackList == null)
        return;

    var strId = "Track-" + _trackCnt++ + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
    var itemId = new ItemId(_trackLayer.ActiveTrackList, strId);
    var speed = RandomProvider.GetRandomDouble(5.0, 50.0);
    var course = RandomProvider.GetRandomDouble(0, 360.0);

    var pos = RandomProvider.GetRandomPosition(_trackLayer.GeoContext.Viewport.GeoRect);
    var trackData = new TrackData(itemId, pos, course, speed) { ObservationTime = DateTime.UtcNow };
    trackData.Fields["name"] = strId;

    switch (_trackCnt % 4)
    {
        case 0:
            trackData.Fields["symbol.2525code"] = "SUS*------*****";
            trackData.Fields["identity"] = "Undef";
            trackData.Fields["type"] = "U";
            break;
        case 1:
            trackData.Fields["symbol.2525code"] = "SFS*------*****";
            trackData.Fields["identity"] = "Friend";
            trackData.Fields["type"] = "F";
            break;
        case 2:
            trackData.Fields["symbol.2525code"] = "SHS*------*****";
            trackData.Fields["identity"] = "Hostile";
            trackData.Fields["type"] = "H";          
            break;
        case 3:
            trackData.Fields["symbol.2525code"] = "SNS*------*****";
            trackData.Fields["identity"] = "Neutral";
            trackData.Fields["type"] = "N";
            break;
    }

    _trackLayer.SetTrackData(trackData);
    _trackCnt++;
}

public static class RandomProvider
{
    private static Random _rand = new Random();

    public static int GetRandomInt(int minimum, int maximum)
    {
        return _rand.Next(minimum, maximum);
    }

    public static double GetRandomDouble(double minimum, double maximum)
    {
        return _rand.NextDouble() * (maximum - minimum) + minimum;
    }

    public static GeoPos GetRandomPosition(GeoRect geoRect, double margin = 1.0)
    {
        var rect = new GeoRect(geoRect.Center)
        {
            DeltaLat = geoRect.DeltaLat * 0.9,
            DeltaLon = geoRect.DeltaLon * 0.9
        };

        var pos = new GeoPos(
            GetRandomDouble(rect.UpperLeft.Lat, rect.LowerRight.Lat),
            GetRandomDouble(rect.UpperLeft.Lon, rect.LowerRight.Lon));

        return pos;
    }

    public static GeoPoint GetRandomGeoPoint(GeoRect geoRect, double minAlt = 0.0, double maxAlt = 0.0)
    {
        var pt = GetRandomPosition(geoRect);
        var alt = GetRandomDouble(minAlt, maxAlt);
        return new GeoPoint() { Latitude = pt.Lat, Longitude = pt.Lon, Altitude = alt };
    }
}
Map area with new track

Update tracks

Track information can be obtained with the track layer interface GetTrackData method, and updated by the SetTrackData method.

Example:

var dataCollection = _trackLayer.GetTrackData(arrayOfTrackIds);
foreach (var trackData in dataCollection)
{
    trackData.Pos = newPosition;
    trackData.Speed = newSpeed;
    trackData.Course = newCourse;
}

_trackLayer.SetTrackData(dataCollection);

Here you have a code example for updating position, course and speed of the currently added tracks.

public void OnUpdateTrack()
{
    var dataCollection = _trackLayer.GetTrackData();
    foreach (var track in dataCollection)
    {
        var rect = _trackLayer.GeoContext.Viewport.GeoRect;

        rect.Center = track.Pos ?? RandomProvider.GetRandomPosition(rect);
        rect.InflateRelative(0.3);

        track.Course = RandomProvider.GetRandomDouble(-179.9, 180.0);
        track.Speed = RandomProvider.GetRandomDouble(5.0, 50.0);
        track.Pos = RandomProvider.GetRandomPosition(rect);

        _trackLayer.SetTrackData(track);
    }
}
Map area with updated track

Track selection

The Maria Control supports selection of tracks by user action in the map area, single select or area select.

In addition, setting and getting selection state can be performed programmatically through the extended track layer interface.

Example:

var selection = _trackLayer.ExtendedTrackLayer.Selected;

_trackLayer.ExtendedTrackLayer.Deselect(itemId);
_trackLayer.ExtendedTrackLayer.Select(itemId);

_trackLayer.ExtendedTrackLayer.Select(newSelection);
_trackLayer.ExtendedTrackLayer.Selected.Clear();

The sample project contains example code for selecting and de-selecting tracks.

Track selection in map area

Remove tracks

The DeleteTrackData method in the track layer interface is used to remove tracks from the track store.

Example:

_trackLayer.DeleteTrackData(instanceId);

The sample project contains example code for removing selected tracks.

Removing tracks