Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Map reference scale

This code sample is available for these platforms:
View Sample on GitHub

Set a map's reference scale and control which feature layers should honor that scale.

Map Reference Scale App

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 selection box to set the map's reference scale (1:500,000 1:250,000 1:100,000 1:50,000).
  • Use the list to choose which layers participate in symbol scaling.

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

Maps & Scenes, reference, annotation, scale

Sample Code

using System;
using Windows.UI.Xaml.Data;

namespace ArcGISRuntime.UWP.Samples.MapReferenceScale
{
    class DoubleToScaleStringConverter : IValueConverter
    {
        // Converts a double to a string
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            return $"1:{value:n0}";
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
<UserControl
    x:Class="ArcGISRuntime.UWP.Samples.MapReferenceScale.MapReferenceScale"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls"
    xmlns:mapping="using:Esri.ArcGISRuntime.Mapping"
    xmlns:local="using:ArcGISRuntime.UWP.Samples.MapReferenceScale">
    <UserControl.Resources>
        <local:DoubleToScaleStringConverter x:Key="DoubleToScaleStringConverter" />
    </UserControl.Resources>
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock Text="Choose a map reference scale:"
                           FontWeight="SemiBold" />
                <!-- When the user's selection changes, the SelectedItem binding will apply the value to the Map's ReferenceScale property. -->
                <ComboBox x:Name="ReferenceScaleBox"
                          SelectedItem="{Binding ElementName=MyMapView, Path=Map.ReferenceScale, Mode=TwoWay}"
                          HorizontalAlignment="Stretch"
                          Margin="0,5,0,5">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <!-- The value converter converts from a double to a string that looks like a map scale. -->
                            <TextBlock Text="{Binding Converter={StaticResource DoubleToScaleStringConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Text="Choose layers to apply scale to:"
                           FontWeight="SemiBold" />
                <!-- Binding is used to display the operational layers for the map view's map, no code behind needed. -->
                <ListView ItemsSource="{Binding ElementName=MyMapView,Path=Map.OperationalLayers}"
                          Margin="0,5,0,5"
                          SelectionMode="None">
                    <ListView.ItemTemplate>
                        <DataTemplate x:DataType="mapping:FeatureLayer">
                            <!-- When the user interacts with the checkbox, 
                                 the two-way binding will update the ScaleSymbols (bool) property automatically. -->
                            <CheckBox Content="{Binding Name}" IsChecked="{Binding ScaleSymbols, Mode=TwoWay}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <TextBlock>
                    <Run Text="Current map scale: " />
                    <Run
                        Text="{Binding ElementName=MyMapView,Path=MapScale,Mode=OneWay,Converter={StaticResource DoubleToScaleStringConverter}}" />
                </TextBlock>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
// 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 Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Offline;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.ArcGISServices;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;
using Windows.UI.Xaml.Controls;
using Esri.ArcGISRuntime.Portal;

namespace ArcGISRuntime.UWP.Samples.MapReferenceScale
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Map reference scale",
        "Map",
        "Set a map's reference scale and control which feature layers honor that scale.",
        "")]
    [ArcGISRuntime.Samples.Shared.Attributes.ClassFile("Converters/DoubleToScaleStringConverter")]
    public partial class MapReferenceScale
    {
        // List of reference scale options.
        private readonly double[] _referenceScales =
        {
            50000,
            100000,
            250000,
            500000
        };

        public MapReferenceScale()
        {
            InitializeComponent();
            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);

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

            // Populate the reference scale choices.
            ReferenceScaleBox.ItemsSource = _referenceScales;

            // NOTE: this sample uses binding, so explicit control of reference scale isn't seen here.
            // See the iOS or Android samples for an implementation that does not rely on data binding.
        }
    }
}