-
Notifications
You must be signed in to change notification settings - Fork 521
/
ControlAnnotationSublayerVisibility.xaml.cs
101 lines (86 loc) · 4.42 KB
/
ControlAnnotationSublayerVisibility.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2022 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 ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
namespace ArcGIS.Samples.ControlAnnotationSublayerVisibility
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Control annotation sublayer visibility",
category: "Layers",
description: "Use annotation sublayers to gain finer control of annotation layer subtypes.",
instructions: "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.",
tags: new[] { "annotation", "scale", "text", "utilities", "visualization" })]
[ArcGIS.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 Task 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 = Colors.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;
}
}
}