Custom symbols are off the point locations

594
2
02-07-2012 09:01 AM
GeorgeShi
New Contributor
Long title: Custom symbols for a graphic layer are off the point locations (Well symbols for oil&gas) on the dynamic map service layer.

Hi all,


I have a Dynamic Map Service layer (with symbols generated by ArcGIS server) in my Silverlight Map.  I also created a graphic layer that is a search result against the same layer above.  Based on an ESRI's example (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols),
the graphic layer uses customized symbol (in blue colour) defined in the XAML as following:


<esri:MarkerSymbol x:Key="SelectMarkerSymbol" >
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Ellipse x:Name="Element" Width="8" Height="8" Fill="blue" Stroke="blue" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <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>

However, for the same Well, the symbol on the graphic layer (blue) is shifted a bit from the symbol on the dynamic map service layer. I guess this problem is caused by improper definition of customer symbols.

Could you shed some lights for me?

Thanks in advance.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
When drawing a graphicslayer with points, the marker symbols are created at the position of the points.
By default, if you symbol is not centered, the top-left corner of the symbol will be at the position of the point.
That explains the shift you pointed out.

To center the symbol, the easier way is to apply an offset equal to half the size by using the MarkerSymbol OffsetX and OffsetY properties.

In your case, the symbol size is 8, so this should do the trick:

<esri:MarkerSymbol x:Key="SelectMarkerSymbol" OffsetX="4" OffsetY="4" >
<esri:MarkerSymbol.ControlTemplate>
<ControlTemplate>
<Ellipse x:Name="Element" Width="8" Height="8" Fill="blue" Stroke="blue" HorizontalAlignment="Center" VerticalAlignment="Center">
<......
0 Kudos
GeorgeShi
New Contributor
It works.  Many thanks to Dominique!!



Regards,

George
0 Kudos