Select to view content in your preferred language

Graphics Layers Behavior

613
2
04-28-2010 08:43 AM
LanceCrumbliss
Frequent Contributor
hi all,

ive got two symbols and two graphics layers defined in xaml as such:

<Grid.Resources>
      <esriSymbols:SimpleMarkerSymbol x:Name="DefaultMarkerSymbol" Size="8" Color="#DD00FFFF"/>
      <esriSymbols:SimpleMarkerSymbol x:Name="HighlightMarkerSymbol" Size="10" Color="#DDFF0000"/>
</Grid.Resources>

<esri:Map x:Name="Map">
      <esri:Map.Layers>
            <esri:GraphicsLayer ID="FindLayer" Visible="False" />
            <esri:GraphicsLayer ID="HighlightLayer" Visible="False"/>
      </esri:Map.Layers>
</esri:Map>


The "FindLayer" shows all of the results returned from a Find task and displays the "DefaultMarkerSymbol" for each result returned fine.

         'Called when the FindTask Task is completed and contains valid results
         Private Sub ShowResultsOnMap(ByVal results As List(Of FindResult))
  Dim findLayer As GraphicsLayer = TryCast(Map.Layers("FindLayer"), GraphicsLayer)
  Dim graphicsList As New List(Of Graphic)

  For Each fr As FindResult In results
   graphicsList.Add(fr.Feature)
  Next

  For Each foundFeature As Graphic In graphicsList
   foundFeature.Symbol = DefaultMarkerSymbol 'Defined in XAML
   findLayer.Graphics.Add(foundFeature)
  Next

  findLayer.Visible = True
 End Sub


When selecting a result from the listbox that the attributes are displayed in, the "HighlightLayer" shows the larger, "HighlightMarkerSymbol" on top.  It works fine for the first selection, but for some reason each subsequent selection simply  highlights the selection without removing the previous one.  it's like the "ClearGraphics" method doesn't work....but it does.  the collection is clear, but the symbol seems to persist on the "HighlightLayer" graphics layer.  this will happen for each subsequent selection.

 Private Sub lbFoundFeatures_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)

  Dim highlightLayer As GraphicsLayer = TryCast(Map.Layers("HighlightLayer"), GraphicsLayer)
                highlightLayer.ClearGraphics()

  Try
   Dim selectedListBoxItem As ESRI.ArcGIS.Client.Tasks.FindResult = TryCast(e.AddedItems(0), ESRI.ArcGIS.Client.Tasks.FindResult)
   Dim selectedFeature As Graphic = selectedListBoxItem.Feature
   selectedFeature.Symbol = HighlightMarkerSymbol 'Defined in XAML
   highlightLayer.Visible = True
   highlightLayer.Graphics.Add(selectedFeature)
  Catch ex As Exception
                       'Cathes error when e.AddItems is Nothing
  End Try
 End Sub


Oddly, if i never call the ShowResultsOnMap sub (so that the results are not highlighted in cyan upon the FindTask completion), then the highlighting works fine; when a result is selected in the listbox, the corresponding red dot appears on the map.  selecting a different result removes the previous and shows the newly selected one.

does anyone know what's going on?

lance
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Looks like you affect the same graphic to 2 graphics layers.
By changing the symbology of one graphic, you are changing it for the two layers.

Try to manage only one graphics layer and when the selection changes, reset the symbol of the previous selection to 'DefaultMarkerSymbol'.

/Dominique
0 Kudos
LanceCrumbliss
Frequent Contributor
gah, that never occurred to me.  i just assumed that there was no relationship between the different graphic layers.

thanks,

lance
0 Kudos