Click or drag to resize

GroupLayer Class

A group layer contains other layers. Group layers help organize related kinds of layers in a map and can be used to define advanced drawing options. Group layer supports nested group layers.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public sealed class GroupLayer : Layer

The GroupLayer type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyAttribution
Gets the attribution text for the layer.
(Inherited from Layer.)
Public propertyCanChangeVisibility
Gets a value indicating whether the layer content's visibility can be changed.
(Inherited from Layer.)
Public propertyDescription
Gets the description for the layer.
(Inherited from Layer.)
Public propertyCode exampleFullExtent
Gets the full extent of the layer, which is the extent where all the data in the layer is contained.
(Inherited from Layer.)
Public propertyCode exampleId
Gets or sets an identifier for the layer
(Inherited from Layer.)
Public propertyIsIdentifyEnabled
Gets a value indicating whether the layer supports the identify operation.
(Inherited from Layer.)
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether the layer content is visible.
(Inherited from Layer.)
Public propertyItem
Gets the ArcGIS Item
(Inherited from Layer.)
Public propertyCode exampleLayers
Gets or sets the child layers associated with a group layer.
Public propertyLoadError
Gets the load error of the layer, if there is one.
(Inherited from Layer.)
Public propertyCode exampleLoadStatus
Gets the load status of the layer.
(Inherited from Layer.)
Public propertyCode exampleMaxScale
Gets or sets the maximum scale where the layer is visible.
(Inherited from Layer.)
Public propertyCode exampleMinScale
Gets or sets the minimum scale where the layer is visible.
(Inherited from Layer.)
Public propertyCode exampleName
Gets or sets the name of the layer content.
(Inherited from Layer.)
Public propertyCode exampleOpacity
Gets or sets the opacity of the layer.
(Inherited from Layer.)
Public propertyShowChildrenInLegend
Gets or sets the show children in legend property of the group layer
Public propertyShowInLegend
Gets or sets a value indicating whether the layer content participates in the legend.
(Inherited from Layer.)
Public propertySpatialReference
Gets the spatial reference of the layer.
(Inherited from Layer.)
Public propertyCode exampleSublayerContents
Gets the sub layer contents of a layer content.
(Inherited from Layer.)
Top
Methods
  NameDescription
Public methodCancelLoad
Cancels an ongoing load.
(Inherited from Layer.)
Public methodCode exampleClone
Clones this instance of Layer and its members.
(Inherited from Layer.)
Public methodGetLegendInfosAsync
Returns an immutable list of LegendInfo.
(Inherited from Layer.)
Public methodIsVisibleAtScale
Returns the layer content's effective visibility at the specified scale.
(Inherited from Layer.)
Public methodCode exampleLoadAsync
Initiates loading of a layer
(Inherited from Layer.)
Public methodRetryLoadAsync
Retry loading the layer.
(Inherited from Layer.)
Top
Events
  NameDescription
Public eventCode exampleLoaded
Occurs when the layer is loaded.
(Inherited from Layer.)
Public eventCode exampleLoadStatusChanged
Occurs when the layer LoadStatus is changed.
(Inherited from Layer.)
Public eventPropertyChanged
Occurs when a property value changes.
(Inherited from Layer.)
Top
Examples

Android

Example Name: GroupLayers

Group a collection of layers together and toggle their visibility as a group.

Code example screen shot.

C#
// Copyright 2019 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace ArcGISRuntimeXamarin.Samples.GroupLayers
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Group layers",
        "Layers",
        "Group a collection of layers together and toggle their visibility as a group.",
        "")]
    public class GroupLayers : Activity
    {
        // Hold references to the UI controls.
        private SceneView _mySceneView;
        private LinearLayout _layerListView;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Group layers";

            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create the layers.
            ArcGISSceneLayer devOne = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Trees/SceneServer"));
            FeatureLayer devTwo = new FeatureLayer(new Uri("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Pathways/FeatureServer/1"));
            ArcGISSceneLayer devThree = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevB_BuildingShells/SceneServer"));
            ArcGISSceneLayer nonDevOne = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_BuildingShells/SceneServer"));
            FeatureLayer nonDevTwo = new FeatureLayer(new Uri("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevelopmentProjectArea/FeatureServer/0"));

            // Create the group layer and add sublayers.
            GroupLayer gLayer = new GroupLayer();
            gLayer.Name = "Group: Dev A";
            gLayer.Layers.Add(devOne);
            gLayer.Layers.Add(devTwo);
            gLayer.Layers.Add(devThree);

            // Create the scene with a basemap.
            _mySceneView.Scene = new Scene(Basemap.CreateImagery());

            // Add the top-level layers to the scene.
            _mySceneView.Scene.OperationalLayers.Add(gLayer);
            _mySceneView.Scene.OperationalLayers.Add(nonDevOne);
            _mySceneView.Scene.OperationalLayers.Add(nonDevTwo);

            // Wait for all of the layers in the group layer to load.
            await Task.WhenAll(gLayer.Layers.ToList().Select(m => m.LoadAsync()).ToList());

            // Zoom to the extent of the group layer.
            _mySceneView.SetViewpoint(new Viewpoint(gLayer.FullExtent));

            // Add the layer list to the UI.
            foreach (Layer layer in _mySceneView.Scene.OperationalLayers)
            {
                AddLayersToUI(layer);
            }
        }

        private async void AddLayersToUI(Layer layer, int nestLevel = 0)
        {
            // Wait for the layer to load - ensures that the UI will be up-to-date.
            await layer.LoadAsync();

            // Add a row for the current layer.
            _layerListView.AddView(ViewForLayer(layer, nestLevel));

            // Add rows for any children of this layer if it is a group layer.
            if (layer is GroupLayer layerGroup)
            {
                foreach (Layer child in layerGroup.Layers)
                {
                    AddLayersToUI(child, nestLevel + 1);
                }
            }
        }

        private View ViewForLayer(Layer layer, int nestLevel = 0)
        {
            // Create the view that holds the row.
            LinearLayout rowContainer = new LinearLayout(this);
            rowContainer.Orientation = Orientation.Horizontal;

            // Padding implements the nesting/hieararchy display.
            rowContainer.SetPadding(32 * nestLevel, 0, 0, 0);

            // Create and configure the visibility toggle.
            CheckBox toggle = new CheckBox(this);
            toggle.Checked = true;
            toggle.CheckedChange += (sender, args) => layer.IsVisible = toggle.Checked;
            rowContainer.AddView(toggle);

            // Add a label for the layer.
            rowContainer.AddView(new TextView(this) {Text = layer.Name});

            return rowContainer;
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app.
            var layout = new LinearLayout(this) {Orientation = Orientation.Vertical};

            _layerListView = new LinearLayout(this);
            _layerListView.Orientation = Orientation.Vertical;

            layout.AddView(_layerListView);

            // Add the map view to the layout.
            _mySceneView = new SceneView(this);
            layout.AddView(_mySceneView);

            // Show the layout in the app.
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: GroupLayers

Group a collection of layers together and toggle their visibility as a group.

Code example screen shot.

C#
// Copyright 2019 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Mapping;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.GroupLayers
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Group layers",
        "Layers",
        "Group a collection of layers together and toggle their visibility as a group.",
        "")]
    public partial class GroupLayers : ContentPage
    {
        public GroupLayers()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Create the layers.
            ArcGISSceneLayer devOne = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Trees/SceneServer"));
            FeatureLayer devTwo = new FeatureLayer(new Uri("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Pathways/FeatureServer/1"));
            ArcGISSceneLayer devThree = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevB_BuildingShells/SceneServer"));
            ArcGISSceneLayer nonDevOne = new ArcGISSceneLayer(new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_BuildingShells/SceneServer"));
            FeatureLayer nonDevTwo = new FeatureLayer(new Uri("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevelopmentProjectArea/FeatureServer/0"));

            // Create the group layer and add sublayers.
            GroupLayer gLayer = new GroupLayer();
            gLayer.Name = "Group: Dev A";
            gLayer.Layers.Add(devOne);
            gLayer.Layers.Add(devTwo);
            gLayer.Layers.Add(devThree);

            // Create the scene with a basemap.
            MySceneView.Scene = new Scene(Basemap.CreateImagery());

            // Add the top-level layers to the scene.
            MySceneView.Scene.OperationalLayers.Add(gLayer);
            MySceneView.Scene.OperationalLayers.Add(nonDevOne);
            MySceneView.Scene.OperationalLayers.Add(nonDevTwo);

            // Wait for all of the layers in the group layer to load.
            await Task.WhenAll(gLayer.Layers.ToList().Select(m => m.LoadAsync()).ToList());

            // Zoom to the extent of the group layer.
            MySceneView.SetViewpoint(new Viewpoint(gLayer.FullExtent));

            // Add the layer list to the UI.
            foreach (Layer layer in MySceneView.Scene.OperationalLayers)
            {
                AddLayersToUI(layer);
            }
        }

        private async void AddLayersToUI(Layer layer, int nestLevel = 0)
        {
            // Wait for the layer to load - ensures that the UI will be up-to-date.
            await layer.LoadAsync();

            // Add a row for the current layer.
            LayersView.Children.Add(ViewForLayer(layer, nestLevel));

            // Add rows for any children of this layer if it is a group layer.
            if (layer is GroupLayer layerGroup)
            {
                foreach (Layer child in layerGroup.Layers)
                {
                    AddLayersToUI(child, nestLevel + 1);
                }
            }
        }

        private View ViewForLayer(Layer layer, int nestLevel = 0)
        {
            // Create the view that holds the row.
            StackLayout container = new StackLayout();
            container.Orientation = StackOrientation.Horizontal;

            // Create and configure the visibility toggle.
            Switch toggleSwitch = new Switch();
            toggleSwitch.VerticalOptions = LayoutOptions.Center;
            toggleSwitch.IsToggled = true;
            toggleSwitch.Toggled += (sender, args) => layer.IsVisible = !layer.IsVisible;

            // Implement nesting/hiearchy display.
            container.Margin = new Thickness(nestLevel * 30, 5, 10, 5);
            container.Children.Add(toggleSwitch);

            // Add the label to the row.
            Label layerLabel = new Label();
            layerLabel.Text = layer.Name;
            layerLabel.VerticalOptions = LayoutOptions.Center;
            layerLabel.VerticalTextAlignment = TextAlignment.Center;
            container.Children.Add(layerLabel);

            return container;
        }
    }
}
XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:resources="clr-namespace:Forms.Resources;assembly=ArcGISRuntime"
             x:Class="ArcGISRuntimeXamarin.Samples.GroupLayers.GroupLayers">
    <RelativeLayout>
        <esriUI:SceneView x:Name="MySceneView" Style="{StaticResource SceneWithFormStyle}"
                          BindingContext="{x:Reference Name=ResponsiveFormContainer}" />
        <resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
            <!-- View is being done mostly in code, not XAML, because of buggy listview behavior and no option to specify a maximum height. -->
            <StackLayout x:Name="LayersView" />
        </resources:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
GroupLayersGroup a collection of layers together and toggle their visibility as a group.