Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MAUI/Maui.Samples/ArcGIS.Samples.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<MauiImage Include="Resources\Icons\*.svg" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\PictureMarkerSymbols\beacon.png" />
<EmbeddedResource Include="Resources\PictureMarkerSymbols\pin_blue.png" />
<EmbeddedResource Include="Resources\PictureMarkerSymbols\pin_star_blue.png" />
</ItemGroup>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGIS.Samples.ShowLineOfSightAnalysisOnMap.ShowLineOfSightAnalysisOnMap"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Maui;assembly=Esri.ArcGISRuntime.Maui">
<Grid Style="{DynamicResource EsriSampleContainer}">
<esriUI:MapView x:Name="MyMapView" Style="{DynamicResource EsriSampleGeoView}" />
<Border Style="{DynamicResource EsriSampleControlPanel}"
VerticalOptions="Start"
MaximumWidthRequest="620">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="250" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<CheckBox x:Name="VisibleOnlyCheckBox"
Grid.Column="0"
CheckedChanged="VisibleOnlyCheckBox_Changed" />
<Label Grid.Column="1"
Text="Show line of sight where target (circle) is visible from observer (triangle)"
VerticalOptions="Center"
LineBreakMode="WordWrap" />
</Grid>
<BoxView Grid.Row="1" HeightRequest="1" Color="Gray" Margin="0,4" />
<ScrollView Grid.Row="2">
<VerticalStackLayout x:Name="ResultsStackLayout" />
</ScrollView>
</Grid>
</Border>
<Label Text="Raster data Copyright Scottish Government and SEPA (2014)"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
HorizontalOptions="End"
VerticalOptions="End"
Margin="0,0,10,30"
FontAttributes="Italic"
FontSize="11"
TextColor="White" />
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
// Copyright 2026 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Analysis;
using Esri.ArcGISRuntime.Analysis.Visibility;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Color = System.Drawing.Color;
using Grid = Microsoft.Maui.Controls.Grid;

namespace ArcGIS.Samples.ShowLineOfSightAnalysisOnMap
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Show line of sight analysis in map",
category: "Analysis",
description: "Perform a line of sight analysis in a map view between fixed observer and target positions.",
instructions: "The sample loads with a map centered on the Isle of Arran, Scotland, and runs a line of sight analysis from multiple observer points (triangles) to a fixed target point (beacon icon) located at the highest point of the island. Solid green line segments represent visible portions of each line of sight result, and dashed gray segments represent not visible portions. For each observer, the information panel reports whether the target is visible and over what distance the line remains unobstructed. Use the checkbox in the panel to show only results where the target is visible from the observer.",
tags: new[] { "analysis", "elevation", "line of sight", "map view", "spatial analysis", "terrain", "visibility" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData("aa97788593e34a32bcaae33947fdc271")]
[ArcGIS.Samples.Shared.Attributes.EmbeddedResource(@"PictureMarkerSymbols\beacon.png")]
public partial class ShowLineOfSightAnalysisOnMap : ContentPage
{
private const double RelativeHeightMeters = 5.0;

// Target position (radio mast/receiver location).
private readonly MapPoint _targetPosition = new MapPoint(
-577955.365, 7484288.220, RelativeHeightMeters,
SpatialReferences.WebMercator);

// Observer positions with associated colors.
private static readonly (Color Color, double X, double Y)[] ObserverSeeds =
{
(Color.Green, -580893.546, 7489102.890),
(Color.Cyan, -583446.004, 7483567.462),
(Color.Orange, -577665.236, 7490792.908),
(Color.Yellow, -576452.981, 7487071.388),
(Color.FromArgb(255, 228, 168, 239), -576650.067, 7481479.772), // light purple
(Color.Blue, -571683.896, 7492017.864),
};

// Graphics overlay for the analysis results.
private GraphicsOverlay _resultsGraphicsOverlay;
Comment thread
praveenaak marked this conversation as resolved.

// Symbols for visible and not-visible line segments.
private readonly SimpleLineSymbol _visibleLineSymbol = new SimpleLineSymbol(
SimpleLineSymbolStyle.Solid, Color.Green, 4);

private readonly SimpleLineSymbol _notVisibleLineSymbol = new SimpleLineSymbol(
SimpleLineSymbolStyle.LongDash, Color.Gray, 2);

public ShowLineOfSightAnalysisOnMap()
{
InitializeComponent();
_ = Initialize();
}

// Set up the map, graphics overlays, and perform the line of sight analysis.
private async Task Initialize()
{
// Create a map with a dark hillshade basemap and set the initial viewpoint to the Isle of Arran, Scotland.
MyMapView.Map = new Map(BasemapStyle.ArcGISHillshadeDark)
{
InitialViewpoint = new Viewpoint(55.632572, -5.185883, DeviceInfo.Idiom == DeviceIdiom.Phone ? 200000 : 90000)
};

// Create graphics overlays for results and position markers.
_resultsGraphicsOverlay = new GraphicsOverlay();
var positionsGraphicsOverlay = new GraphicsOverlay();
MyMapView.GraphicsOverlays.Add(_resultsGraphicsOverlay);
MyMapView.GraphicsOverlays.Add(positionsGraphicsOverlay);

try
{
// Create a beacon symbol from an embedded resource image for the target point graphic.
string resourceStreamName = GetType().Assembly.GetManifestResourceNames().Single(str => str.EndsWith("beacon.png"));
PictureMarkerSymbol beaconSymbol;
using (Stream resourceStream = GetType().Assembly.GetManifestResourceStream(resourceStreamName))
{
beaconSymbol = await PictureMarkerSymbol.CreateAsync(resourceStream);
beaconSymbol.Width = 24;
beaconSymbol.Height = 24;
}
positionsGraphicsOverlay.Graphics.Add(new Graphic(_targetPosition, beaconSymbol));

// Add observer position graphics using triangle marker symbols.
foreach (var seed in ObserverSeeds)
{
var observerPoint = new MapPoint(seed.X, seed.Y, RelativeHeightMeters, SpatialReferences.WebMercator);
var observerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Triangle, seed.Color, 15);
positionsGraphicsOverlay.Graphics.Add(new Graphic(observerPoint, observerSymbol));
}

// Get the path to the locally stored elevation raster file.
string rasterPath = DataManager.GetDataFolder("aa97788593e34a32bcaae33947fdc271", "arran.tif");

// Create a continuous field from the elevation raster file.
var continuousField = await ContinuousField.CreateAsync(new[] { rasterPath }, 0);

// Create a line of sight position for the target.
var targetPosition = new LineOfSightPosition(_targetPosition, HeightOrigin.Relative);

// Create line of sight positions for each observer.
var observerPositions = ObserverSeeds.Select(seed =>
new LineOfSightPosition(
new MapPoint(seed.X, seed.Y, RelativeHeightMeters, SpatialReferences.WebMercator),
HeightOrigin.Relative)).ToList();

// Create line of sight parameters with many-to-many observer-target pairs.
var parameters = new LineOfSightParameters
{
ObserverTargetPairs = new ObserverTargetPairs(
observerPositions, new[] { targetPosition })
};

// Create line of sight function with the continuous field and parameters.
var lineOfSightFunction = new LineOfSightFunction(continuousField, parameters);

// Evaluate the line of sight function.
var results = await lineOfSightFunction.EvaluateAsync();

// Add result line graphics to the results graphics overlay.
foreach (var result in results)
{
var targetVisibility = result.TargetVisibility;

if (result.VisibleLine != null)
{
var graphic = new Graphic(result.VisibleLine, _visibleLineSymbol);
graphic.Attributes["TargetVisibility"] = targetVisibility;
_resultsGraphicsOverlay.Graphics.Add(graphic);
}

if (result.NotVisibleLine != null)
{
var graphic = new Graphic(result.NotVisibleLine, _notVisibleLineSymbol);
graphic.Attributes["TargetVisibility"] = targetVisibility;
_resultsGraphicsOverlay.Graphics.Add(graphic);
}
}

// Build observer summaries for the info panel.
BuildResultsUI(results);
}
catch (Exception ex)
{
await Application.Current.Windows[0].Page.DisplayAlertAsync("Error", ex.Message, "OK");
}
}

// Build the results UI by programmatically adding rows to the VerticalStackLayout for each observer.
private void BuildResultsUI(IReadOnlyList<LineOfSight> results)
{
for (int i = 0; i < results.Count; i++)
{
var result = results[i];

// Get the length of the visible line if it exists.
var visibleLength = result.VisibleLine == null ? 0 :
GeometryEngine.LengthGeodetic(result.VisibleLine, LinearUnits.Meters, GeodeticCurveType.Geodesic);

// Set the info text based on the results of the analysis.
string infoText;
if (result.Error != null)
infoText = result.Error.Message;
else if (result.NotVisibleLine == null)
infoText = $"Target visible from observer over {visibleLength:F1} metres.";
else
infoText = $"Target not visible from observer. Obstructed after {visibleLength:F1} metres.";

// Update the UI.
var color = ObserverSeeds[i].Color;

var row = new Grid
{
Margin = new Thickness(0, 2),
ColumnDefinitions =
{
new ColumnDefinition(new GridLength(30)),
new ColumnDefinition(GridLength.Star)
}
};

var rect = new BoxView
{
WidthRequest = 16,
HeightRequest = 16,
Color = Microsoft.Maui.Graphics.Color.FromRgba(color.R, color.G, color.B, color.A),
HorizontalOptions = LayoutOptions.Start,
Margin = new Thickness(4, 0, 0, 0)
};
Grid.SetColumn(rect, 0);

var label = new Label
{
Text = infoText,
LineBreakMode = LineBreakMode.WordWrap,
Margin = new Thickness(4, 2)
};
Grid.SetColumn(label, 1);

row.Children.Add(rect);
row.Children.Add(label);
ResultsStackLayout.Children.Add(row);
}
}

// Filter the result line graphics based on the checkbox state to show only visible lines.
private void VisibleOnlyCheckBox_Changed(object sender, CheckedChangedEventArgs e)
{
if (_resultsGraphicsOverlay == null) return;

bool showVisibleOnly = VisibleOnlyCheckBox.IsChecked;

foreach (var graphic in _resultsGraphicsOverlay.Graphics)
{
// TargetVisibility value of 1.0 indicates the target is visible from the observer.
bool isVisible = Convert.ToDouble(graphic.Attributes["TargetVisibility"]) == 1.0;
graphic.IsVisible = !showVisibleOnly || isVisible;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Show line of sight analysis in map

Perform a line of sight analysis in a map view between fixed observer and target positions.

![Show line of sight analysis in map sample](showlineofsightanalysisonmap.jpg)

## Use case

Line of sight analysis determines whether a target can be seen from one or more observer locations based on elevation data. This can support planning workflows such as siting communication equipment, assessing observation coverage, or evaluating potential obstructions between known locations. In this sample, several predefined observer points are evaluated against a single fixed target to compare visibility outcomes side by side.

Note: This analysis is a form of "data-driven analysis", which means the analysis is calculated at the resolution of the data rather than the resolution of the display.

## How to use the sample

The sample loads with a map centered on the Isle of Arran, Scotland, and runs a line of sight analysis from multiple observer points (triangles) to a fixed target point (beacon icon) located at the highest point of the island. Solid green line segments represent visible portions of each line of sight result, and dashed gray segments represent not visible portions. For each observer, the information panel reports whether the target is visible and over what distance the line remains unobstructed. Use the checkbox in the panel to show only results where the target is visible from the observer.

## How it works

1. Create a `Map` and set it on a `MapView`.
2. Create a `GraphicsOverlay` and add target and observer points to it, along with an appropriate symbol. Create another `GraphicsOverlay` that will display the line of sight result graphics.
3. Create a `ContinuousField` from a raster file containing elevation data.
4. Create a list of `LineOfSightPosition` from target and observer `MapPoint`s and a `HeightOrigin.Relative`.
5. Configure `LineOfSightParameters` with a new `ObserverTargetPairs`, passing the list of observer and target line of sight positions.
6. Create a `LineOfSightFunction` from the continuous field and line of sight parameters.
7. Evaluate the function to get `LineOfSight` results.
8. Create a `Graphic` from each result, using the geometry of the result's `VisibleLine` or `NotVisibleLine` result, and an appropriate symbol.
9. Use `LineOfSight.TargetVisibility` to determine if the observer position has a direct line of sight to the target position.
10. Check for `LineOfSight.Error`s and get the length of the visible line result with `GeometryEngine.LengthGeodetic` to report results.

## Relevant API

* ContinuousField
* GeometryEngine
* GraphicsOverlay
* LineOfSight
* LineOfSightFunction
* LineOfSightParameters
* LineOfSightPosition
* ObserverTargetPairs

## About the data

The sample uses a [10m resolution digital terrain elevation raster of the Isle of Arran, Scotland](https://www.arcgis.com/home/item.html?id=aa97788593e34a32bcaae33947fdc271)
(Raster data Copyright Scottish Government and SEPA (2014)).

## Tags

analysis, elevation, line of sight, map view, spatial analysis, terrain, visibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"category": "Analysis",
"description": "Perform a line of sight analysis in a map view between fixed observer and target positions.",
"formal_name": "ShowLineOfSightAnalysisOnMap",
"ignore": false,
"images": [
"showlineofsightanalysisonmap.jpg"
],
"keywords": [
"analysis",
"elevation",
"line of sight",
"map view",
"spatial analysis",
"terrain",
"visibility"
],
"offline_data": [],
"redirect_from": [],
"relevant_apis": [
"ContinuousField",
"GeometryEngine",
"GraphicsOverlay",
"LineOfSight",
"LineOfSightFunction",
"LineOfSightParameters",
"LineOfSightPosition",
"ObserverTargetPairs"
],
"snippets": [
"ShowLineOfSightAnalysisOnMap.xaml.cs",
"ShowLineOfSightAnalysisOnMap.xaml"
],
"title": "Show line of sight analysis in map"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/MAUI/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [Show exploratory viewshed from geoelement in scene](Maui.Samples/Samples/Analysis/ShowExploratoryViewshedFromGeoelementInScene) - Analyze the exploratory viewshed for an object (GeoElement) in a scene.
* [Show exploratory viewshed from point in scene](Maui.Samples/Samples/Analysis/ShowExploratoryViewshedFromPointInScene) - Perform an exploratory viewshed analysis from a defined vantage point.
* [Show interactive viewshed with analysis overlay](Maui.Samples/Samples/Analysis/ShowInteractiveViewshedInAnalysisOverlay) - Perform an interactive viewshed analysis to determine visible and non-visible areas from a given observer position.
* [Show line of sight analysis in map](Maui.Samples/Samples/Analysis/ShowLineOfSightAnalysisOnMap) - Perform a line of sight analysis in a map view between fixed observer and target positions.

## Data

Expand Down
1 change: 1 addition & 0 deletions src/Samples.Shared/Resources/FeaturedSamples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Sample>ApplyMapAlgebra</Sample>
<Sample>DistanceMeasurement</Sample>
<Sample>ShowInteractiveViewshedInAnalysisOverlay</Sample>
<Sample>ShowLineOfSightAnalysisOnMap</Sample>
</Category>
<Category name="Data">
<Sample>CreateKmlMultiTrack</Sample>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading