Select to view content in your preferred language

Newbie question: how to add feature layer symbol to a layer list?

931
5
08-31-2010 03:29 AM
SuiHuang
Frequent Contributor
I adapted the following example to make layer list for a map with 3 FeatureLayer and 1 ArcGISTiledMapServiceLayer:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LayerList

The layer list works fine but does not show the symbol for each FeatureLayer. I found that I don't know how to adapt the above example and add the symbol graphics.

Can you tell me some idea?

Thank you.


Following is the map layers I am in my XAML code:
***********************************************************
<esri:Map.Layers>
    <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
    <esri:FeatureLayer ID="Warning"
Url="http://sampleserver.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapSer..." Color="Yellow"/>
    <esri:FeatureLayer ID="Wind"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapSe..."
  Color="Brown"/>
<esri:FeatureLayer ID="Stream Gauges"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapSe..."
  Color="BlueViolet"/>
</esri:Map.Layers>
***********************************************************************
0 Kudos
5 Replies
GopiP
by
Occasional Contributor
Use the FeatureSymbol attribute of the FeatureLayer.

http://help.arcgis.com/en/webapi/silverlight/help/index.html
0 Kudos
SuiHuang
Frequent Contributor
Use the FeatureSymbol attribute of the FeatureLayer.

http://help.arcgis.com/en/webapi/silverlight/help/index.html



Hi SriGopi:
    I understand that in some place of the code I should be able to do a binding on the FeatureSymbol property of the FeatureLayer. I also found the reference of FeatureSymbol
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...

    However, after trying around I still could find out how to use the FeatureSymbol property. It is in Symbol class of ESRI.ArcGIS.Client.Symbols Namespace, I don't know how to put it into the StackPanel and arrange it with other controls such as text blocks and checkboxes.

   Any further suggestion?

   Thank you.
0 Kudos
dotMorten_esri
Esri Notable Contributor
The REST API doesn't expose legend information, so there is no simple way to do this.
If you are hitting an ArcGIS Server 10 (your example aboe is not!), FeatureLayers do get render information from the server, but you will have to go through each symbol defined on the renderer (there could be more whan one symbol depending on what service you are hitting) and set these symbols on the Symbol property for the ESRI.ArcGIS.Client.Toolkit.Primitives.SymbolDisplay control.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
However, after trying around I still could find out how to use the FeatureSymbol property. It is in Symbol class of ESRI.ArcGIS.Client.Symbols Namespace, I don't know how to put it into the StackPanel and arrange it with other controls such as text blocks and checkboxes.


As Morten said, you can use the ESRI.ArcGIS.Client.Toolkit.Primitives.SymbolDisplay control.
For example the following code will give the attached result:
 
<Grid x:Name="LayoutRoot" >
<Grid.Resources>
<esri:FillSymbol x:Name="FillSymbol" Fill="Yellow" />
<esri:SimpleMarkerSymbol x:Name="MarkerSymbol0" Color="Brown" Style="Circle" />
<esri:SimpleMarkerSymbol x:Name="MarkerSymbol1" Color="BlueViolet" Style="Circle"/>
</Grid.Resources>
<esri:Map x:Name="MyMap" Extent="-120,20,-90,60">
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
<esri:FeatureLayer ID="Warning" FeatureSymbol="{StaticResource FillSymbol}" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapServer/2"/>
<esri:FeatureLayer ID="Wind" FeatureSymbol="{StaticResource MarkerSymbol0}" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapServer/0"/>
<esri:FeatureLayer ID="Stream Gauges" FeatureSymbol="{StaticResource MarkerSymbol1}" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyFeedSample/MapServer/1"/>
</esri:Map.Layers>
</esri:Map>
<Border Background="#77919191" BorderThickness="1" CornerRadius="5"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="20" Padding="5" BorderBrush="Black" >
 
<ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!--Layer visibility checkbox-->
<CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" />
<!-- Symbol -->
<esriPrimitives:SymbolDisplay Symbol="{Binding FeatureSymbol}" Margin="5,0,0,0" Height="18" Width="25" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<!--Opacity slider-->
<Slider Margin="0,0,0,0" Minimum="0" Maximum="1" Width="30" 
Value="{Binding Opacity, Mode=TwoWay}" Height="18" />
<!--Layer name-->
<TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,0,0" > 
<!-- Tooltip on hover-->
<ToolTipService.ToolTip>
<StackPanel MaxWidth="400">
<TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</ToolTipService.ToolTip>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
�??
�??
</Grid>
0 Kudos
SuiHuang
Frequent Contributor
Thank you dbroux, SharpGIS and SriGopi!
0 Kudos