Select to view content in your preferred language

Changing FeatureLayer SelectionColor has no effect

1559
10
03-14-2011 06:48 AM
MarkusHjärne
Deactivated User
Hi,

I have a FeatureLayer pointing to a feature service with an unique value renderer. When trying to change the SelectionColor after the layer has been initailized, the value gets set, but the selection color in the map isn't changed. Shouldn't that be possible? I'm using version 2.0 of the API.

Regards,

Markus Hjarne
0 Kudos
10 Replies
JenniferNery
Esri Regular Contributor
I tried the following code and was not able to replicate the issue:
This feature service also defines its own UniqueValueRenderer. I am using Editor.Select for to select the features.
<Grid x:Name="LayoutRoot" Background="White">
 <Grid.Resources>
  <esri:Editor x:Key="MyEditor" 
    Map="{Binding ElementName=MyMap}" 
    GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer" 
    SelectionMode="Rectangle"/>
 </Grid.Resources>
 <esri:Map x:Name="MyMap" Background="White">
  <esri:ArcGISTiledMapServiceLayer  Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  <esri:FeatureLayer ID="MyLayer" SelectionColor="Yellow" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0"/>
 </esri:Map>
 <Button Content="Select" Command="{Binding Select}" CommandParameter="new" 
 DataContext="{StaticResource MyEditor}" VerticalAlignment="Top" HorizontalAlignment="Center"/>
</Grid>
0 Kudos
MarkusHjärne
Deactivated User
Setting the selection color initially works for me too, but if I add a button to your example:

<Button Content="Change Selection Color" VerticalAlignment="Top" Click="Button_Click" />


with the following code-behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
 FeatureLayer layer = MyMap.Layers["MyLayer"] as FeatureLayer;
 var brush = new SolidColorBrush(Colors.Magenta);
 layer.SelectionColor = brush;
}


clicking the button will not change the selection color of a currently or subsequently selected feature as I expected it should. Am I missing something?
0 Kudos
JenniferNery
Esri Regular Contributor
Oh I see, symbols defined by the service does not update their selection color.

Thank you for reporting this. We'll try to get it fixed in future release.
0 Kudos
MarkusHjärne
Deactivated User
Thanks. Can you think of any workaround for doing this in the meantime?

What I actually want to do is set the selection color to Transparent to kind of hide the selection in the map temporarily. I cannot just save the selection somewhere else and deselect everything, because I also has a FeatureDataGrid where I still want the selection to be visible.
0 Kudos
JenniferNery
Esri Regular Contributor
If you want SelectionColor to be ignored, you can define your own renderer so that it will not use the renderer defined by the service.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
0 Kudos
MarkusHjärne
Deactivated User
Thanks for the tip.

Since the picture marker symbols in the feature service's unique value renderer might be changed in the future, I want to base my own renderer on the symbol images from the feature service's symbols. But since the picture marker symbol class of the feature service's renderer is internal, I don't know how to get to those images. Any ideas?
0 Kudos
JenniferNery
Esri Regular Contributor
You are right, FeatureService.Symbols are internal and you will not have access to the image URL or image data.

You can parse the json by appending "?f=json" to the layer URL ("?f=pjson" for pretty json).
For example: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0?f=pjson

If image URL is provided, you can append "/images/[image URL]" tothe layer URL to get the image. For example:
http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0/images/4A138C60
If image data is provided, you can Convert this Base64String to byte[], set BitmapImage Source to MemoryStream of this byte[], set Image.Source to this BitmapImage.

This is best described in REST documentation for Picture Marker Symbols: http://help.arcgis.com/en/arcgisserver/10.0/apis/rest/symbol.html#pms

This link provides example on how you can read/parse JSON: http://forums.silverlight.net/forums/p/169016/380845.aspx
0 Kudos
MarkusHjärne
Deactivated User
Thanks, but no thanks. 🙂

If only ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol had inherited from ESRI.ArcGIS.Client.Symbols.PictureMarkerSymbol, it had been so much easier (the same holds for most of the other feature service symbols). Do you have any plans to change this in a future release (it should be a non-breaking change)?

But, at least now I know how to do it if it gets absolutely necessary.
0 Kudos
JenniferNery
Esri Regular Contributor
I checked with our dev lead and Morten said an alternative solution that will allow you to set SelectionColor on the fly is to recreate the layer (it should be fast because the requests will be cached by the browser).

This way you don't have to change the renderer defined by your service.
0 Kudos