Select to view content in your preferred language

Symbol rotation change by attribute update

1854
8
05-14-2010 01:01 AM
TobiasJohansson
Emerging Contributor
How can I update the rotation of the symbol in the map after the attribute the rotation is bound to is updated?
I've tried using 2 methods for rotating the symbol:
Morten's Surrogate Binder
And plain xaml:
<Grid.RenderTransform>
    <RotateTransform Angle ="{Binding Attributes[ROTATION]}" />
</Grid.RenderTransform>

If I change the symbol after updating the rotation attribute value, the new symbol will have the correct rotation.
Is it possible to do this somehow  without having to change symbol? Could this be because the Attributes-property of Graphic is not registered as a DependencyProperty?
0 Kudos
8 Replies
AnilDhiman
Deactivated User
Today, I implemented surrogate binder and it works fine for me. I don't see any issues with the way it has been achieved. What are your concerns.

You have create one dependency property for Angle,(surrogate.angle), and add one attribute for angle in your graphic layer and it will be up and running. Do let me know, if you need some more help
0 Kudos
dotMorten_esri
Esri Notable Contributor
Auto-updating of bindings to attributes will only work with the v2.0 build. v1.x does not support change detection to attributes.
0 Kudos
TobiasJohansson
Emerging Contributor
I'm able to rotate the symbol based on the value of the angle-attribute on the Graphic.
But when I change the value I don't see any change in rotation of the symbol.
I get the same result using both Surrogate Binder and xaml RotateTransform binding.

I'm using v2.0 (v2.0.50727) of the API. The symbol is applied to a FeatureLayer with Mode=SnapShot and AutoSave=True.
Should I hook up to the Graphic's AttributeValueChanged event or should this be auto-updated?
0 Kudos
dotMorten_esri
Esri Notable Contributor
Just confirming... your binding expression is as shown above right? You are not using the dictionaryconverter ? (it will not work with DictionaryConverter).
Could you share the entire xaml of the symbol template you are using? (preferably simplified if it's really complex)
0 Kudos
TobiasJohansson
Emerging Contributor
My symbol is:
<esriSymbols:MarkerSymbol x:Name="SinglePole" OffsetX="6" OffsetY="6" >
            <esriSymbols:MarkerSymbol.ControlTemplate>
                <ControlTemplate>
                    <Grid RenderTransformOrigin="0.5,0.5" Width="12" Height="12" >
                        <Grid.RenderTransform>
                            <RotateTransform Angle ="{Binding Attributes[ROTATION]}" />
                        </Grid.RenderTransform>
                        <Ellipse Fill="Black" Stroke="Black" Height="6" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top" Width="6"/>
                        <Path Fill="Black" Stretch="Fill" Stroke="Black" Height="1" VerticalAlignment="Bottom" UseLayoutRounding="False" Data="M0,0 L12,0" Margin="0,0.749,0,0"/>
                    </Grid>                
                </ControlTemplate>
            </esriSymbols:MarkerSymbol.ControlTemplate>
        </esriSymbols:MarkerSymbol>

When the features has been loaded into the FeatureLayer and I apply the symbol the rotation works as expected. But when chagning the ROTATION attribute of the Graphic, the symbol rotation is not updated unless i change symbol. I used a TextBox and a NumericUpDown with TwoWay binding to change the value.
0 Kudos
dotMorten_esri
Esri Notable Contributor
From what I can tell, it looks right. Are you absolutely sure the attribute actually gets updated through your bindings?
Also be wary of having AutoUpdate set to true here. Note that everytime you change the attribute, a save is pushed back to the server. It could quickly get quite chatty.
0 Kudos
TobiasJohansson
Emerging Contributor
Morten, thank you for helping me out here!
Turns out turning AutoSave to False did it. Maybe my machine is a bit slow..
As you pointed out, AutoSave might cause some unnecessary traffic and setting this to False might even result in a better user-experience in this case.

Thanks.
0 Kudos
PhilPonce
Emerging Contributor
Morten,
I have a symbol that is placed at the correct angle using:

                Symbol symb = LayoutRoot.Resources["rotateSymbol"] as Symbol;
                Graphic g = new Graphic()
                {
                    Geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(location[0], location[1]),
                    Symbol = symb
                };
                g.Attributes.Add("Heading", location[2]-90);
                g.SetZIndex(10);
                symbolGraphic = g;
                videoLayer.Graphics.Add(symbolGraphic);

As I move the symbol along a line I want to change the rotation using:


  symbolGraphic.Attributes["Heading"] = location[2]-90;
  symbolGraphic.Geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(location[0], location[1]);

The point moves smoothly across the screen, but does not honor the rotation.  Can you direct me on what I'm missing?

Thanks

Symbol Definition:

<esriSymbols:MarkerSymbol OffsetX="10" OffsetY="10" x:Key="rotateSymbol">
                <esriSymbols:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Grid RenderTransformOrigin=".5,.5" local:SurrogateBinder.Angle="{Binding Path=Attributes, Converter={StaticResource dictConverter}, ConverterParameter=Heading}">
                            <Grid.RenderTransform>
                                <RotateTransform />
                            </Grid.RenderTransform>

                            <Ellipse Width="20" Height="20" Fill="Yellow" Stroke="Black" StrokeThickness="2" />
                            <TextBlock Text="-&gt;" FontWeight="Bold" FontSize="10" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </esriSymbols:MarkerSymbol.ControlTemplate>
            </esriSymbols:MarkerSymbol>
0 Kudos