Select to view content in your preferred language

esriToolkitPrimitives Legend sync

765
4
10-01-2011 12:43 AM
SantoshV
Emerging Contributor
HI,

I have a FeatureLayer
        <esri:Map x:Name="MyMap" >

            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
            <esri:FeatureLayer ID="MyFeatureLayer2"
              Url="http://192.168.1.52/ArcGIS/rest/services/RMS_BOUNDARIES/MapServer/1"
              Where="DISTRICT_ID = 5"   >
            </esri:FeatureLayer>
        </esri:Map>


here the map shows the District whos ID is 5..
but when I bind this featureLayer to esriToolkitPrimitives
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <ListBox Margin="0" IsHitTestVisible="False" BorderThickness="0"
                         ItemsSource="{Binding ElementName=MyMap, Path=Layers.[MyFeatureLayer2].LayerInfo.Renderer.Infos}" 
                         Grid.Row="1">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <esriToolkitPrimitives:SymbolDisplay 
                                    Symbol="{Binding Symbol}" 
                                    Width="20" Height="20"                                     
                                    VerticalAlignment="Center" />
                                        <TextBlock Text="{Binding Label}" 
                                           FontSize="10" 
                                           VerticalAlignment="Center"
                                           Margin="5,0,0,0" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </ScrollViewer>

The listbox still shows all the layers in it..
I want to only show the Item whose Id is 5

how do i achieve this
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
The problem is coming from your ItemsSource binding:
ItemsSource="{Binding ElementName=MyMap, Path=Layers.[MyFeatureLayer2].LayerInfo.Renderer.Infos}"

With this binding you will get all renderer infos whatever it's used or not.

One option is you to implement by code your own enumeration that returns only the symbols used in the layer.
0 Kudos
SantoshV
Emerging Contributor
The problem is coming from your ItemsSource binding:

With this binding you will get all renderer infos whatever it's used or not.

One option is you to implement by code your own enumeration that returns only the symbols used in the layer.


Hi,
Thanks you for your reply I have been breaking my head over this trying to remove items from the Legend control..
Can you please throw in a little bit of code that would help me overcome this issue
0 Kudos
DominiqueBroux
Esri Frequent Contributor
See this thread for an answer concerning the legend control.

Looks like whatever you use the legend control or your own control, the problem is the same, how to know the useful renderer items from a where clause.
0 Kudos
SantoshV
Emerging Contributor
The legend control worked well

ESRI.ArcGIS.Client.Toolkit.Legend.RefreshedEventArgs e)
{
  var fLayer = e.LayerItem.Layer as FeatureLayer;
  if (fLayer != null && fLayer.ID == "MyFeatureLayer2" && e.LayerItem.LegendItems != null)
  {
    var toRemove = e.LayerItem.LegendItems.Where(item => item.Label != "7").ToArray(); // Warning : may be a coded value instead of just '7'. Depending on your model
    foreach (var item in toRemove)
      e.LayerItem.LegendItems.Remove(item);
  }
}


but I display the Label with its symbol..
I want to add the length of the polyline(road) in KMs which will be queryed from the database..
is this possible ..
0 Kudos