Select to view content in your preferred language

How to set selection color with custom renderer

1067
5
02-15-2011 05:45 AM
DonFreeman
Emerging Contributor
My featureLayer is drawn with a custom renderer.
 <Grid.Resources>
   <esri:SimpleRenderer x:Key="AMRenderer">
    <esri:SimpleRenderer.Symbol>
     <esriSymbols:SimpleMarkerSymbol x:Name="AllMarkerSymbol" Color="Green" Style="Circle" Size="8" />
    </esri:SimpleRenderer.Symbol>
   </esri:SimpleRenderer>        </Grid.Resources>

     <esri:FeatureLayer ID="AMAvailableLayer" 
      Url="http://gismaps.pagnet.org/ArcGIS/rest/services/testprojectALLBikeCounts/FeatureServer/0"
      MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
      SelectionColor="Yellow"
      OutFields="Location,VolunteerAM,PhoneAM,EmailAM,SpanishAM"
      Where="VolunteerAM = 'Available' and VolunteerPM != 'Available'"    
      Renderer="{StaticResource AMRenderer}"
      DisableClientCaching="True"
      AutoSave="True" 
      EndSaveEdits="FeatureLayer_EndSaveEdits">
      <esri:FeatureLayer.MapTip>
       <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
        <StackPanel Margin="7">
         <StackPanel Orientation="Horizontal">
          <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
          <TextBlock Text="{Binding [Location]}" Foreground="Black" />
         </StackPanel>
        </StackPanel>
       </Border>
      </esri:FeatureLayer.MapTip>
     </esri:FeatureLayer>

Note that the selection color in the layer is set to Yellow. In operation this places a yellow square around the selected point (very hard to see) but does not change the color of the point itself. How can I change my code so that the symbol for the selected point becomes yellow?
Thanks
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
Instead of using SimpleMarkerSymbol in your SimpleRenderer, you can use symbols that define their template as in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics. Notice how the template has VisualStates defined for Selected.
0 Kudos
DonFreeman
Emerging Contributor
Instead of using SimpleMarkerSymbol in your SimpleRenderer, you can use symbols that define their template as in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics. Notice how the template has VisualStates defined for Selected.


This is a FeatureLayer that I am working with. I was previously advised that I had to use the custom renderer to override the default symbol in the service. This seems to be true as setting a symbol like this:
FeatureSymbol="{StaticResource SelectMarkerSymbol}"
has no effect. The code for the resource is taken directly from the sample you referenced.
Thanks
0 Kudos
DonFreeman
Emerging Contributor
Instead of using SimpleMarkerSymbol in your SimpleRenderer, you can use symbols that define their template as in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics. Notice how the template has VisualStates defined for Selected.


Thanks Jenn. The light came on right after I sent the previous post. It works. 🙂
0 Kudos
DonFreeman
Emerging Contributor
Jenn -
Would it also be possible to change the size of the ellipse? Something like
<Storyboard>
           <ColorAnimation Storyboard.TargetName="Element" 
            Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
            To="Yellow" Duration="00:00:0.25"/>
           <PointAnimation Storyboard.TargetName="Element" Storyboard.TargetProperty="(Ellipse.Height)" To="15" Duration="00:00:0.25"/>
          </Storyboard>
0 Kudos
JenniferNery
Esri Regular Contributor
Sure, you can apply ScaleTransform to your symbol as shown in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols
Look for this "Enlarge gradient marker symbol" in XAML. You can use similar code in your Selected state.
0 Kudos