Map interaction client/Track layer interaction: Difference between revisions
(→) |
(→) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
{| class="wikitable" | {| class="wikitable" | ||
! Interface | ! Interface !! Accesed through | ||
! Accesed through | |||
|- | |- | ||
| [http://maria. | | [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'' | ||
|- | |- | ||
| [http://maria. | | [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'' | ||
|} | |} | ||
Line 45: | Line 44: | ||
var speed = RandomProvider.GetRandomDouble(5.0, 50.0); | var speed = RandomProvider.GetRandomDouble(5.0, 50.0); | ||
var course = RandomProvider.GetRandomDouble(0, 360.0); | var course = RandomProvider.GetRandomDouble(0, 360.0); | ||
var pos = RandomProvider.GetRandomPosition(_trackLayer.GeoContext.Viewport.GeoRect); | var pos = RandomProvider.GetRandomPosition(_trackLayer.GeoContext.Viewport.GeoRect); | ||
var trackData = new TrackData(itemId, pos, course, speed) { ObservationTime = DateTime.UtcNow }; | var trackData = new TrackData(itemId, pos, course, speed) { ObservationTime = DateTime.UtcNow }; | ||
trackData.Fields["name"] = strId; | trackData.Fields["name"] = strId; | ||
switch (_trackCnt % 4) | switch (_trackCnt % 4) | ||
Line 84: | Line 81: | ||
private static Random _rand = new Random(); | private static Random _rand = new Random(); | ||
public static int GetRandomInt(int minimum, int maximum) | public static int GetRandomInt(int minimum, int maximum) | ||
{ | { | ||
Line 95: | Line 86: | ||
} | } | ||
public static double GetRandomDouble(double minimum, double maximum) | public static double GetRandomDouble(double minimum, double maximum) | ||
{ | { | ||
Line 106: | Line 91: | ||
} | } | ||
public static GeoPos GetRandomPosition(GeoRect geoRect, double margin = 1.0) | public static GeoPos GetRandomPosition(GeoRect geoRect, double margin = 1.0) | ||
{ | { | ||
Line 120: | Line 98: | ||
DeltaLon = geoRect.DeltaLon * 0.9 | DeltaLon = geoRect.DeltaLon * 0.9 | ||
}; | }; | ||
var pos = new GeoPos( | var pos = new GeoPos( | ||
Line 129: | 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 178: | 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 | 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 16: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 };
}
}
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);
}
}
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.
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.