Most apps have more than one layer. In real apps, there could be five layers or even 20 layers. You could even have the option for the user to have multiple basemaps. Once multiple vector (geometric) layers are added to the map, it can easily become difficult to discern which layers are which, especially in dense urban areas. Because of this, a legend is really helpful and pretty much a standard feature for non-trivial apps. Here is an example of a legend built with the iOS version of the SDK:
Unfortunately, ArcGIS Runtime does not come with a legend control in Esri.ArcGISRuntime.Controls
. However, Esri has built a toolkit that comes with some sample legends, which we will now make use of in the next exercise:
Esri.ArcGISRuntime.Toolkit.dll
, which is located in C:ArcGISRuntimeBook
.MainWindow.xaml
. Add the following reference to the XAML code:xmlns:toolkit="clr-namespace:Esri.ArcGISRuntime.Toolkit.Controls;assembly=Esri.ArcGISRuntime.Toolkit"
</MapView>
tab, add the following XAML code:<Border BorderBrush="Black" BorderThickness="1" Margin="30" Padding="10,20,20,20" HorizontalAlignment="Right" VerticalAlignment="Top"> <Border.Effect> <DropShadowEffect /> </Border.Effect> <ScrollViewer VerticalScrollBarVisibility="Hidden"> <toolkit:Legend Foreground="White" Layers="{Binding Map.Layers, ElementName=MyMapView}" ReverseLayersOrder="False" > </toolkit:Legend> </ScrollViewer> </Border>
It's not much at this point because we don't have many layers; however, as you add more layers, the legend will show any new FeatureLayer
classes. All that this code does is use a component in the toolkit named Legend
. The Legend
component has a property called Layers
, which is bound to the MapView
component's Map
, which has a Layers
property. The layers are also shown in the reverse order in which they were added using the ReverseLayersOrder
property.
There are other kinds of legend in the toolkit, which you can explore on your own. In fact, you can download the source code for the toolkit from GitHub at https://github.com/Esri/arcgis-toolkit-dotnet.