Hi Guys,
I was wondering if there is a way to add Distance to Geometry. I am currently using a GeometryService to work out a Distance between two points however I don't see any functionailty to add distance to a point.
I know there is a MapPoint.MoveTo() function but this takes coordniates, not a distance.
Any help would be appericated.
Thanks
Hi Christopher,
I'm not sure I understand the question. Are you asking to move geometry by some distance or do you want to store distance?
If it is the former, you can still use MapPoint.MoveTo() specifying current position and the distance you want to move by, in this example I am only moving X by distance from GeometryService. In this sample, I am using Editor to add my 3 graphics and then I move third graphic by the distance between first and second graphic.
If you need the latter, you can use graphic.Attributes["distance"] = distance to store it and to retrieve it you just need to cast back to double.
xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
<UserControl.Resources>
<esri:SimpleMarkerSymbol x:Key="SMS" />
<esri:Editor x:Key="MyEditor"
LayerIDs="MyLayer"
Map="{Binding ElementName=MyMap}"
GeometryServiceUrl="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<esri:Map x:Name="MyMap">
<esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
<esri:GraphicsLayer ID="MyLayer" />
</esri:Map>
<StackPanel
VerticalAlignment="Top"
HorizontalAlignment="Center"
DataContext="{StaticResource MyEditor}">
<Button Content="Add"
Command="{Binding Add}"
CommandParameter="{StaticResource SMS}" />
<Button Content="Move" Click="Button_Click" />
</StackPanel>
</Grid>
public EditorSample()
{
InitializeComponent();
var editor = this.Resources["MyEditor"] as Editor;
editor.Map = MyMap;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var layer = MyMap.Layers["MyLayer"] as GraphicsLayer;
if (layer.Graphics.Count > 2)
{
var first = layer.Graphics[0];
var second = layer.Graphics[1];
var distance = await GetDistanceAsync(first.Geometry, second.Geometry);
var third = layer.Graphics[2];
var mapPoint = (MapPoint)third.Geometry;
mapPoint.MoveTo(mapPoint.X + distance, mapPoint.Y);
}
}