Select to view content in your preferred language

Labeling a graphic using the ArcGIS Runtime for WPF

7749
10
01-21-2014 11:10 AM
Labels (1)
JenniferLink
Occasional Contributor
Hello,
I'm looking for a way to label a graphic using the ArcGIS Runtime for WPF. Previously, I accomplished this by creating a graphic that referenced a MarkerSymbol created in XAML. A TextBlock was used within the MarkerSymbol ControlTemplate to bind to an attribute of the graphic. The latest ArcGIS Runtime does not appear to support this. Could someone point out the correct objects I should be using to accomplish this? I need to dynamically set the label text associated with the graphic.
Thanks!
Jen

XAML

<Grid x:Name="LayoutRoot" Margin="0,0,-430.4,0.4">
        <Grid.Resources>
            <esri:MarkerSymbol x:Key="labelSymbol_10_1">
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Grid>
                            <StackPanel Orientation="Horizontal">
                            <Ellipse Width="12" Height="12" Fill="Red" HorizontalAlignment="Left" VerticalAlignment="Top" />
                            <TextBlock Text="{Binding Attributes[NAME]}" FontSize="12" FontStyle="Oblique" FontWeight="Bold"></TextBlock>
                            </StackPanel>
                        </Grid>                        
                    </ControlTemplate>
                </esri:MarkerSymbol.ControlTemplate>
            </esri:MarkerSymbol>
        </Grid.Resources>


C#
 
ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer10_1 = new ESRI.ArcGIS.Client.GraphicsLayer();

                ESRI.ArcGIS.Client.Symbols.MarkerSymbol marker10_1 = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol()
                {Size = 10, Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle, };

                ESRI.ArcGIS.Client.Graphic graphic10_1 = new ESRI.ArcGIS.Client.Graphic()
                {
                    Geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint()
                    {
                        X = -10764928.3045,
                        Y = 4985563.0066,
                    },
                    Selected = false,
                    Symbol = LayoutRoot.Resources["labelSymbol_10_1"] as ESRI.ArcGIS.Client.Symbols.MarkerSymbol,
                };

                graphic10_1.Attributes.Add("NAME", "Here I Am");
                graphicsLayer10_1.Graphics.Add(graphic10_1);
                myMap10_1.Layers.Add(graphicsLayer10_1);
0 Kudos
10 Replies
BKuiper
Frequent Contributor
it might still work, but you need to make sure AcceleratedDisplay is not turned on (for this specific layer). AD doesn't allow for styling of graphics.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Bjorn is correct, but ideally we recommend you try to avoid using ControlTemplates to create custom symbols and stick to the core Esri symbol and renderer types (SimpleMarkerSymbol, PictureMarkerSymbol, etc.) and do exclusively use the "accelerated display" (Map.UseAcceleratedDisplay = True). For simple labelling of graphics you could use the TextSymbol, and if you would like to calculate the correct position use the LabelPointsAsync operation on the GeometryService Task (LocalGeometryService or an online GeometryServer) - for more information see http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli....

We are aware of the requirement for a richer labelling API - and a full labelling engine is on the roadmap, but for the new ArcGIS Runtime SDK for .NET which is scheduled for release later this year.

Cheers

Mike
0 Kudos
JenniferLink
Occasional Contributor
Thanks for the replies. I did some experimenting with the TextSymbol, and the CompositeSymbol and there are quite a few options available. Thanks for the tip!
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Ideally you would avoid using CompositeSymbol - it's not supported in the accelerated display mode.

Cheers
0 Kudos
MiriRevivo
Deactivated User
Hi Mike,

The full labeling engine that you mentioned for the .Net version - will it provide us with the functionality of binding the labels to Graphics' attributes?
Will the position of the displayed labels be controllable through the API?
I assume that it will contain a placement (and collision avoidance) mechanism?

And most importantly - will this engine for graphics layers make it into the summer release?

Thanks,
Miri.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi Miri,

Your timing is impeccable - we are currently testing labelling in the API - and if all goes well we would like to make it available in the summer release. Unfortunately I cannot promise it will make it into the forthcoming beta.

You are correct, the goal is to label Graphics based on Attribute values with the ability to build up more complex labels via simple expressions (field concatenation, strings, numeric rounding, etc) plus label placement options and label formatting (foreground color, background color, font size, font, etc). the label placement options are a guide to the label engine, since it has conflict detection it will ultimately determine the best location for the label.

Cheers

Mike
0 Kudos
SaranPon
Emerging Contributor
Hi,

Did you resolve this problem? I am also looking for a way to Labeling but nothing seems to be working on my end.... If possible can you post some sample code?

Thanks,
Saran
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

We are working on a labeling design which will eventually be rolled out across the ArcGIS Runtime SDKs (excluding WPF) - you can see a preview of this in the new ArcGIS Runtime SDK for .NET beta, although in the beta it is quite a limited API. Therefore we welcome input e.g.:
- Types of layers/objects you would like to label?
- Placement control you need?
- Display properties you would like to set?
- Behavior you would like the labels to exhibit?
- Interaction you expect to be able to have with labels in the map?

You can email on mbranscomb@esri.com if you would prefer to contact me directly.

Cheers

Mike
0 Kudos
VinhLe
by
Deactivated User
Hi Mike,

I am currently trying to use the AdvancedSymbology, MilitaryMessage.  How do I enable the labels on those symbology?
Is it currently possible?  If it doesn't, ideally.
1. You should be able to choose if you can display the UniqueDesignation or ID
2. if it is 2525C complaint, it should be display the varies labels associated with that 2525 symbology?  Does the WPF Runtime SDK support this?

I am currently in learning mode, so any help and guidance would be much appreciated.

Vinh Le
0 Kudos