Use annotation sublayers to gain finer control of annotation layer subtypes.
Use case
Annotation, which differs from labels by having a fixed place and size, is typically only relevant at particular scales. Annotation sublayers allow for finer control of annotation by allowing properties (like visibility in the map and legend) to be set and others to be read (like name) on subtypes of an annotation layer.
An annotation dataset which marks valves as "Opened" or "Closed", might be set to display the "Closed" valves over a broader range of scales than the "Opened" valves, if the "Closed" data is considered more relevant by the map's author. Regardless, the user can be given a manual option to set visibility of annotation sublayers on and off, if required.
How to use the sample
Start the sample and take note of the visibility of the annotation. Zoom in and out to see the annotation turn on and off based on scale ranges set on the data.
Use the checkboxes to manually set "Open" and "Closed" annotation sublayers visibility to on or off.
How it works
- Load a
MobileMapPackage
that containsAnnotationSublayer
. - Get the sublayers from the map package's layers by calling
Sublayer.SublayerContents
. - You can toggle the visibility of each sublayer manually using the
Sublayer.IsVisible
property. - To determine if a sublayer is visible at the current scale of the
MapView
, useSublayer.IsVisibleAtScale(MapView.Scale)
, by passing in the map's current scale.
Relevant API
- AnnotationLayer
- AnnotationSublayer
- LayerContent
Offline data
This sample uses Gas Device Anno Mobile Map Package. It is downloaded from ArcGIS Online automatically before the sample runs.
About the data
The scale ranges were set by the map's author using ArcGIS Pro:
- The "Open" annotation sublayer has its maximum scale set to 1:500 and its minimum scale set to 1:2000.
- The "Closed" annotation sublayer has no minimum or maximum scales set, so will be drawn at all scales.
Tags
annotation, scale, text, utilities, visualization
Sample Code
<UserControl x:Class="ArcGISRuntime.WPF.Samples.ControlAnnotationSublayerVisibility.ControlAnnotationSublayerVisibility"
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" />
<Border Style="{StaticResource BorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="OpenCheckBox"
Grid.Column="0"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Checked="OpenCheckBoxChanged"
IsChecked="True"
IsEnabled="False"
Unchecked="OpenCheckBoxChanged">
<Label x:Name="OpenLabel"
Grid.Column="1"
Content="Open" />
</CheckBox>
</Grid>
<Grid Grid.Row="1" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="ClosedCheckBox"
Grid.Column="0"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Checked="ClosedCheckBoxChanged"
IsChecked="True"
IsEnabled="False"
Unchecked="ClosedCheckBoxChanged">
<Label x:Name="ClosedLabel"
Grid.Column="1"
Content="Closed" />
</CheckBox>
</Grid>
<Label x:Name="ScaleLabel"
Grid.Row="2"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Content="Current map scale: 1:" />
</Grid>
</Border>
</Grid>
</UserControl>