Select to view content in your preferred language

Display Annotations in feature Layer

1210
6
07-26-2010 01:20 AM
xariaD
by
Occasional Contributor
How to display the labels for features of feature layer?
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
You might use a custom symbol with a text which binds to an attribute.
This should be easy for points.

More difficult for polylines or polygones because you will have to find the label placement within.
0 Kudos
BrooksShannon
Deactivated User
Dominique,

I'm trying to label points in a feature layer using a custom symbol (a MarkerSymbol with a custom ControlTemplate), and I think you're suggestion, above, is along the lines of what I'm attempting to do.

My question relates specifically to data binding: what I'd really like to do is use a binding statement within the XAML of my ControlTemplate to bind to one of my graphics' attributes - such that the label for each feature reflects each feature individually.

Here's the XAML I'm using, from the Renderer down to the ControlTemplate:

<esri:SimpleRenderer x:Key="AddressPointRenderer_Display">
    <esri:SimpleRenderer.Symbol>
        <esriSymbols:MarkerSymbol>
            <esriSymbols:MarkerSymbol.ControlTemplate>
                <ControlTemplate>                                        
                    <StackPanel Orientation="Vertical">                                        
                        <Ellipse x:Name="Element" Width="5" Height="5" StrokeThickness="10" 
                                    Stroke="Blue">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected" />
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element" 
                                                Storyboard.TargetProperty="(Ellipse.Stroke).(SolidColorBrush.Color)"
                                                To="Cyan" Duration="00:00:0.25"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Ellipse>
                        <TextBlock Foreground="DarkGreen" FontWeight="ExtraBold" Margin="0,10,0,0" Text="{Binding [MY_ATTRIBUTE]}" />
                    </StackPanel>
                </ControlTemplate>
            </esriSymbols:MarkerSymbol.ControlTemplate>
        </esriSymbols:MarkerSymbol>
    </esri:SimpleRenderer.Symbol>
</esri:SimpleRenderer>


The intent is that TextBlock's Text value should be whatever the "MY_ATTRIBUTE" value is, for each individual feature being rendered.

Is it possible to do this, like I'm attempting to do it?  The binding fails, so I assume the DataContext is either different than what I expect it to be, or it's nonexistent (aka, I just can't do it this way).

Thanks!
Brooks
0 Kudos
BrooksShannon
Deactivated User
Dominique,

I figured it out.  My binding statement was Text="{Binding [DLVRY_ADD]}", but it  should be Text="{Binding Attributes[DLVRY_ADD]}" instead.

Have a good one,
Brooks
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Hi Brooks:

Can you share  full code?. I want display label for dynamic service layer as well?. Please help

SR
0 Kudos
MattMiley
Deactivated User
I second this, it is ridiculous that its this hard to add a label.
0 Kudos
BrooksShannon
Deactivated User
Guys,

What I posted above (which, mind you, just labels points) is essentially the full code.  Bear in mind that my renderer XAML code, as originally pasted, had a binding expression error that I described the resolution for, in the subsequent post.

The only magic, then, to using this is to make the renderer a resource of your layer's parent - in my case a Grid, so the renderer's XAML code is a part within the Grid's <Grid.Resources> collection.

Then, in your feature layer, add an attribute to its declaration:

Renderer="{StaticResource AddressPointRenderer_Display}"


Which tells the layer that it must use your custom renderer.

Now, I can't say what tricks you'll need to do to perform special labeling in dynamic map service layers other than setting up labeling in your map service definition (via MXD or MSD)... or if you can do anything but that.  This technique is really only applicable to Feature Layers (and by extension, general GraphicsLayers) as they are rendered client-side, giving you control of how the labeling occurs.

Let me know if you have any other questions.

Thanks!
Brooks
0 Kudos