Show subtype layer in popup, rather than integer code

2339
3
06-01-2012 09:56 AM
KarenEllett
Occasional Contributor
I've added a layer in the map that has a subtype field.  Unfortunately it only shows the integer code in the popup, and not the actual value.  There's no domain, only this subtype.  I've pretty much exhausted all of my ideas; anyone have any suggestions?
Thanks!
0 Kudos
3 Replies
ChristopherHill
Occasional Contributor
Hello i can help you with this issue.

are you building the data template for the popup or is the datatemplate provided through creation of a WebMap item?

if you are building the datatemplate yourself you will need to make a converter for you binding to do the lookup. SubType is a little more tricky than a standard coded value domain because you need to know the TypeIDField value in addition to the SubType value in order to map to the display vaue you need to show the user. SubType requires two fields be accessible to your binding converter. You need the TypeIDField and the SubType Field. If you navigate the REST endpoint of your service you will see that there is a Type ID Field and Types Section. You need to lookup your SubType value based on your TypeIDField value and your SubType Value.

You can find the domain information for your SubType in FeatureLayer.LayerInfo.FeatureTypes

Your custom converter will need 1) string property to hold the name of the TypeIDField which will never change 2) a string property that will hold the name of the SubTypeField name. 3) the FetureType object so it can lookup domain info on the fly. You will not bind directly to the SubType attribute you will need to the attirbutes dictionary so your converter will be able to get access to the TypeID value and the SubType value based on the two string properties you created on the converter. You will use the FeatureType info to lookup the domain info to replace the value with the display value inside. I have implemented this logic in FeatureDataGrid, FeatureDataForm and in WebMap popup data templates. If you are just using a feature layer and the info window control then you will need to create this same converter logic so the correct display value can be located.

Hope this helps,
0 Kudos
KarenEllett
Occasional Contributor
Chris,

I'm actually attempting to customize an application created with the Silverlight Viewer, so the popup template is one that is already created.  I've made some changes to it previously, so I'm fairly familiar with it; (very new to Silverlight) I've included the code for that template below.  Do you think you can give me a few lines of code as an example, to get me started? 

When you refer to a TypeIDField, do you mean the one that is the same for the entire layer?  My TypeIDField is "SubtypeCD".  Or do you mean the "ID" field that is different for each subtype? 
Here's an example of what is shown at my endpoint:

Type ID Field: SubtypeCD

Types:
 
ID: 9
Name: Loopfeed
Domains:

Field Name: ENABLED
Inherited

ID: 3
Name: Vault
Domains:

Field Name: ENABLED
Inherited


I don't care about any of the inherited values; only about the names. (Loopfeed, etc.)
Below is my code for the popup template.  (There were about 900 lines of code, so I've cut some out to make it a bit more concise.)

<Style x:Key="OnClickPopupContainerStyle" TargetType="Control">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Control">
                    <Grid x:Name="LayoutRoot" Height="300" Background="{TemplateBinding Background}" Width="300"
                          FlowDirection="{Binding Source={StaticResource RTLHelper}, Path=FlowDirection}">
                        <Grid.Resources>
                            <LinearGradientBrush x:Name="OpacityGradient" StartPoint="0,0.5" EndPoint="1,0.5">
                                <GradientStop Color="White" Offset="0" />
                                <GradientStop Color="#22FFFFFF" Offset="1" />
                            </LinearGradientBrush>
                            <extensibility:HasAttachmentsConverter x:Key="HasAttachmentsConverter" />
                            <Style x:Key="CloseButtonStyle" TargetType="Button">
                                .......
                            </Style>
.......
<extensibility:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
                            <extensibility:NotNullVisibilityConverter x:Key="NotNullVisibilityConverter" />
                        </Grid.Resources>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="1"/>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" MaxHeight="30" />
                        </Grid.RowDefinitions>
                        <Grid Margin="3,3,3,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" ></ColumnDefinition>
                                <ColumnDefinition Width="70"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding PopupItem.LayerName}" Grid.Row="0"
                                      Foreground="{TemplateBinding Foreground}"
                                      FontSize="13" FontWeight="Bold"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                TextTrimming="WordEllipsis">
                                <i:Interaction.Triggers>
                                    .......
                                </i:Interaction.Triggers>
                            </TextBlock>
                            <StackPanel Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0">
                                <StackPanel x:Name="PagerStack" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0" Visibility="Collapsed" >
                                    <Button >
                                        <Button.RenderTransform>
                                            <RotateTransform Angle="90" />
                                        </Button.RenderTransform>
                                    </Button>
                                    <Button Style="{StaticResource ArrowButtonStyle}" Command="{Binding Next}"
                                        Foreground="{TemplateBinding Foreground}" Cursor="Hand" RenderTransformOrigin="0.5,0.5"
                                        Margin="0" Width="20" Height="20">
                                        <Button.RenderTransform>
                                            <RotateTransform Angle="270" />
                                        </Button.RenderTransform>
                                    </Button>
                                </StackPanel>
                                <Button Style="{StaticResource CloseButtonStyle}" Foreground="{TemplateBinding Foreground}" Cursor="Hand" Margin="10,0,0,0">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <ei:ChangePropertyAction TargetObject="{Binding Container}" PropertyName="IsOpen" Value="false" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>
                            </StackPanel>
                        </Grid>
                        <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="12,0,0,2">
                            <TextBlock Text="{Binding SelectionDescription}" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="{TemplateBinding Foreground}" Visibility="{Binding Path=Visibility, ElementName=PagerStack}" />
                            <ContentControl Margin="5,0,0,0"
                                Template="{StaticResource ActivityIndicatorTemplate}"
                                HorizontalAlignment="Right" Visibility="{Binding InProgress,
                                Converter={StaticResource BooleanToVisibilityConverter}}" />
                        </StackPanel>
                        <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="2" Margin="0" OpacityMask="{StaticResource OpacityGradient}"
                               Fill="{TemplateBinding Foreground}" />
                        <ScrollViewer x:Name="AttributeContainer" HorizontalScrollBarVisibility="Disabled"  VerticalScrollBarVisibility="Auto" 
                            MinHeight="150" MaxHeight="300" MaxWidth="300" Grid.Row="3" BorderThickness="0"
                            Padding="0" BorderBrush="{TemplateBinding BorderBrush}" Foreground="{TemplateBinding Foreground}" Margin="5">
                            <Grid>
                                <ContentControl ContentTemplate="{Binding PopupItem.DataTemplate}"  Content="{Binding}"
                                    HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Top"
                                    Foreground="{TemplateBinding Foreground}" Background="{TemplateBinding Background}"
                                    Visibility="{Binding PopupItem.DataTemplate, Converter={StaticResource NotNullVisibilityConverter}}" >
                                </ContentControl>
                            </Grid>
                        </ScrollViewer>
...
<ContentControl x:Name="PopupToolbarContainer"
                                        DataContext="{Binding }"
                                        Grid.Row="5"
                                        Margin="2"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Right" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



Thanks for the guidance thus far!
0 Kudos
KarenEllett
Occasional Contributor
Can anyone give me a bit of help on how to create the custom converter?
Thanks!
0 Kudos