Dynamic Layer Reordering

Download Samples Repository

Description

This sample demonstrates changing the order of dynamic layers. Clicking the 'Change Layer Order' button uses the DynamicLayerInfoCollection to move the top layer to the bottom.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.DynamicLayerReordering"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
		<esri:MapView x:Name="MyMapView" WrapAround="True">
            <esri:Map InitialViewpoint="-14675766.357,2695407.734,-6733121.861,6583994.101,102100">
                <esri:ArcGISDynamicMapServiceLayer x:Name="dynamicLayer" ID="USA"
				    ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />
            </esri:Map>
        </esri:MapView>
		
		<Border Background="White" BorderBrush="Black" BorderThickness="1"
				HorizontalAlignment="Right" VerticalAlignment="Top" 
				Margin="30" Padding="20">
			<Border.Effect>
				<DropShadowEffect />
			</Border.Effect>

            <Button Content="Change Layer Order" Click="ChangeLayerOrderClick" Height="30" />
        </Border>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Geometry;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample demonstrates changing the order of dynamic layers. Clicking the 'Change Layer Order' button uses the DynamicLayerInfoCollection to move the top layer to the bottom.
    /// </summary>
    /// <title>Dynamic Layer Reordering</title>
	/// <category>Layers</category>
	/// <subcategory>Dynamic Service Layers</subcategory>
	public partial class DynamicLayerReordering : UserControl
    {
        public DynamicLayerReordering()
        {
            InitializeComponent();
			MyMapView.Map.SpatialReference = SpatialReferences.WebMercator;
        }

        private void ChangeLayerOrderClick(object sender, System.Windows.RoutedEventArgs e)
        {
            if (dynamicLayer.DynamicLayerInfos == null)
                dynamicLayer.DynamicLayerInfos = dynamicLayer.CreateDynamicLayerInfosFromLayerInfos();

            // Move the bottom layer to the top
            var layerInfo = dynamicLayer.DynamicLayerInfos[0];
            dynamicLayer.DynamicLayerInfos.RemoveAt(0);
            dynamicLayer.DynamicLayerInfos.Add(layerInfo);
        }
    }
}
Feedback on this topic?