Click or drag to resize

AnnotationSublayer Class

Describes a sublayer of AnnotationLayer.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.MappingAnnotationSublayer

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

The AnnotationSublayer type exposes the following members.

Properties
  NameDescription
Public propertyCanChangeVisibility
Gets a value indicating whether the sublayer's visibility can be changed.
Public propertyDefinitionExpression
The WHERE clause of the SQL expression that defines which annotation features from the feature table are selected into this Sublayer.
Public propertyCode exampleIsVisible
Gets or sets a value indicating whether the sublayer content is visible.
Public propertyCode exampleMaxScale
Gets the maximum scale at which to display the Sublayer.
Public propertyCode exampleMinScale
Gets the minimum scale at which to display the Sublayer.
Public propertyCode exampleName
Gets the title of this Annotation sublayer.
Public propertyOpacity
Gets the opacity with which to display the annotation text associated with this Sublayer.
Public propertyScaleSymbols
Gets a value indicating whether the annotation text scales with the MapView.
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 propertySublayerId
Gets a non-negative number representing Id of the AnnotationSublayer within its AnnotationLayer.
Top
Methods
  NameDescription
Public methodGetLegendInfosAsync
Asynchronously retrieves a read-only list of LegendInfo objects.
Public methodCode exampleIsVisibleAtScale
Retrieves the sublayer's visibility at the specified scale.
Top
Remarks
AnnotationSublayer allows you to interrogate the properties of a Sublayer within an Annotation layer, and to change the visibility of the sublayer.
Examples

Android

Example Name: ControlAnnotationSublayerVisibility

Use annotation sublayers to gain finer control of annotation layer subtypes.

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.Graphics;
using Android.OS;
using Android.Widget;
using ArcGISRuntime;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;

namespace ArcGISRuntimeXamarin.Samples.ControlAnnotationSublayerVisibility
{
    [Activity(ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Control annotation sublayer visibility",
        "Layers",
        "Use annotation sublayers to gain finer control of annotation layer subtypes.",
        "")]
    [ArcGISRuntime.Samples.Shared.Attributes.AndroidLayout("ControlAnnotationSublayerVisibility.axml")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("b87307dcfb26411eb2e92e1627cb615b")]
    public class ControlAnnotationSublayerVisibility : Activity
    {
        // Hold references to the UI controls.
        private MapView _myMapView;
        private CheckBox _openCheckBox;
        private CheckBox _closedCheckBox;
        private TextView _status;

        // Mobile map package that contains annotation layers.
        private MobileMapPackage _mobileMapPackage;

        // Sub layers of the annotation layer.
        private AnnotationSublayer _openSublayer;
        private AnnotationSublayer _closedSublayer;

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

            Title = "Control annotation sublayer visibility";

            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            try
            {
                // Load the mobile map package.
                _mobileMapPackage = new MobileMapPackage(DataManager.GetDataFolder("b87307dcfb26411eb2e92e1627cb615b", "GasDeviceAnno.mmpk"));
                await _mobileMapPackage.LoadAsync();

                // Set the mapview to display the map from the package.
                _myMapView.Map = _mobileMapPackage.Maps.First();

                // Get the annotation layer from the MapView operational layers.
                AnnotationLayer annotationLayer = (AnnotationLayer)_myMapView.Map.OperationalLayers.Where(layer => layer is AnnotationLayer).First();

                // Load the annotation layer.
                await annotationLayer.LoadAsync();

                // Get the annotation sub layers.
                _closedSublayer = (AnnotationSublayer)annotationLayer.SublayerContents[0];
                _openSublayer = (AnnotationSublayer)annotationLayer.SublayerContents[1];

                // Set the label content.
                _openCheckBox.Text = $"{_openSublayer.Name} (1:{_openSublayer.MaxScale} - 1:{_openSublayer.MinScale})";
                _closedCheckBox.Text = _closedSublayer.Name;

                // Enable the check boxes.
                _openCheckBox.Enabled = true;
                _closedCheckBox.Enabled = true;

                // Add event handler for changing the text to indicate whether the "open" sublayer is visible at the current scale.
                _myMapView.ViewpointChanged += (s, e) =>
                {
                    // Check if the sublayer is visible at the current map scale.
                    if (_openSublayer.IsVisibleAtScale(_myMapView.MapScale))
                    {
                        _openCheckBox.SetTextColor(Color.Black);
                    }
                    else
                    {
                        _openCheckBox.SetTextColor(Color.Gray);
                    }

                    // Set the current map scale text.
                    _status.Text = "Current map scale: 1:" + (int)_myMapView.MapScale;
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        private void OpenCheckBoxChanged(object sender, CompoundButton.CheckedChangeEventArgs e)
        {
            // Set the visibility of the sub layer.
            if (_openSublayer != null) _openSublayer.IsVisible = _openCheckBox.Checked;
        }

        private void ClosedCheckBoxChanged(object sender, CompoundButton.CheckedChangeEventArgs e)
        {
            // Set the visibility of the sub layer.
            if (_closedSublayer != null) _closedSublayer.IsVisible = _closedCheckBox.Checked;
        }

        private void CreateLayout()
        {
            // Load the UI from the axml file.
            SetContentView(Resource.Layout.ControlAnnotationSublayerVisibility);

            // Get the UI elements from the axml resource.
            _myMapView = FindViewById<MapView>(Resource.Id.MapView);
            _openCheckBox = FindViewById<CheckBox>(Resource.Id.openCheckBox);
            _closedCheckBox = FindViewById<CheckBox>(Resource.Id.closedCheckBox);
            _status = FindViewById<TextView>(Resource.Id.statusLabel);

            // Add listeners for the checkboxes.
            _openCheckBox.CheckedChange += OpenCheckBoxChanged;
            _closedCheckBox.CheckedChange += ClosedCheckBoxChanged;
        }
    }
}
Examples

Xamarin Forms Android

Example Name: ControlAnnotationSublayerVisibility

Use annotation sublayers to gain finer control of annotation layer subtypes.

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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Linq;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.ControlAnnotationSublayerVisibility
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Control annotation sublayer visibility",
        "Layers",
        "Use annotation sublayers to gain finer control of annotation layer subtypes.",
        "")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("b87307dcfb26411eb2e92e1627cb615b")]
    public partial class ControlAnnotationSublayerVisibility : ContentPage
    {
        // Mobile map package that contains annotation layers.
        private MobileMapPackage _mobileMapPackage;

        // Sub layers of the annotation layer.
        private AnnotationSublayer _openSublayer;
        private AnnotationSublayer _closedSublayer;

        public ControlAnnotationSublayerVisibility()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            try
            {
                // Load the mobile map package.
                _mobileMapPackage = new MobileMapPackage(DataManager.GetDataFolder("b87307dcfb26411eb2e92e1627cb615b", "GasDeviceAnno.mmpk"));
                await _mobileMapPackage.LoadAsync();

                // Set the mapview to display the map from the package.
                MyMapView.Map = _mobileMapPackage.Maps.First();

                // Get the annotation layer from the MapView operational layers.
                AnnotationLayer annotationLayer = (AnnotationLayer)MyMapView.Map.OperationalLayers.Where(layer => layer is AnnotationLayer).First();

                // Load the annotation layer.
                await annotationLayer.LoadAsync();

                // Get the annotation sub layers.
                _closedSublayer = (AnnotationSublayer)annotationLayer.SublayerContents[0];
                _openSublayer = (AnnotationSublayer)annotationLayer.SublayerContents[1];

                // Set the label content.
                OpenLabel.Text = $"{_openSublayer.Name} (1:{_openSublayer.MaxScale} - 1:{_openSublayer.MinScale})";
                ClosedLabel.Text = _closedSublayer.Name;

                // Enable the check boxes.
                OpenSwitch.IsEnabled = true;
                ClosedSwitch.IsEnabled = true;

                // Add event handler for changing the text to indicate whether the "open" sublayer is visible at the current scale.
                MyMapView.ViewpointChanged += (s, e) =>
                {
                    // Check if the sublayer is visible at the current map scale.
                    if (_openSublayer.IsVisibleAtScale(MyMapView.MapScale))
                    {
                        OpenLabel.TextColor = ClosedLabel.TextColor;
                    }
                    else
                    {
                        OpenLabel.TextColor = Color.Gray;
                    }

                    // Set the current map scale text.
                    ScaleLabel.Text = "Current map scale: 1:" + (int)MyMapView.MapScale;
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        private void OpenSwitchChanged(object sender, ToggledEventArgs e)
        {
            // Set the visibility of the sub layer.
            if (_openSublayer != null) _openSublayer.IsVisible = OpenSwitch.IsToggled;
        }

        private void ClosedSwitchChanged(object sender, ToggledEventArgs e)
        {
            // Set the visibility of the sub layer.
            if (_closedSublayer != null) _closedSublayer.IsVisible = ClosedSwitch.IsToggled;
        }
    }
}
XAML
<ContentPage
    x:Class="ArcGISRuntimeXamarin.Samples.ControlAnnotationSublayerVisibility.ControlAnnotationSublayerVisibility"
    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">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <esriUI:MapView
            x:Name="MyMapView"
            Grid.Row="0"
            Grid.RowSpan="2" />
        <Grid
            x:Name="StatusGrid"
            Grid.Row="0"
            BackgroundColor="#CC000000">
            <Label
                x:Name="ScaleLabel"
                Margin="5"
                HorizontalOptions="FillAndExpand"
                HorizontalTextAlignment="Center"
                Text="Current map scale: 1:"
                TextColor="White" />
        </Grid>
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Switch
                x:Name="OpenSwitch"
                Grid.Column="0"
                Margin="5"
                IsEnabled="False"
                IsToggled="True"
                Toggled="OpenSwitchChanged"
                WidthRequest="50" />
            <Label
                x:Name="OpenLabel"
                Grid.Column="1"
                Text="Open"
                VerticalTextAlignment="Center" />
        </Grid>
        <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Switch
                x:Name="ClosedSwitch"
                Grid.Column="0"
                Margin="5"
                IsEnabled="False"
                IsToggled="True"
                Toggled="ClosedSwitchChanged"
                WidthRequest="50" />
            <Label
                x:Name="ClosedLabel"
                Grid.Column="1"
                Text="Closed"
                VerticalTextAlignment="Center" />
        </Grid>
        <Label />
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
ControlAnnotationSublayerVisibilityUse annotation sublayers to gain finer control of annotation layer subtypes.