Select to view content in your preferred language

Change behavior of selected graphics out of a selected set

1053
5
09-13-2012 11:00 AM
MiriEshel
Esri Contributor
Hi,

I want to change the symbol of the selected graphic out of other graphics. Now all the selected graphics are cyan circles ( <VisualState x:Name="Unselected"/>) and the chosen ones out of the selected set are yellow circles (<VisualState x:Name="Selected">)
:

<esri:SimpleRenderer x:Name="SimplePointRender">
<esri:SimpleRenderer.Symbol>
<esri:MarkerSymbol OffsetX="5" OffsetY="5">
<esri:MarkerSymbol.ControlTemplate>
<ControlTemplate>
<Ellipse x:Name="Element" Width="10" Height="10" Fill="Cyan" >

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
To="Yellow" Duration="00:00:0.25"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Ellipse>

</ControlTemplate>
</esri:MarkerSymbol.ControlTemplate>
</esri:MarkerSymbol>
</esri:SimpleRenderer.Symbol>
</esri:SimpleRenderer>


I want to change the symbol of the schosen ones. Instead of yellow circles, I want to show a PIN symbol, something like:

<Path Fill="Red" Data="F1 M 7.44917,7.18082C 7.43555,7.44724 6.95625,7.59891 6.01125,7.63583L 5.69333,7.65335C 5.53194,7.65335 5.38271,7.65335 5.24563,7.65335C 5.10854,7.65335 4.97778,7.65335 4.85333,7.65335C 4.72889,7.65335 4.62,7.65674 4.52667,7.66354C 4.43333,7.67038 4.34972,7.6796 4.27583,7.69125L 3.69542,11.76L 3.17333,7.7496C 3.04889,7.71069 2.91812,7.68494 2.78104,7.67227C 2.64396,7.65967 2.50736,7.65335 2.37125,7.65335L 2.03583,7.65335C 1.53806,7.65335 1.11806,7.63583 0.775833,7.60083C 0.433611,7.56583 0.175,7.43265 9.93411e-009,7.20126L 0.0554167,7.11377C 0.154583,6.96402 0.260556,6.80215 0.373333,6.62814C 0.486111,6.4541 0.573611,6.29807 0.635833,6.16L 1.08208,6.23584C 1.20653,6.23584 1.31542,6.18579 1.40875,6.08566C 1.50208,5.9855 1.57694,5.86398 1.63333,5.72107C 1.68972,5.57813 1.73347,5.42892 1.76458,5.27335C 1.79569,5.1178 1.81125,4.97778 1.81125,4.85336C 1.81125,4.14365 1.74903,3.5491 1.62458,3.06979C 1.50014,2.59048 1.38153,2.18362 1.26875,1.84915C 1.24347,1.76169 1.21528,1.70871 1.08208,1.66251L 0.522083,1.73544C 0.496806,1.69849 0.459375,1.6489 0.409792,1.58667C 0.360209,1.52444 0.307708,1.44958 0.252292,1.36209C 0.196875,1.27457 0.143889,1.18759 0.0933332,1.10104C 0.0427777,1.01453 0.0116666,0.93335 9.93411e-009,0.857513C 0.186667,0.709717 0.438472,0.579468 0.755417,0.466675C 1.07236,0.353882 1.40535,0.263458 1.75437,0.195435C 2.1034,0.12735 2.44903,0.0777893 2.79125,0.0466614C 3.13347,0.0155945 3.43486,0 3.69542,0C 3.78292,0 3.93556,0.00634766 4.15333,0.0189514C 4.37111,0.0316162 4.62,0.0529785 4.9,0.0831299C 5.18,0.113281 5.46632,0.150238 5.75896,0.19397C 6.0516,0.237701 6.32236,0.290192 6.57125,0.351471C 6.82014,0.41272 7.02528,0.483185 7.18667,0.562897C 7.34805,0.64267 7.42875,0.732086 7.42875,0.831268L 7.42875,0.848755C 7.42875,0.909027 7.40104,0.985352 7.34562,1.07773C 7.29021,1.17007 7.23139,1.26245 7.16917,1.35483C 7.10694,1.44714 7.04472,1.52737 6.9825,1.59543L 6.86875,1.715L 6.30875,1.64209C 6.22125,1.64209 6.16826,1.6698 6.14979,1.72522L 6.12208,1.82584C 6.03458,2.12143 5.9568,2.39218 5.88875,2.63815C 5.82069,2.88412 5.76187,3.12378 5.71229,3.35709C 5.66271,3.59042 5.62528,3.82376 5.6,4.0571C 5.57472,4.29044 5.56208,4.53641 5.56208,4.79501C 5.56208,5.20142 5.63354,5.53049 5.77646,5.78232C 5.91937,6.03409 6.09681,6.16 6.30875,6.16C 6.55764,6.16 6.72583,6.13474 6.81333,6.0842C 6.87556,6.22031 6.96257,6.37634 7.07437,6.55228C 7.18618,6.72827 7.31111,6.93777 7.44917,7.18082 Z " />


Is it possible and how?

I attach an image to clarify it more.

Thanks a lot and SHANA TOVA!!!!

Miri
0 Kudos
5 Replies
DanielWalton
Frequent Contributor
It would probably be easiest to create a Renderer to handle this. 3 steps:

  1. define the normal symbol

  2. define the selected symbol

  3. set the graphicslayer.renderer to a custom render that looks like this:

public class CustomRenderer : IRenderer
{
    public Symbol GetSymbol(Graphic g)
    {
        return g.Selected ? new SpecialSymbol() : new NormalSymbol();        
    }
}
0 Kudos
MiriEshel
Esri Contributor
Hi Dan,

Thank you for your reply. I apologize for the delay, we had holidays for the Jewish New Year.

Anyway, I tried your suggestion, defined a new customRenderer and assign it to the graphic's symbol but for some reason, it doesn't show the selected symbol. I guess I do something wrong, I just don't know what....
Enclosed with the file where I did it. Maybe you can take a look and see what I'm doing wrong.

Thanks a lot,

Happy New Year,
Miri

P.S. I'm using a FeatureDataGrid. Upon clicking on a row in this FeatureDataGrid. I expect to see the specialSymbol.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Your custom renderer looks good but it seems the symbols are not always updated when the selection changes.

The workaround may be to wire up an handler to FeatureLayer.PropertyChanged event and to refresh the layer in that handler:

private void FeatureLayer_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "SelectedGraphics")
        ((GraphicsLayer) sender).Refresh();
}


And you no more need to send an event whe the symbol changes:
set{
    _sym = value;
    //NotifyPropertyChanged("sym");
}
0 Kudos
MiriEshel
Esri Contributor
Hi Dominique,

How are you?

Thank you for your reply and sorry for the delay. We still have Holidays...

Your suggestion was good and solved the problem (I should have think about firing this event but I didn't....).

I define the CustomRenderer in the code. The red ane cyan circles were only for proof of concept. Now I want the specialSymbol to look like a Red Pin. How can I assign the long Path (for the Pin shape) to this customRenderer? Will it be faster if I'll attach an image and use a PictureMarkerSymbol instead?

Thanks a lot,
Miri
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Now I want the specialSymbol to look like a Red Pin.

Hi Miri,

You can either create a marker symbol containing one or more paths in order to get a vector representation of your symbol or create a picture marker symbol from an image.
0 Kudos