Select to view content in your preferred language

UniqueValueRenderer change polygon fill color dynamically

4252
29
07-15-2010 08:16 PM
xariaD
by
Occasional Contributor
How to change the fill color of a particular polygon at runtime?
0 Kudos
29 Replies
xariaD
by
Occasional Contributor
Did you set the OutFields property on the FeatureLayer?


Yeah I missed that.
0 Kudos
xariaD
by
Occasional Contributor
But I still don't understand how to dynamically apply the renderer.
The status of all graphic when the map is loaded is 0.
The status changes after the application starts.
So when I set the graphic.Attributes["status"] to newstatus value, it is not rendered.
How to refresh renderer or apply new renderer?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
It should be automatic when you change the value of an attribute which is used in the renderer.

How looks your renderer which is using the attribute 'status'?
0 Kudos
xariaD
by
Occasional Contributor
 <esriSymbols:SimpleFillSymbol x:Key="MyYellowFillSymbol" Fill="YellowGreen" BorderBrush="Transparent" BorderThickness="2" />
            <esriSymbols:SimpleFillSymbol x:Key="MyRedFillSymbol" Fill="Red" BorderBrush="Transparent" BorderThickness="2" />
            <esri:UniqueValueRenderer x:Key="MyUniqueValueRenderer" Attribute="Status" >
                <esri:UniqueValueRenderer.Infos>
                    <esri:UniqueValueInfo Value="Off" Symbol="{StaticResource MyRedFillSymbol}" />
                    <esri:UniqueValueInfo Value="On" Symbol="{StaticResource MyYellowFillSymbol}"/>                    
                </esri:UniqueValueRenderer.Infos>
            </esri:UniqueValueRenderer>


And the feature layer is
<esri:FeatureLayer ID="towers" Url="http://MyMapURL/MapServer/0"
       Where="1=1" Renderer="{StaticResource MyUniqueValueRenderer}"
        MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown">
 <esri:FeatureLayer.OutFields>
         <sys:String>RefName</sys:String>
         <sys:String>Status</sys:String>
         <sys:String>Text</sys:String>
 </esri:FeatureLayer.OutFields>
</esri:FeatureLayer>
0 Kudos
DominiqueBroux
Esri Frequent Contributor
So when I set the graphic.Attributes["status"] to newstatus value, it is not rendered.

<esri:UniqueValueRenderer x:Key="MyUniqueValueRenderer" Attribute="Status" >


Looks like you are using status in code and Status in XAML.
Attribute names are case sensitive.
0 Kudos
xariaD
by
Occasional Contributor
NOoooooooooooooooooooooooooo

I know it is case-sensitive, and I am using "Status" in code behind.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Might be that the status is initialized with coded values such as 0 and 1   and your renderer is using strings "On"/"Off".
0 Kudos
xariaD
by
Occasional Contributor
No, that is not the case either.
The status is defined as String "On"/"Off" and I am assigning the same in code behind.
😞
0 Kudos
xariaD
by
Occasional Contributor
 private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
        {
            Graphic feature = e.Graphic;          
            feature.Attributes["Status"] = "On";
        }


This is what I have in code behind.
What to do??
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I tested with your code and I didn't get any problem.
So I don't understand:confused:

I guess you have verified that your event handler 'FeatureLayer_MouseLeftButtonDown' is executed?

Which ArcGIS SL API version are you using?
0 Kudos