Select to view content in your preferred language

MarkerSymbol is not located at correct place

863
4
08-18-2010 02:46 AM
VivekTyagi
Emerging Contributor
I am creating esriSymbols:MarkerSymbol to present graphics in my layer. One symbol has 2 co-centric Ellipses in its control template.
The problem is that I always get this symbols places at wrong co-ordinates. In fact this seems somewhat offset from the actual coordinate location.
I am not setting any offset value to the symbol. Also, bigger the size of the symbol implies more the offset (symbol size is defined dynamically).

However other symbols which are not of this type (Ex- SimpleMarkerSymbol), are displayed at the correct location with the same logic.

Please help.
Thanks
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
Custom symbols requires an offset set. Default tie point is upper left corner, and offsets are relative to this corner.
0 Kudos
VivekTyagi
Emerging Contributor
Thanks Morten,

My problem is a bit complicated.
Even if offset is used correctly, it does not position the symbol at correct location. This happens only in the case when symbol size (and so the offset) is decided at runtime.
If fixed size symbols and accordingly fixed offset is used, then things work alright.

Code and the symbol definition are mentioned for reference -

Symbol Resource in XAML -
<esriSymbols:MarkerSymbol x:Name="DefaultFLRateSymbol">
                <esriSymbols:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Grid Name="flGrd">
                            <Ellipse Height="{Binding Path=Attributes, Converter={StaticResource MyDictionaryConverter}, ConverterParameter=SYMBOL_SIZE, Mode=OneWay}"
                                     Width="{Binding Path=Attributes, Converter={StaticResource MyDictionaryConverter}, ConverterParameter=SYMBOL_SIZE, Mode=OneWay}"
                                     StrokeThickness="2" Fill="#5500FF00" Stroke="Red" HorizontalAlignment="Center" VerticalAlignment="Center" />
                            <Ellipse Name="innerRadius" Width="5" Height="5" Fill="Black"  HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </esriSymbols:MarkerSymbol.ControlTemplate>
            </esriSymbols:MarkerSymbol>


Code Behind -
//FL layer
                        Graphic graphicFL = new Graphic()
                        {
                            Geometry = graphic.Geometry,
                        };
                        //where 'ind' is static  double with initial value 0.0
                        double d = 12.45 + ind;
                        ind = ind + 1.20;
                        graphicFl.Attributes["SYMBOL_SIZE"] = d;
                        MarkerSymbol ms = DefaultFLRateSymbol as MarkerSymbol;
                        ms.OffsetX = d / 2;
                        ms.OffsetY = d / 2;

                        graphicFl.Symbol = DefaultFLRateSymbol;
                        grLyrFlowRate.Graphics.Add(graphicFl);

If I keep the 'd' as a fixed value then symbols are located at correct location.
In my case symbol size represent some field attribute so need to be dynamic.

Your help is highly appreciated.
0 Kudos
dotMorten_esri
Esri Notable Contributor
If you change values on the fly after the graphic has rendered, you must raise PropertyChanged for the properties you modified that affect rendering.
Also if you require different offsets for all your graphics, make sure you use different symbol instances for each.
Or create a template that expands its size around (0,0), so you don't have to muck around with offsets in the first place.
0 Kudos
VivekTyagi
Emerging Contributor
Thanks Morten  !
It works 🙂
0 Kudos