<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
<!-- QUERY -->
<StackPanel Margin="1">
<TextBlock Foreground="White" Margin="0,4,0,0" VerticalAlignment="Center" Text="{Binding Attributes[TYPE]}"/>
</StackPanel>
<StackPanel Margin="5,0,0,0" Orientation="Vertical">
<TextBlock Foreground="White" Text="{Binding Attributes[CITY_NAME], StringFormat='City Name: \{0\}'}" >
<TextBlock.Effect>
<DropShadowEffect/>
</TextBlock.Effect>
</TextBlock>
<TextBlock Foreground="White" Text="{Binding Attributes[POP1990], StringFormat='Population: \{0\}'}" >
<TextBlock.Effect>
<DropShadowEffect/>
</TextBlock.Effect>
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
For Each g As var In MyGraphicsLayer.Graphics
Dim c As MapPoint = g.Geometry.Extent.GetCenter()
g.Attribute("BUFFER_DISTANCE") = GetDistance(bufferPoint, c)
NextselectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(bp, c)selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)
Private _XYLocation As String = ""
Private Sub GeometryService_BufferCompleted2(ByVal sender As Object, ByVal args As GraphicsEventArgs)
Dim bufferGraphic As New Graphic()
bufferGraphic.Geometry = args.Results(0).Geometry
bufferGraphic.Geometry.SpatialReference = MyMap.SpatialReference
bufferGraphic.Symbol = TryCast(LayoutRoot.Resources("BufferSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
bufferGraphic.SetZIndex(1)
_pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic)
' Find the Center point of the buffer
Dim bp As ESRI.ArcGIS.Client.Geometry.MapPoint = bufferGraphic.Geometry.Extent.GetCenter()
' Set the Buffer Variable for the Center Point of the buffer
_XYLocation = Nothing
_XYLocation = bp.ToString
Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
query.ReturnGeometry = True
query.OutSpatialReference = MyMap.SpatialReference
query.Geometry = bufferGraphic.Geometry
query.OutFields.Add("*")
_queryTask.ExecuteAsync(query)
End Sub
Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs)
Dim featureSet As FeatureSet = args.FeatureSet
imageListBuffer.ItemsSource = args.FeatureSet.Features
' Set the Buffer Variable for the Center Point of the buffer
Dim _XYLocationBuffer As String = Nothing
_XYLocationBuffer = _XYLocation.ToString
If args.FeatureSet.Features.Count < 1 Then
MessageBox.Show("No features found")
Return
End If
For Each selectedGraphic As Graphic In args.FeatureSet.Features
selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
_resultsGraphicsLayer.Graphics.Add(selectedGraphic)
Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter()
MessageBox.Show(c.ToString)
selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)
Next selectedGraphic
End SubDim distParams = New ESRI.tasks.DistanceParameters() distParams.distanceUnit = ESRI.tasks.GeometryService.UNIT_STATUTE_MILE distParams.geometry1 = pointA '<--- your Point A geometry distParams.geometry2 = pointB '<--- your Point B geometry distParams.geodesic = True GeometryService.distance(distParams,function(distance))
For Each selectedGraphic As Graphic In args.FeatureSet.Features
selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
_resultsGraphicsLayer.Graphics.Add(selectedGraphic)
Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter()
MessageBox.Show(c.ToString)
selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c)
MessageBox.Show(selectedGraphic.Attributes("BUFFER_DISTANCE"))
Next selectedGraphic
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
<StackPanel Margin="1">
<TextBlock Foreground="White" Margin="0,4,0,0" VerticalAlignment="Center" Text="{Binding Attributes[TYPE]}"/>
</StackPanel>
<StackPanel Margin="5,0,0,0" Orientation="Vertical">
<TextBlock Foreground="White" Text="{Binding Attributes[NAME], StringFormat='Name: \{0\}'}" />
<TextBlock Foreground="White" Text="{Binding BUFFER_DISTANCE, StringFormat='Distance: \{0\}'}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Foreground="White" Text="{Binding BUFFER_DISTANCE, StringFormat='Distance: \{0\}'}" ><TextBlock Foreground="White" Text="{Binding Attributes[BUFFER_DISTANCE], StringFormat='Distance: \{0\}'}" >
private double GetDistance(MapPoint a, MapPoint b)
{
if (a == null || b == null) return 0;
return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
}
I have a similar issue where I want to get distance from a point to multiple points. Where did you find the GetDistance() method listed on your posts? I'm thinking this method isn't built into the API. Did you have to use the GeometryService for each point you wanted to get the distance to?
Thanks,
Rob
Private Function GetDistance(ByVal start As MapPoint, ByVal [end] As MapPoint) As Integer Dim deltaX As Double = 0 Dim deltaY As Double = 0 deltaX = start.X - [end].X deltaY = start.Y - [end].Y Return Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)) End Function