highlight geometry on mouse over

3912
12
09-07-2010 10:04 AM
AgatinoLa_Rosa
New Contributor
I am looking for a sample code triggering a color change in a polygon feature of a silverlight map control when passing it over with the mouse. Thanks.
0 Kudos
12 Replies
JenniferNery
Esri Regular Contributor
You can use MouseEnter, MouseLeave events on your GraphicsLayer and mark the e.Graphic.Selected to true/false to select/unselect feature as you hover.

If you do not want to affect the feature's selected property, you can add another GraphicsLayer that will always have one feature. In your MouseEnter, MouseLeave event handlers, instead of setting e.Graphic's selected property, you can simply add e.Graphic to the GraphicsLayer you just created. Be sure that this GraphicsLayer provide a different symbol for the graphic so that it can be identified on hover. You may use a renderer or set symbol on the new graphic instance.
0 Kudos
dotMorten_esri
Esri Notable Contributor
Use the MouseOver state of the graphic.
See: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols
3 of the marker symbols has a hover state defined. This is basically just a storyboard you want to trigger when the user hovers over a graphic.
0 Kudos
AgatinoLa_Rosa
New Contributor
I have followed your instructions, however when I set the event such as MouseEnter to the graphiclayer I get the following message.

No overload for 'GraphicsLayer_MouseEnter' matches delegate 'MouseEventHandler

I have also tried to add the handler at the Initialize event

((GraphicsLayer)sender).MouseEnter += new GraphicsLayer.MouseEventHandler(GraphicsLayer_MouseEnter);

but no luck. Any suggestion?
0 Kudos
JenniferNery
Esri Regular Contributor
The better solution would be to define visual states as Morten had suggested.

The MouseEnter, MouseLeave events are on the Map.
0 Kudos
AgatinoLa_Rosa
New Contributor
Thanks, it has been helpful the following link: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols.

However it takes into consideration only MarkerSymbol. Is there any other example using Fill symbols? I would like also to change fill symbol when hovering a polygon. Thanks.
0 Kudos
JMcNeil
Occasional Contributor III
0 Kudos
AgatinoLa_Rosa
New Contributor
I have seen that example several times checking on query procedures and never focused on the fill symbol I am looking for. Thank you.
0 Kudos
AgatinoLa_Rosa
New Contributor
I am not able to see any symbol for the states - normal, mouseover, selection - defined in the xaml. I am still trying to understand how it works. Following used codes, hopefully I get help.

XAML Code:

       <Grid x:Name="MapLayout" Width="750" Height="600" Margin="0,75,0,0">
            <Grid.Resources>
                <esri:FillSymbol x:Key="ResultsFillSymbol">
                    <esri:FillSymbol.ControlTemplate>
                         <ControlTemplate x:Name="CustomMemberTemplate" >
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="#880000FF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="Brown" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="Orange" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                    </esri:FillSymbol.ControlTemplate>
                </esri:FillSymbol>
            </Grid.Resources>                  

The cs looks like:

                foreach (Graphic resultingFeature in args.FeatureSet.Features)
                {                   
                    myGraphicsLayer.Graphics.Add(resultingFeature);
                    resultingFeature.Symbol = (FillSymbol)MapLayout.Resources["ResultsFillSymbol"];
                }
0 Kudos
DavidAshton
Occasional Contributor III
I am not able to see any symbol for the states - normal, mouseover, selection - defined in the xaml. I am still trying to understand how it works. Following used codes, hopefully I get help.

XAML Code:

       <Grid x:Name="MapLayout" Width="750" Height="600" Margin="0,75,0,0">
            <Grid.Resources>
                <esri:FillSymbol x:Key="ResultsFillSymbol">
                    <esri:FillSymbol.ControlTemplate>
                         <ControlTemplate x:Name="CustomMemberTemplate" >
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="#880000FF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="Brown" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Member"
                                                        Storyboard.TargetProperty="(Fill).(Color)"
                                                            To="Orange" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                    </esri:FillSymbol.ControlTemplate>
                </esri:FillSymbol>
            </Grid.Resources>                  

The cs looks like:

                foreach (Graphic resultingFeature in args.FeatureSet.Features)
                {                   
                    myGraphicsLayer.Graphics.Add(resultingFeature);
                    resultingFeature.Symbol = (FillSymbol)MapLayout.Resources["ResultsFillSymbol"];
                }







Alarosa,

We might be dealing with a similar problem.  I'm trying to make spatial query work for a point layer and I can't get the markersymbol to show up at all.  Maybe if I help you Karma will strike today and I will figure out my problem by solving yours and/or someone like you will help me.  Here's my post if you want to check it out and return the favor if I help.

http://forums.arcgis.com/threads/14622-Super-Easy-Point-Graphic

In the mean time here's what I think I know. 

In your code behind C# you have this which is working with your xaml storyboard
The FillSymbol is being passed

  GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                foreach (Graphic feature in featureSet.Features)
                {
                    feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                    graphicsLayer.Graphics.Insert(0, feature);
                }
            }


And then here's your Story for you Fill mouse over and out
 <esri:FillSymbol x:Key="ResultsFillSymbol">
                <esri:FillSymbol.ControlTemplate>
                    <ControlTemplate x:Name="CustomPolygonTemplate">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#FFF5FF45" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Path x:Name="Element" Stroke="Blue" Fill="#880000FF"
                                StrokeStartLineCap="Round" StrokeThickness="2" 
                                StrokeLineJoin="Round" StrokeEndLineCap="Round" />
                        </Grid>
                    </ControlTemplate>
                </esri:FillSymbol.ControlTemplate>
            </esri:FillSymbol>






In your xaml you should also have

Default fill or initail, which should look like this mine is yellow


            <esri:FillSymbol x:Key="DefaultFillSymbol" >
                <esri:FillSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Path x:Name="Element" IsHitTestVisible="False" Fill="#66FF0000" 
                            Stroke="Red" StrokeThickness="1"/>
                    </ControlTemplate>
                </esri:FillSymbol.ControlTemplate>
            </esri:FillSymbol>





You also need this in your xaml to, in your map declar area   ---- Actually I don't think you need this so don't add this...
 <esri:GraphicsLayer ID="MySelectionGraphicsLayer" 
                                    MouseEnter="GraphicsLayer_MouseEnter" 

                                    MouseLeave="GraphicsLayer_MouseLeave" />



Oh one more thing in your code behind, under your Public MainPage you need initialize your DefaultFillSymbol

 _drawSurface = new Draw(Map)
            {
                
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as FillSymbol
            };






Sorry for all the bad/hack language I barely read code and really haven't mastered the correct terms.

David.
0 Kudos