@@ -53,6 +53,7 @@ private static readonly (Color Color, double X, double Y)[] ObserverSeeds =
5353 ( Color . Blue , - 571683.896 , 7492017.864 ) ,
5454 } ;
5555
56+ // Graphics overlay for the analysis results.
5657 private GraphicsOverlay _resultsGraphicsOverlay ;
5758
5859 // Symbols for visible and not-visible line segments.
@@ -110,11 +111,11 @@ private async Task Initialize()
110111 // Create a continuous field from the elevation raster file.
111112 var continuousField = await ContinuousField . CreateAsync ( new [ ] { rasterPath } , 0 ) ;
112113
113- // Create line of sight positions for the target.
114- var targetLosPosition = new LineOfSightPosition ( _targetPosition , HeightOrigin . Relative ) ;
114+ // Create a line of sight position for the target.
115+ var targetPosition = new LineOfSightPosition ( _targetPosition , HeightOrigin . Relative ) ;
115116
116117 // Create line of sight positions for each observer.
117- var observerLosPositions = ObserverSeeds . Select ( seed =>
118+ var observerPositions = ObserverSeeds . Select ( seed =>
118119 new LineOfSightPosition (
119120 new MapPoint ( seed . X , seed . Y , RelativeHeightMeters , SpatialReferences . WebMercator ) ,
120121 HeightOrigin . Relative ) ) . ToList ( ) ;
@@ -123,7 +124,7 @@ private async Task Initialize()
123124 var parameters = new LineOfSightParameters
124125 {
125126 ObserverTargetPairs = new ObserverTargetPairs (
126- observerLosPositions , new [ ] { targetLosPosition } )
127+ observerPositions , new [ ] { targetPosition } )
127128 } ;
128129
129130 // Create line of sight function with the continuous field and parameters.
@@ -132,10 +133,6 @@ private async Task Initialize()
132133 // Evaluate the line of sight function.
133134 var results = await lineOfSightFunction . EvaluateAsync ( ) ;
134135
135- // Build observer summaries for the info panel.
136- var summaries = BuildObserverSummaries ( results ) ;
137- ResultsItemsControl . ItemsSource = summaries ;
138-
139136 // Add result line graphics to the results graphics overlay.
140137 foreach ( var result in results )
141138 {
@@ -155,42 +152,36 @@ private async Task Initialize()
155152 _resultsGraphicsOverlay . Graphics . Add ( graphic ) ;
156153 }
157154 }
155+
156+ // Build observer summaries for the info panel.
157+ ResultsItemsControl . ItemsSource = BuildObserverSummaries ( results ) ;
158158 }
159159 catch ( Exception ex )
160160 {
161161 MessageBox . Show ( ex . Message , "Error" ) ;
162162 }
163163 }
164164
165- // Filter the result line graphics based on the checkbox state to show only visible lines.
166- private void VisibleOnlyCheckBox_Changed ( object sender , RoutedEventArgs e )
167- {
168- if ( _resultsGraphicsOverlay == null ) return ;
169-
170- bool showVisibleOnly = VisibleOnlyCheckBox . IsChecked == true ;
171-
172- foreach ( var graphic in _resultsGraphicsOverlay . Graphics )
173- {
174- // TargetVisibility value of 1.0 indicates the target is visible from the observer.
175- bool isVisible = Convert . ToDouble ( graphic . Attributes [ "TargetVisibility" ] ) == 1.0 ;
176- graphic . IsVisible = ! showVisibleOnly || isVisible ;
177- }
178- }
179-
180165 // Build a list of observer result summaries from the line of sight results for display in the info panel.
181166 private List < ObserverResultSummary > BuildObserverSummaries ( IReadOnlyList < LineOfSight > results )
182167 {
183168 var summaries = new List < ObserverResultSummary > ( ) ;
184169 for ( int i = 0 ; i < results . Count ; i ++ )
185170 {
186171 var result = results [ i ] ;
187- var error = result . Error ;
188- var visibleLength = PolylineLengthMeters ( result . VisibleLine ) ;
189- var notVisibleLength = PolylineLengthMeters ( result . NotVisibleLine ) ;
190172
191- string infoText = error != null
192- ? error . Message
193- : GetVisibleDistanceInfoText ( visibleLength , notVisibleLength ) ;
173+ // Get the length of the visible line if it exists.
174+ var visibleLength = result . VisibleLine == null ? 0 :
175+ GeometryEngine . LengthGeodetic ( result . VisibleLine , LinearUnits . Meters , GeodeticCurveType . Geodesic ) ;
176+
177+ // Set the info text based on the results of the analysis.
178+ string infoText ;
179+ if ( result . Error != null )
180+ infoText = result . Error . Message ;
181+ else if ( result . NotVisibleLine == null )
182+ infoText = $ "Target visible from observer over { visibleLength : F1} metres.";
183+ else
184+ infoText = $ "Target not visible from observer. Obstructed after { visibleLength : F1} metres.";
194185
195186 var color = ObserverSeeds [ i ] . Color ;
196187 var brush = new SolidColorBrush (
@@ -201,20 +192,19 @@ private List<ObserverResultSummary> BuildObserverSummaries(IReadOnlyList<LineOfS
201192 return summaries ;
202193 }
203194
204- // Return a description of the line of sight result based on the visible and not-visible line lengths .
205- private static string GetVisibleDistanceInfoText ( double visibleLength , double notVisibleLength )
195+ // Filter the result line graphics based on the checkbox state to show only visible lines .
196+ private void VisibleOnlyCheckBox_Changed ( object sender , RoutedEventArgs e )
206197 {
207- if ( notVisibleLength <= 0 )
208- return $ "Target visible from observer over { visibleLength : F1} metres.";
198+ if ( _resultsGraphicsOverlay == null ) return ;
209199
210- return $ "Target not visible from observer. Obstructed after { visibleLength : F1} metres.";
211- }
200+ bool showVisibleOnly = VisibleOnlyCheckBox . IsChecked == true ;
212201
213- // Calculate the geodetic length of a polyline in meters.
214- private static double PolylineLengthMeters ( Polyline line )
215- {
216- if ( line == null ) return 0 ;
217- return GeometryEngine . LengthGeodetic ( line , LinearUnits . Meters , GeodeticCurveType . Geodesic ) ;
202+ foreach ( var graphic in _resultsGraphicsOverlay . Graphics )
203+ {
204+ // TargetVisibility value of 1.0 indicates the target is visible from the observer.
205+ bool isVisible = Convert . ToDouble ( graphic . Attributes [ "TargetVisibility" ] ) == 1.0 ;
206+ graphic . IsVisible = ! showVisibleOnly || isVisible ;
207+ }
218208 }
219209 }
220210
0 commit comments