Click or drag to resize
LayerDefinition Class
Inheritance Hierarchy

Namespace: Esri.ArcGISRuntime.Layers
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: (
public sealed class LayerDefinition

The LayerDefinition type exposes the following members.

Public methodLayerDefinition
Initializes a new instance of the LayerDefinition class
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public propertyDefinition
Gets or sets the layer definition.
Public propertyCode exampleLayerID
Gets or sets the layer ID.

Shows adding an ArcGISDynamicMapServiceLayer with a LayerDefinition applied (discovered by the ArcGISDynamicMapServiceLayer.GetDetailsAsync Method) and then modifying the LayerDefinition to change the features returned.

Code example using the LayerDefinition Class.

<Window x:Class="ArcGISDynamicMapServiceLayer_GetDetails.MainWindow"
    Title="MainWindow" Height="600" Width="800">

    <Grid x:Name="LayoutRoot">

        <!-- Add a MapView Control. -->
        <esri:MapView x:Name="MapView1" Background="White" HorizontalAlignment="Left" Margin="10,107,0,0" 
                      VerticalAlignment="Top" Height="453" Width="772">

            <!-- Add a Map. -->
            <esri:Map x:Name="Map1">

                <!-- Add an ArcGISDynamicMapServiceLayer. -->
                <esri:ArcGISDynamicMapServiceLayer ID="MyUniqueName"
                    ServiceUri="" />


        <!-- Add a Button to apply to modify ArcGISDynamicMapServiceLayer.LayerDefinitions. -->
        <Button Content="Apply New LayerDefinition" Height="23" HorizontalAlignment="Left" Margin="7,79,0,0" 
          Name="Button_ApplyNewLayerDefinition" VerticalAlignment="Top" Width="184" 

        <!-- TextBox to hold the LayerDefinitions text for the ArcGISDynamicMapServiceLayer. -->
        <TextBox Height="23" HorizontalAlignment="Left" Margin="206,79,0,0" Name="TextBox1" 
           VerticalAlignment="Top" Width="576" />

        <!-- TextBlock to hold the instructions on how to use the sample code. -->
        <TextBlock Height="74" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="775" 
                   TextWrapping="Wrap" Margin="7,0,0,0" />



SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "ArcGISDynamicMapServiceLayer_GetDetails.MainWindow" to be just "MainWindow".

namespace ArcGISDynamicMapServiceLayer_GetDetails
    public partial class MainWindow : System.Windows.Window
        public MainWindow()
            // This call is required by the designer.

            // Add any initialization after the InitializeComponent() call.

            // Add instructions on how to use the sample. 
            TextBlock1.Text = "When the application loads an ArcGISDynamicMapServiceLayer will display. One of the " + 
                "sub-layers has a LayerDefinition value specified which restrict how many features are returned in the " + 
                "Map. This server-side LayerDefintion will be displayed in the TextBox. Click " + 
                "your cursor in the TextBox for the sub-layer LayerDefinition and modify it. Then click the Button " + 
                "to see the changes. If you type a bogus LayerDefintion in the TextBox for the sub-layer, it will " + 
                "not display any features. Use the '1=1' to return all features for the sub-layer.";

            // Zoom to a specified target area in the in the Map.
            Esri.ArcGISRuntime.Geometry.Envelope myEnvelope = new Esri.ArcGISRuntime.Geometry.Envelope(13414332, 392041, 13415767, 392701);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope);

            // Call the asynchronous function to display the DefinitionExpression of the ArcGISDynamicMapServiceLayer in a TextBox. 

        private async void Init()
            // When the application loads get the LayerDefinition expression for a specific sub-layer.
            // It is necessary to use the ArcGISDynamicMapServiceLayer.GetDetails Method to obtain the LayerDefintion
            // for the sub-layer of the web service on ArcGIS Server via the FeatureServiceLayerInfo object. 
            // NOTE: Do not use the ArcGISDynamicMapServiceLayer.LayerDefinitions Property to try and obtain the
            // layer definition value as this the Property will return null/Nothing from the web service. 

            // Get the ArcGISDynamicMapServiceLayer from the Map by its ID value that was set in XAML.
            Esri.ArcGISRuntime.Layers.LayerCollection myLayerCollection = MapView1.Map.Layers;
            Esri.ArcGISRuntime.Layers.Layer myLayer = myLayerCollection["MyUniqueName"];
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)myLayer;

            // Get the details for the first (i.e. 0) sub-layer. 
            Esri.ArcGISRuntime.ArcGISServices.FeatureServiceLayerInfo myFeatureServiceLayerInfo = await myArcGISDynamicMapServiceLayer.GetDetailsAsync(0);

            // Display the sub-layer's DefinitionExpression in the TextBox via the FeatureServiceLayerInfo object.
            TextBox1.Text = myFeatureServiceLayerInfo.DefinitionExpression;

        private void Button_ApplyNewLayerDefinition_Click(object sender, System.Windows.RoutedEventArgs e)
            // This function will apply the user changes to the sub-layer LayerDefintion to produce a new map
            // with different features returned.

            // Get the ArcGISDynamicMapServiceLayer from the Map Control by its ID value that was set in XAML.
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)(Map1.Layers["MyUniqueName"]);

            // Create an ObservableCollection of sub-layer LayerDefinitions. 
            System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Layers.LayerDefinition> myObservableCollection = new System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Layers.LayerDefinition>();

            // Create a new LayerDefinition object for the first (i.e. 0) sub-layer. Set the ID and Definition values.
            Esri.ArcGISRuntime.Layers.LayerDefinition myDefinition = new Esri.ArcGISRuntime.Layers.LayerDefinition();
            myDefinition.LayerID = 0;
            myDefinition.Definition = TextBox1.Text;

            // Apply the custom LayerDefinition to the ArcGISDynamicMapServiceLayer; this will force the map to redraw.
            myArcGISDynamicMapServiceLayer.LayerDefinitions = myObservableCollection;
See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
ArcGISDynamicMapServiceLayer_GetDetailsShows adding an ArcGISDynamicMapServiceLayer with a LayerDefinition applied (discovered by the ArcGISDynamicMapServiceLayer.GetDetailsAsync Method) and then modifying the LayerDefinition to change the features returned.
DynamicLayerInfosDemonstrates using various Renderers on a Dynamic Layer (via XAML and code-behind) when the 'WorkspaceID' and 'DataSourceName' are known using a TableDataSource.
LayerDefinitionsDemonstrates setting numerous LayerDefinitions values on an ArcGISDynamicMapServiceLayer and visualizing the impact of the features being returned in the Map.
LayerDefinitionsSimpleDemonstrates setting the LayerDefinitions Property of an ArcGISDynamicMapServiceLayer where two sub-layers are present. One sub-layer has the LayerDefinition set in XAML and the other sub-layer has it's LayerDefinition set via code-behind.