Map reference scale

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Set the map's reference scale and which feature layers should honor the reference scale.

Image of map reference scale

Use case

Setting a reference scale on a Map fixes the size of symbols and text to the desired height and width at that scale. As you zoom in and out, symbols and text will increase or decrease in size accordingly. When no reference scale is set, symbol and text sizes remain the same size relative to the MapView.

Map annotations are typically only relevant at certain scales. For instance, annotations to a map showing a construction site are only relevant at that construction site's scale. So, when the map is zoomed out that information shouldn't scale with the MapView, but should instead remain scaled with the Map.

How to use the sample

Use the control at the top to set the map's reference scale (1:500,000 1:250,000 1:100,000 1:50,000). Use the menu checkboxes in the layer menu to set which feature layers should honor the reference scale.

How it works

  1. Get and set the reference scale property on the Map object.
  2. Get and set the scale symbols property on each individual FeatureLayer object.

Relevant API

  • Map
  • FeatureLayer

Additional information

The map reference scale should normally be set by the map's author and not exposed to the end user like it is in this sample.

Tags

map, reference scale, scene

Sample Code

MapReferenceScale.cs
Use dark colors for code blocksCopy
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// 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.Portal;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;

namespace ArcGISRuntimeXamarin.Samples.MapReferenceScale
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Map reference scale",
        category: "Map",
        description: "Set the map's reference scale and which feature layers should honor the reference scale.",
        instructions: "Use the control at the top to set the map's reference scale (1:500,000 1:250,000 1:100,000 1:50,000). Use the menu checkboxes in the layer menu to set which feature layers should honor the reference scale.",
        tags: new[] { "map", "reference scale", "scene" })]
    public class MapReferenceScale : Activity
    {
        // Hold references to the UI controls.
        private MapView _myMapView;
        private TextView _currentScaleLabel;
        private TextView _referenceScaleSelectionLabel;
        private Button _layersButton;

        // List of reference scale options.
        private readonly double[] _referenceScales =
        {
            50000,
            100000,
            250000,
            500000
        };

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

            Title = "Map reference scale";

            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a portal and an item; the map will be loaded from portal item.
            ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri("https://runtime.maps.arcgis.com"));
            PortalItem mapItem = await PortalItem.CreateAsync(portal, "3953413f3bd34e53a42bf70f2937a408");

            // Create the map from the item.
            Map webMap = new Map(mapItem);

            // Update the UI when the map navigates.
            _myMapView.ViewpointChanged += (o, e) => _currentScaleLabel.Text = $"Current map scale: 1:{_myMapView.MapScale:n0}";

            // Display the map.
            _myMapView.Map = webMap;

            // Wait for the map to load.
            await webMap.LoadAsync();

            // Enable the button now that the map is ready.
            _layersButton.Enabled = true;
        }

        private void ChooseScale_Clicked(object sender, EventArgs e)
        {
            try
            {
                Button scaleButton = (Button) sender;

                // Create menu for showing layer controls.
                PopupMenu sublayersMenu = new PopupMenu(this, scaleButton);
                sublayersMenu.MenuItemClick += ScaleSelection_Changed;

                // Create menu options.
                int index = 0;
                foreach (double scale in _referenceScales)
                {
                    // Add the menu item.
                    sublayersMenu.Menu.Add(0, index, index, $"1:{scale:n0}");
                    index++;
                }

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

        private void ScaleSelection_Changed(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            // Find the index of the selected scale.
            int selectionIndex = e.Item.Order;

            // Apply the selected scale.
            _myMapView.Map.ReferenceScale = _referenceScales[selectionIndex];

            // Update the UI.
            _referenceScaleSelectionLabel.Text = $"1:{_referenceScales[selectionIndex]:n0}";
        }

        private void ChooseLayers_Clicked(object sender, EventArgs e)
        {
            try
            {
                Button layersButton = (Button) sender;

                // Create menu for showing layer controls.
                PopupMenu sublayersMenu = new PopupMenu(this, layersButton);
                sublayersMenu.MenuItemClick += LayerScaleSelection_Changed;

                // Create menu options.
                int index = 0;
                foreach (FeatureLayer layer in _myMapView.Map.OperationalLayers.OfType<FeatureLayer>())
                {
                    // Add the menu item.
                    sublayersMenu.Menu.Add(0, index, index, layer.Name);

                    // Configure the menu item.
                    sublayersMenu.Menu.GetItem(index).SetCheckable(true).SetChecked(layer.ScaleSymbols);

                    index++;
                }

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

        private void LayerScaleSelection_Changed(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            // Get the checked item.
            int selectedLayerIndex = e.Item.Order;

            // Find the layer.
            FeatureLayer selectedLayer = _myMapView.Map.OperationalLayers.OfType<FeatureLayer>().ElementAt(selectedLayerIndex);

            // Set the symbol scale mode.
            selectedLayer.ScaleSymbols = !selectedLayer.ScaleSymbols;

            // Update the UI.
            e.Item.SetChecked(selectedLayer.ScaleSymbols);
        }

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

            // Button for choosing the map's reference scale.
            Button chooseScaleButton = new Button(this);
            chooseScaleButton.Text = "Choose map reference scale";
            chooseScaleButton.Click += ChooseScale_Clicked;
            layout.AddView(chooseScaleButton);

            // Label for showing current reference scale.
            _referenceScaleSelectionLabel = new TextView(this);
            _referenceScaleSelectionLabel.Text = "Choose a reference scale";
            layout.AddView(_referenceScaleSelectionLabel);

            // Button for selecting which layers will have symbol scaling enabled.
            _layersButton = new Button(this);
            _layersButton.Text = "Manage scaling for layers";
            _layersButton.Click += ChooseLayers_Clicked;
            layout.AddView(_layersButton);

            // Add a horizontal line separator.
            View separatorView = new View(this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1);
            separatorView.LayoutParameters = lp;
            layout.AddView(separatorView);

            // Add a label that shows the current map scale.
            _currentScaleLabel = new TextView(this);
            _currentScaleLabel.Text = "Current map scale: ";
            layout.AddView(_currentScaleLabel);

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

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

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.