Legend

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:

Legend

Legend built with the ios version

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:

  1. Add a reference to Esri.ArcGISRuntime.Toolkit.dll, which is located in C:ArcGISRuntimeBook.
  2. In the project we created earlier in this chapter, we will now add some XAML code to MainWindow.xaml. Add the following reference to the XAML code:
    xmlns:toolkit="clr-namespace:Esri.ArcGISRuntime.Toolkit.Controls;assembly=Esri.ArcGISRuntime.Toolkit"
  3. After the closing </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>
  4. Run the app and you will note that you have a legend:
    Legend

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset