-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
611 lines (522 loc) · 26.9 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.ArcGISServices;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Mapping.Labeling;
using Esri.ArcGISRuntime.RealTime;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks.Geocoding;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace Flights
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
#region Constants
// - main map
const BasemapStyle MainMapBasemap = BasemapStyle.ArcGISChartedTerritory;
// - tracking scene
const BasemapStyle TrackingSceneBasemap = BasemapStyle.ArcGISImagery;
const string ElevationServiceUrl = "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
const double SceneElevationExaggeration = 2.5;
// - weather map (precipitation radar)
const string WeatherMapItemUrl = "https://www.arcgis.com/home/item.html?id=629b61c7505547d5b4abad400ca2d049";
//const string PrecipRadarLayerUrl = "http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0q.cgi";
// Geocode service (for finding airports)
const string GeocodeServiceUrl = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";
// TODO: Provide a URL to a FlightAware stream service.
// (You can use another stream service, but may need to update field names and other details)
const string FlightAwareStreamUrl = "";
#endregion
public MainWindow()
{
InitializeComponent();
// Call functions to create the maps/scenes and graphics overlays.
SetupGeoModels();
_ = CreateGraphicsOverlays();
// Set the code behind as the data context
// (some properties will be bound to UI elements).
this.DataContext = this;
}
#region Start up functions
private async void SetupGeoModels()
{
// GeoModel == Map or Scene
// Main map to display dynamic entities
var mainMap = new Map(MainMapBasemap);
// Weather map (to show weather radar at the destination or origin airport).
var weatherMap = new Map(new Uri(WeatherMapItemUrl));
// Scene to show one entity (follow a graphic, eg) ...
// Create an elevation source to show relief in the scene.
var elevationSource = new ArcGISTiledElevationSource(new Uri(ElevationServiceUrl));
// Create a Surface with the elevation data.
var elevationSurface = new Surface
{
ElevationExaggeration = SceneElevationExaggeration
};
elevationSurface.ElevationSources.Add(elevationSource);
var trackingScene = new Scene(TrackingSceneBasemap)
{
BaseSurface = elevationSurface
};
// Set the initial extent to the southwestern United States.
var initialExtent = new Envelope(-120.5, 32.0, -110.0, 38.0, SpatialReferences.Wgs84);
mainMap.InitialViewpoint = new Viewpoint(initialExtent);
weatherMap.InitialViewpoint = new Viewpoint(initialExtent);
trackingScene.InitialViewpoint = new Viewpoint(initialExtent);
MainMapView.Map = mainMap;
WeatherMapView.Map = weatherMap;
TrackingSceneView.Scene = trackingScene;
}
private async Task CreateGraphicsOverlays()
{
// Create a GraphicsOverlay to show the selected airport on the weather map.
var graphicsOverlayAirport = new GraphicsOverlay();
var airportSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Yellow, 20);
var rendererAirports = new SimpleRenderer(airportSymbol);
var airportLabelSymbol = new TextSymbol
{
FontFamily = "Arial",
Color = System.Drawing.Color.Navy,
HaloColor = System.Drawing.Color.White,
HaloWidth = 2,
Size = 20
};
var airportLabelExp = new ArcadeLabelExpression("return $feature.airportcode;");
var airportLabelDef = new LabelDefinition(airportLabelExp, airportLabelSymbol)
{
WhereClause = "1=1",
Placement = LabelingPlacement.PointBelowCenter
};
graphicsOverlayAirport.LabelDefinitions.Add(airportLabelDef);
graphicsOverlayAirport.Renderer = rendererAirports;
graphicsOverlayAirport.LabelsEnabled = true;
WeatherMapView.GraphicsOverlays?.Add(graphicsOverlayAirport);
// Create a GraphicsOverlay to display a graphic for the selected dynamic entity in the scene view.
var graphicsOverlayTrackEntity = new GraphicsOverlay();
var modelUri = new Uri(@".\3D\bristol.dae", UriKind.Relative);
var plane3DSymbol = await ModelSceneSymbol.CreateAsync(modelUri, 1.0);
var rendererTrackEntity = new SimpleRenderer(plane3DSymbol);
// Set a heading expression to orient the plane symbol with its heading.
rendererTrackEntity.SceneProperties.HeadingExpression = "[heading]";
graphicsOverlayTrackEntity.Renderer = rendererTrackEntity;
graphicsOverlayTrackEntity.SceneProperties.SurfacePlacement = SurfacePlacement.RelativeToScene;
TrackingSceneView.GraphicsOverlays?.Add(graphicsOverlayTrackEntity);
}
#endregion
#region Properties
// ArcGIS Stream Service data source.
private ArcGISStreamService _streamService;
// Dynamic entity layer to display flights.
private DynamicEntityLayer _dynamicEntityLayer;
// The selected destination airport.
private string _selectedAirport;
// A graphic to show the selected flight in a scene view.
private Graphic _planeGraphic;
// Collection of flights going to the selected airport.
private ConcurrentDictionary<string, long> _dynamicEntityIdDictionary = new();
public ObservableCollection<DynamicEntity> DynamicEntityCollection { get; } = new ObservableCollection<DynamicEntity>();
// Collection of unique destinations (airport codes) for flights in the layer.
private ConcurrentDictionary<string, string> _uniqueAirportCodesDictionary = new();
public ObservableCollection<string> CurrentAirports { get; } = new ObservableCollection<string>();
// The selected flight.
private DynamicEntity _selectedFlight;
public DynamicEntity SelectedFlight
{
get { return _selectedFlight; }
set
{
_selectedFlight = value;
RaisePropertyChanged(nameof(SelectedFlight));
}
}
// Count of dynamic entities currently displayed.
private int _dynamicEntityCount = 0;
public int DynamicEntityCount
{
get { return _dynamicEntityCount; }
set
{
_dynamicEntityCount = value;
RaisePropertyChanged(nameof(DynamicEntityCount));
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region Utilities
private async void StartStreamService()
{
// Create the stream service from the URL (passed into the view model constructor).
_streamService = new ArcGISStreamService(new Uri(FlightAwareStreamUrl));
_streamService.ConnectionStatusChanged += (e, status) =>
{
Dispatcher.Invoke(()=>ConnectionStatusTextBlock.Text = $"{status}");
};
// Set option to purge updates older than 12 hours.
_streamService.PurgeOptions.MaximumDuration = new TimeSpan(12, 0, 0);
// Keep no more than 50 observations per track.
_streamService.PurgeOptions.MaximumObservationsPerTrack = 50;
// Filter the service to show flights above 10,000 feet.
var streamFilter = new ArcGISStreamServiceFilter
{
WhereClause = "alt >= 10000"
};
// If requested, also filter by the current map extent.
if (FilterWithExtentCheckBox.IsChecked == true)
{
var extent = MainMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry)?.TargetGeometry;
streamFilter.Geometry = extent;
}
_streamService.Filter = streamFilter;
// Setup the notification handlers for new dynamic entities and observations.
_streamService.DynamicEntityReceived += StreamService_DynamicEntityReceived;
_streamService.DynamicEntityObservationReceived += StreamService_DynamicEntityObservationReceived;
_streamService.DynamicEntityPurged += StreamService_DynamicEntityPurged;
// Create a dynamic entity layer to show the stream data.
_dynamicEntityLayer = new DynamicEntityLayer(_streamService)
{
// Create and apply a simple renderer with a red circle.
Renderer = new SimpleRenderer(new SimpleMarkerSymbol
(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 6))
};
var trackSym = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDotDot, System.Drawing.Color.RebeccaPurple, 2);
var trackLineRenderer = new SimpleRenderer(trackSym);
var previousObsSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, System.Drawing.Color.DarkMagenta, 5);
var previousObsRenderer = new SimpleRenderer(previousObsSym);
_dynamicEntityLayer.TrackDisplayProperties.TrackLineRenderer = trackLineRenderer;
_dynamicEntityLayer.TrackDisplayProperties.PreviousObservationRenderer = previousObsRenderer;
// Call a function to define labels.
SetupLabeling();
// Load and connect the stream service.
await _streamService.LoadAsync();
await _streamService.ConnectAsync();
// Add the layer to the map.
MainMapView.Map.OperationalLayers.Add(_dynamicEntityLayer);
// Handle the connection change event (clean up when closed).
_streamService.ConnectionStatusChanged += StreamConnectionStatusChanged;
}
private UniqueValueRenderer CreateRendererForDestination(string airportCode)
{
var uvr = new UniqueValueRenderer();
var defaultSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.RoyalBlue, 4);
var destinationSym = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 8);
uvr.DefaultSymbol = defaultSym;
var destinationValue = new UniqueValue(airportCode, airportCode, destinationSym, airportCode);
uvr.UniqueValues.Add(destinationValue);
uvr.FieldNames.Add("dest");
return uvr;
}
private void SetupLabeling()
{
_dynamicEntityLayer.LabelDefinitions.Clear();
var labelExp = new ArcadeLabelExpression("return $feature.ident");
var labelSym = new TextSymbol
{
FontFamily = "Arial",
Color = System.Drawing.Color.Navy,
HaloColor = System.Drawing.Color.White,
Size = 14
};
var labelDef = new LabelDefinition(labelExp, labelSym);
_dynamicEntityLayer.LabelDefinitions.Add(labelDef);
}
private async Task<MapPoint> GeocodeAirportCode(string airportCode)
{
var locator = await LocatorTask.CreateAsync(new Uri(GeocodeServiceUrl));
var geocodeResults = await locator.GeocodeAsync(airportCode);
var topResult = geocodeResults.FirstOrDefault();
if (topResult == null) { return null; }
return topResult.DisplayLocation;
}
private void StartTrackingPlane(GeoElement plane)
{
// Clear existing graphics in the scene view.
TrackingSceneView.GraphicsOverlays.First().Graphics.Clear();
// Get the flight's altitude for the graphic point z-value.
double planeAltitude = 0.0;
double.TryParse(plane.Attributes["alt"]?.ToString(), out planeAltitude);
var planeLocation = plane.Geometry as MapPoint;
var pointZ = new MapPoint(planeLocation.X, planeLocation.Y, planeAltitude, planeLocation.SpatialReference);
// Create a new graphic with flight ID and heading attributes.
var attributes = new Dictionary<string, object>
{
{"ident", plane.Attributes["ident"]},
{"heading", plane.Attributes["heading"] }
};
_planeGraphic = new Graphic(pointZ, attributes);
// Add the graphic.
TrackingSceneView.GraphicsOverlays.First().Graphics.Add(_planeGraphic);
// Apply an orbit camera controller to follow the graphic.
TrackingSceneView.CameraController = new OrbitGeoElementCameraController(_planeGraphic, 100.0);
}
#endregion
#region Stream event handlers
// Handle notifications for new dynamic entities.
private void StreamService_DynamicEntityReceived(object sender, DynamicEntityEventArgs e)
{
DynamicEntityCount++;
}
private void StreamService_DynamicEntityPurged(object sender, DynamicEntityEventArgs e)
{
DynamicEntityCount--;
// Get the dynamic entity being purged.
var dynamicEntity = e.DynamicEntity;
// Get the flight ID.
var flightId = dynamicEntity.Attributes["ident"]?.ToString();
if (!string.IsNullOrEmpty(flightId))
{
// Try to remove it from the ConcurrentDictionary.
if (_dynamicEntityIdDictionary.TryRemove(flightId, out long entityId))
{
// If removed, also remove from the collection.
Application.Current?.Dispatcher?.Invoke(() =>
{
DynamicEntityCollection.Remove(dynamicEntity);
});
}
}
}
// Handle notifications for new observations.
private void StreamService_DynamicEntityObservationReceived(object sender, DynamicEntityObservationEventArgs e)
{
// Get the attributes dictionary for this observation.
var attr = e.Observation.Attributes;
// Make sure there's a value for the destination airport.
if (attr["dest"] != null)
{
// Get the destination airport code as an upper case string.
var thisDestination = attr["dest"].ToString().ToUpper();
// Only look for North American airports (indicated by initial letter).
string[] prefixesCanadaMexicoUSA = { "K", "C", "M" };
if (!prefixesCanadaMexicoUSA.Any(prefix => thisDestination.StartsWith(prefix))) { return; }
// ----
// See if this destination is already in the airport code list.
// Add it to the list if it isn't.
// ----
if (_uniqueAirportCodesDictionary.TryAdd(thisDestination, thisDestination))
{
// If this is a new airport code, insert it into the observable collection.
Application.Current?.Dispatcher?.Invoke(() =>
{
CurrentAirports.Add(thisDestination);
});
}
// ----
// If there's a selected destination, see if this flight is going there.
// If it is, add the flight to the collection shown in the list box.
// ----
// See if this observation's destination ("dest") matches the selected airport.
if (_selectedAirport is not null && thisDestination == _selectedAirport)
{
// The "ident" field holds the flight ID ("DAL1234", eg).
var flightId = attr["ident"]?.ToString();
if (!string.IsNullOrEmpty(flightId))
{
// Get the dynamic entity to which this observation applies.
var dynamicEntity = e.Observation.GetDynamicEntity();
// Call 'TryAdd' on the ConcurrentDictionary (returns false if it already exists).
if (_dynamicEntityIdDictionary.TryAdd(flightId, dynamicEntity.EntityId))
{
// If this is a new flight ID, insert it into the observable collection.
Application.Current?.Dispatcher?.Invoke(() =>
{
DynamicEntityCollection.Add(dynamicEntity);
});
}
}
}
}
}
// Handle notifications for updates to the selected dynamic entity (flight).
private void SelectedFlight_DynamicEntityChanged(object sender, DynamicEntityChangedEventArgs e)
{
// Get updates from a new observation.
var obs = e.ReceivedObservation;
if (obs != null)
{
// Get the updated altitude for the graphic point z-value.
double planeAltitude = 0.0;
double.TryParse(obs.Attributes["alt"]?.ToString(), out planeAltitude);
var updatedLocation = obs.Geometry as MapPoint;
var pointZ = new MapPoint(updatedLocation.X, updatedLocation.Y, planeAltitude, updatedLocation.SpatialReference);
Dispatcher.Invoke(() =>
{
// Update the geometry and the heading attribute.
_planeGraphic.Geometry = pointZ;
_planeGraphic.Attributes["heading"] = obs.Attributes["heading"];
});
}
}
private void StreamConnectionStatusChanged(object sender, ConnectionStatus e)
{
// When the stream is disconnected, detach event handlers and clean up.
if (e == ConnectionStatus.Disconnected)
{
// Remove notification handlers.
_streamService.DynamicEntityReceived -= StreamService_DynamicEntityReceived;
_streamService.DynamicEntityObservationReceived -= StreamService_DynamicEntityObservationReceived;
_streamService.DynamicEntityPurged -= StreamService_DynamicEntityPurged;
// Remove the dynamic entity layer from the map.
MainMapView.Map.OperationalLayers.Remove(_dynamicEntityLayer);
// Clear any airports or dynamic entities tracked for the service.
_dynamicEntityIdDictionary = new();
_uniqueAirportCodesDictionary = new();
DynamicEntityCollection.Clear();
CurrentAirports.Clear();
// Clear the selected airport, flight, and reset entity count.
_selectedAirport = null;
SelectedFlight = null;
DynamicEntityCount = 0;
// Clear graphics and reset the map/scene viewpoints.
var mainMapViewpoint = MainMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
TrackingSceneView.GraphicsOverlays.First().Graphics.Clear();
TrackingSceneView.SetViewpoint(mainMapViewpoint);
WeatherMapView.GraphicsOverlays.First().Graphics.Clear();
WeatherMapView.SetViewpoint(mainMapViewpoint);
}
}
#endregion
#region UI event handlers
private void ZoomToDynamicEntity(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// Should be one or zero selected dynamic entities in the layer at any time.
var selectedFlight = _dynamicEntityLayer.GetSelectedDynamicEntities().FirstOrDefault();
if (selectedFlight != null)
{
var extentBuilder = new EnvelopeBuilder(selectedFlight.Geometry.Extent);
var flightViewpoint = new Viewpoint(extentBuilder.Center, 500000);
MainMapView.SetViewpoint(flightViewpoint);
}
}
private async void MainMapView_Tapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
// First dismiss any existing callout (previous identify, eg).
MainMapView.DismissCallout();
if (_dynamicEntityLayer is null) { return; }
// Identify the dynamic entity layer using the tap/click location on the map.
var idResult = await MainMapView.IdentifyLayerAsync(_dynamicEntityLayer, e.Position, 4, false, 1);
// Get the first DynamicEntityObservation from the results.
var obs = idResult.GeoElements.FirstOrDefault() as DynamicEntityObservation;
// Get the DynamicEntity for this observation.
// (if the user clicked a previous observation,
// this will "jump" the callout to the last one).
var de = obs?.GetDynamicEntity();
if (de != null)
{
// Get the flight ID, departure and arrival airports.
var flight = de.Attributes["ident"]?.ToString();
var from = de.Attributes["orig"]?.ToString();
var to = de.Attributes["dest"]?.ToString();
var fromTo = $"From '{from}' To '{to}'";
// Show the flight info in a callout at the entity location.
var calloutDef = new CalloutDefinition(flight, fromTo);
MainMapView.ShowCalloutForGeoElement(de, e.Position, calloutDef);
}
}
private void StreamServiceConnectButton_Click(object sender, RoutedEventArgs e)
{
// Connect to or disconnect from the stream service.
if (_streamService == null ||
_streamService.ConnectionStatus == ConnectionStatus.Disconnected)
{
// Make sure a service URL was provided.
if(string.IsNullOrEmpty(FlightAwareStreamUrl))
{
MessageBox.Show("Please provide a URL for the FlightAware stream service (line 40 of MainWindow.xaml.cs)",
"No stream service URL", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
StartStreamService();
FilterWithExtentCheckBox.IsEnabled = false;
StreamServiceConnectButton.Content = "Disconnect from stream service";
}
else
{
// Disconnect from the stream service data source.
_streamService.DisconnectAsync();
// Update the UI.
FilterWithExtentCheckBox.IsEnabled = true;
StreamServiceConnectButton.Content = "Connect to stream service";
}
}
private void MainMapView_ViewpointChanged(object sender, System.EventArgs e)
{
// Get the current map scale.
var currentScale = MainMapView.MapScale;
// Show tracks at scales larger than 1/500000
// (otherwise hide them).
var showTracks = (currentScale <= 500000);
var _dynamicEntityLayer = MainMapView.Map.OperationalLayers.OfType<DynamicEntityLayer>().FirstOrDefault();
// Layer might not be loaded yet.
if (_dynamicEntityLayer != null)
{
// Toggle tracks, observations, and labels.
_dynamicEntityLayer.TrackDisplayProperties.ShowTrackLine = showTracks;
_dynamicEntityLayer.TrackDisplayProperties.ShowPreviousObservations = showTracks;
_dynamicEntityLayer.LabelsEnabled = showTracks;
}
}
private async void SelectedDestinationChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// Clear any previously tracked dynamic entities.
DynamicEntityCollection.Clear();
_dynamicEntityIdDictionary.Clear();
if (e.AddedItems.Count > 0)
{
_selectedAirport = e.AddedItems[0].ToString();
// Create a renderer to show flights to this airport.
_dynamicEntityLayer.Renderer = CreateRendererForDestination(_selectedAirport);
WeatherMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Clear();
// Geocode to find the airport location from its code.
var airportLocation = await GeocodeAirportCode(_selectedAirport);
if (airportLocation == null) { return; }
// Create a new graphic for the airport.
var airportGraphic = new Graphic(airportLocation);
airportGraphic.Attributes.Add("airportcode", _selectedAirport);
WeatherMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(airportGraphic);
// Zoom to the airport on the weather map.
var airportViewpoint = new Viewpoint(airportLocation, 2000000);
WeatherMapView.SetViewpoint(airportViewpoint);
}
}
private void SelectedFlightChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// Clear any currrently selection.
_dynamicEntityLayer.ClearSelection();
if (SelectedFlight != null)
{
SelectedFlight.DynamicEntityChanged -= SelectedFlight_DynamicEntityChanged;
}
SelectedFlight = null;
if (e.AddedItems.Count > 0)
{
// Get the item selected in the ListBox.
SelectedFlight = e.AddedItems[0] as DynamicEntity;
if (SelectedFlight == null) { return; }
// Select the new flight.
_dynamicEntityLayer.SelectDynamicEntity(SelectedFlight);
// Start tracking the flight in the scene view.
StartTrackingPlane(SelectedFlight);
// Handle updates to this flight.
SelectedFlight.DynamicEntityChanged += SelectedFlight_DynamicEntityChanged;
}
}
#endregion
}
}