Select to view content in your preferred language

Adding text overlay to a polygon graphic

2615
2
07-07-2010 12:57 AM
BjornHrobjartsson
New Contributor
Hi.

We are new to ArcGis development and need to add text and other custom graphics to a polygon
graphic.

Changing the controltemplate is simple for a single point but what is the best way to accomplish this
for a polygon graphic?

Thanks.
Bjorn
0 Kudos
2 Replies
dotMorten_esri
Esri Notable Contributor
The simple answer is: You can't.
The workaround is to create a point graphic on top of the polygon and use a TextMarkerSmbol for it.
0 Kudos
BjornHrobjartsson
New Contributor
The simple answer is: You can't.
The workaround is to create a point graphic on top of the polygon and use a TextMarkerSmbol for it.


Hey.
Thanks for the reply and info.

FYI
Here is our implementation :

In the Xaml (resources section), we created a controltemplate for the TextSymbol
and add a Graphics layer that will hold the custom graphics.

 
<Grid.Resources>
<esriSymbols:TextSymbol x:Name="LegendTextSymbol">
                <esriSymbols:TextSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Border Padding="10,5,10,5" Background="White" BorderBrush="Black">
                            <TextBlock 
                                FontSize="{Binding Symbol.Size}" 
                                Text="{Binding Symbol.Text}" 
                                Foreground="Blue"
                                FontFamily="{Binding Symbol.FontFamily}"
                                HorizontalAlignment="Center" />
                        </Border>
                    </ControlTemplate>
                </esriSymbols:TextSymbol.ControlTemplate>
            </esriSymbols:TextSymbol>
 </Grid.Resources>


...and then in the code behind, we hook up the UpdateCompleted event of the FeatureLayer:

 _featureLayer.UpdateCompleted += (sender, args) =>
                                                        {
                                                            _graphicsLayer.Graphics.Clear();
    
                                                            foreach (var graphic in _featureLayer.Graphics)
                                                            {
                                                                 var textSymbol = new TextSymbol();
                textSymbol.ControlTemplate = LegendTextSymbol.ControlTemplate;
                textSymbol.Text = graphic.Attributes["NAME"] as string;

                var textGraphic = new Graphic()
                                      {
                                          Geometry = new MapPoint(graphic.Geometry.Extent.XMax, 
                                              graphic.Geometry.Extent.YMax),
                                          Symbol = textSymbol
                                      };

                                                                _graphicsLayer.Graphics.Add(textGraphic);
                                                            }
                                                        };


Thanks.

-Bjorn
0 Kudos