Private Sub QueryTask_ExecuteCompletedBuffer2(ByVal sender As Object, ByVal args As QueryEventArgs) ' Set up the collection View Source in order to Sort the results of the query by DISTANCE Dim cs As New CollectionViewSource cs.SortDescriptions.Add(New SortDescription("BUFFER_DISTANCE", ListSortDirection.Ascending)) cs.Source = args.FeatureSet.Features ' Apply the sort to the listbox imageListBuffer.ItemsSource = cs.View ' refresh the listbox cs.View.Refresh() Dim featureSet As FeatureSet = args.FeatureSet imageListBuffer.ItemsSource = args.FeatureSet.Features ' Set the Buffer Variable for the Center Point of the buffer to a MAPPOINT not String to the variable being set ' in the GeometryService_BufferCompleted2...the Variable is globally define at the to of the code page Dim _XYLocationBuffer As MapPoint = Nothing _XYLocationBuffer = _XYLocation 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) ' Get the center point of each selected graphic found in the buffer Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter() ' Call the GetDistance Function...Set the Distance to the BUFFER_DISTANCE variable for each graphic, for display in the listbox selectedGraphic.Attributes("BUFFER_DISTANCE") = GetDistance(_XYLocationBuffer, c) Next selectedGraphic End Sub
For me, I think Linq query might be the easiest solution. Once you have calculated and added the Distance, you can order by this attribute. You can then set ListBox ItemSource with the sortedGraphics.var sortedGraphics = from g in graphicsLayer.Graphics orderby (double)g.Attributes["Distance"] ascending select g;
Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("Distance")) Ascending imageListBuffer.ItemsSource = sortedGraphics
Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("Distance")) Ascending
Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("Distance")) Descending
'Dim sortedGraphics = From g In args.FeatureSet.Features Order By (g.Attributes("NAME")) Ascending 'Dim sortedGraphics = From g In args.FeatureSet.Features Order By (g.Attributes("NAME")) Descending
Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("DISTANCE")) Ascending Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("DISTANCE")) Descending
private void GraphicsLayer_Initialized(object sender, EventArgs e) { GraphicsLayer l = sender as GraphicsLayer; Graphic gr = new Graphic(); gr.Attributes["Distance"] = 2.3; l.Graphics.Add(gr); gr = new Graphic(); gr.Attributes["Distance"] = 4.0; l.Graphics.Add(gr); gr = new Graphic(); gr.Attributes["Distance"] = 2.3; l.Graphics.Add(gr); gr = new Graphic(); gr.Attributes["Distance"] = 3.2; l.Graphics.Add(gr); gr = new Graphic(); gr.Attributes["Distance"] = 1.0; l.Graphics.Add(gr); var sortedGraphics = from g in l.Graphics orderby (double) g.Attributes["Distance"] ascending select g; myList.ItemsSource = sortedGraphics; }
<ListBox x:Name="myList" VerticalAlignment="Top" HorizontalAlignment="Center" > <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Attributes[Distance]}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Dim featureSet As FeatureSet = args.FeatureSet ' CODE WAS HERE Dim _XYLocationBuffer As MapPoint = Nothing _XYLocationBuffer = _XYLocation 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) selectedGraphic.Symbol = TryCast(LayoutRoot.Resources("StrobeMarkerSymbol_Blue"), ESRI.ArcGIS.Client.Symbols.Symbol) _resultsGraphicsLayer.Graphics.Add(selectedGraphic) 'graphicsLayer.Graphics.Add(selectedGraphic) ' Get the center point of each selected graphic found in the buffer Dim c As ESRI.ArcGIS.Client.Geometry.MapPoint = selectedGraphic.Geometry.Extent.GetCenter() ' Call the GetDistance Function...Set the Distance to the BUFFER_DISTANCE variable for each graphic, for display in the listbox selectedGraphic.Attributes("DISTANCE") = GetDistance(_XYLocationBuffer, c) Next selectedGraphic ' NOW HERE Dim sortedGraphics = From g In args.FeatureSet.Features Order By CDbl(g.Attributes("DISTANCE")) Ascending imageListBuffer.ItemsSource = sortedGraphics