Click or drag to resize

ArcGISSublayer Class

The base class for ArcGIS sublayer classes ArcGISMapImageSublayer and ArcGISTiledSublayer.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public abstract class ArcGISSublayer : ILayerContent, 
	IPopupSource, ILoadable

The ArcGISSublayer type exposes the following members.

Properties
  NameDescription
Public propertyCanChangeVisibility
Gets a value indicating whether the sublayer content's visibility can be changed.
Public propertyDefinitionExpression
Gets the definition expression of this sublayer.
Public propertyId
Gets an id that uniquely identifies this sublayer instance.
Public propertyIsPopupEnabled
Gets or sets a value indicating whether the PopupDefinition defined is enabled.
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether the sublayer content is visible.
Public propertyLabelsEnabled
Gets a value indicating whether labels should be displayed on this sublayer.
Public propertyLoadError
Gets the Exception associated with the last load error.
Public propertyLoadStatus
Gets the load status.
Public propertyMapServiceSublayerInfo
Gets this sublayer's metadata.
Public propertyMaxScale
Gets the maximum scale at which this sublayer is visible.
Public propertyMinScale
Gets the minimum scale at which this sublayer is visible.
Public propertyCode exampleName
Gets the name of the sublayer.
Public propertyOpacity
Gets the opacity of this sublayer.
Public propertyPopupDefinition
Gets or sets the popup definition for the sublayer.
Public propertyRenderer
Gets this sublayer's Renderer.
Public propertyScaleSymbols
Gets a value indicating whether this sublayer renders its symbols based on scale.
Public propertyShowInLegend
Gets or sets a value indicating whether the sublayer participates in the legend.
Public propertySublayerContents
Gets a read-only collection of ILayerContent for this sublayer.
Public propertySublayers
Gets the sublayers of this sublayer.
Top
Methods
  NameDescription
Public methodCancelLoad
Cancel loading metadata for the object.
Public methodClone
Clones this instance of the ArcGISSublayer and its members.
Public methodGetLegendInfosAsync
Asynchronously retrieves a read-only list of LegendInfo objects.
Public methodIsVisibleAtScale
Retrieves the sublayer's visibility at the specified scale.
Public methodLoadAsync
Load the metadata for the object asynchronously.
Public methodRetryLoadAsync
Load the metadata for the object asynchronously.
Top
Events
  NameDescription
Public eventLoaded
Event that is raised when the object is done loading.
Public eventLoadStatusChanged
Event that is raised when the LoadStatus property changes.
Top
Examples

Android

Example Name: ChangeSublayerVisibility

Change the visibility of sublayers.

Code example screen shot.

C#
// Copyright 2016 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;

namespace ArcGISRuntime.Samples.ChangeSublayerVisibility
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Change sublayer visibility",
        "Layers",
        "This sample demonstrates how to show or hide sublayers of a map image layer.",
        "")]
    public class ChangeSublayerVisibility : Activity
    {
        // Hold a reference to the map view
        private MapView _myMapView;

        // Hold reference to image layer for easier access to sublayers 
        private ArcGISMapImageLayer _imageLayer;

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

            Title = "Change sublayer visibility";
            // Create the UI, setup the control references and execute initialization 
            CreateLayout();
            Initialize();
        }

        private void Initialize()
        {
            // Create new Map
            Map myMap = new Map();

            // Create uri to the map image layer
            Uri serviceUri = new Uri(
               "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer");

            // Create new image layer from the url
            _imageLayer = new ArcGISMapImageLayer(serviceUri)
            {
                Name = "World Cities Population"
            };

            // Add created layer to the basemaps collection
            myMap.Basemap.BaseLayers.Add(_imageLayer);

            // Assign the map to the MapView
            _myMapView.Map = myMap;
        }

        private async void OnSublayersClicked(object sender, EventArgs e)
        {
            try
            {
                // Make sure that layer and it's sublayers are loaded
                // If layer is already loaded, this returns directly
                await _imageLayer.LoadAsync();

                Button sublayersButton = (Button)sender;

                // Create menu to change sublayer visibility
                PopupMenu sublayersMenu = new PopupMenu(this, sublayersButton);
                sublayersMenu.MenuItemClick += OnSublayersMenuItemClicked;

                // Create menu options
                foreach (ArcGISSublayer sublayer in _imageLayer.Sublayers)
                    sublayersMenu.Menu.Add(sublayer.Name);

                // Set values to the menu items
                for (int i = 0; i < sublayersMenu.Menu.Size(); i++)
                {
                    IMenuItem menuItem = sublayersMenu.Menu.GetItem(i);

                    // Set menu item to contain checkbox
                    menuItem.SetCheckable(true);

                    // Set default value
                    menuItem.SetChecked(_imageLayer.Sublayers[i].IsVisible);
                }

                // Show menu in the view
                sublayersMenu.Show();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.ToString()).SetTitle("Error").Show();
            }
        }

        private void OnSublayersMenuItemClicked(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            // Change the checked value
            e.Item.SetChecked(!e.Item.IsChecked);

            // Get title from the selected item
            string selectedSublayerTitle = e.Item.TitleCondensedFormatted.ToString();

            // Get index that is used to get the selected url
            ArcGISSublayer sublayer = _imageLayer.Sublayers.First(x => x.Name == selectedSublayerTitle);
            sublayer.IsVisible = e.Item.IsChecked;
        }

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

            // Create button to show possible map options
            Button mapsButton = new Button(this)
            {
                Text = "Sublayers"
            };
            mapsButton.Click += OnSublayersClicked;

            // Add maps button to the layout
            layout.AddView(mapsButton);

            // Add the map view to the layout
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

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

Xamarin Forms Android

Example Name: ChangeSublayerVisibility

Change the visibility of sublayers.

Code example screen shot.

C#
// Copyright 2016 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 Xamarin.Forms;

namespace ArcGISRuntime.Samples.ChangeSublayerVisibility
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Change sublayer visibility",
        "Layers",
        "This sample demonstrates how to show or hide sublayers of a map image layer.",
        "")]
    public partial class ChangeSublayerVisibility : ContentPage
    {
        private ArcGISMapImageLayer _imageLayer;

        public ChangeSublayerVisibility()
        {
            InitializeComponent();

            // Create the UI, setup the control references and execute initialization 
            Initialize();
        }

        private void Initialize()
        {
            // Create new Map
            Map myMap = new Map();

            // Create uri to the map image layer
            Uri serviceUri = new Uri(
               "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer");

            // Create new image layer from the url
            _imageLayer = new ArcGISMapImageLayer(serviceUri)
            {
                Name = "World Cities Population"
            };

            // Add created layer to the basemaps collection
            myMap.Basemap.BaseLayers.Add(_imageLayer);

            // Assign the map to the MapView
            MyMapView.Map = myMap;
        }

        private async void OnSublayersClicked(object sender, EventArgs e)
        {
            try
            {
                // Make sure that layer and it's sublayers are loaded
                // If layer is already loaded, this returns directly
                await _imageLayer.LoadAsync();

                // Create layout for sublayers page
                // Create root layout
                StackLayout layout = new StackLayout();

                // Create list for layers
                TableView sublayersTableView = new TableView();

                // Create section for basemaps sublayers
                TableSection sublayersSection = new TableSection(_imageLayer.Name);

                // Create cells for each of the sublayers
                foreach (ArcGISSublayer sublayer in _imageLayer.Sublayers)
                {
                    // Using switch cells that provides on/off functionality
                    SwitchCell cell = new SwitchCell()
                    {
                        Text = sublayer.Name,
                        On = sublayer.IsVisible
                    };

                    // Hook into the On/Off changed event
                    cell.OnChanged += OnCellOnOffChanged;

                    // Add cell into the table view
                    sublayersSection.Add(cell);
                }

                // Add section to the table view
                sublayersTableView.Root.Add(sublayersSection);

                // Add table to the root layout
                layout.Children.Add(sublayersTableView);

                // Create internal page for the navigation page
                ContentPage sublayersPage = new ContentPage()
                {
                    Content = layout,
                    Title = "Sublayers"
                };

                // Navigate to the sublayers page
                await Navigation.PushAsync(sublayersPage);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");

            }
        }

        private void OnCellOnOffChanged(object sender, ToggledEventArgs e)
        {
            SwitchCell cell = (SwitchCell)sender;

            // Find the layer from the image layer
            ArcGISSublayer sublayer = _imageLayer.Sublayers.First(x => x.Name == cell.Text);

            // Change sublayers visibility
            sublayer.IsVisible = e.Value;
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<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:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime" 
             x:Class="ArcGISRuntime.Samples.ChangeSublayerVisibility.ChangeSublayerVisibility">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button x:Name="SublayersButton" Text="Sublayer" Clicked="OnSublayersClicked"></Button>
        <esriUI:MapView x:Name="MyMapView" Grid.Row="1"/>
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
ChangeSublayerRendererApply a renderer to a sublayer.
ChangeSublayerVisibilityChange the visibility of sublayers.
IdentifyLayersIdentify features in all layers in a map. MapView supports identifying features across multiple layers. Because some layer types have sublayers, the sample recursively counts results for sublayers within each layer.
MapImageSublayerQueryFind features in a sublayer based on attributes and location.