ArcGIS Runtime SDK for .NET Samples

Map reference scale

Set a map reference scale

Loading

Code

<?xml version="1.0" encoding="utf-8"?>

<ContentPage 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"
             xmlns:resources="clr-namespace:Forms.Resources;assembly=ArcGISRuntime"
             x:Class="ArcGISRuntimeXamarin.Samples.MapReferenceScale.MapReferenceScale">
    <RelativeLayout>
        <esriUI:MapView x:Name="MyMapView" Style="{StaticResource MapWithFormStyle}"
                        BindingContext="{x:Reference Name=ResponsiveFormContainer}" />
        <resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
            <StackLayout>
                <Label Text="Choose a map reference scale:" />
                <!-- When the user's selection changes, the SelectedItem binding will apply the value to the Map's ReferenceScale property. -->
                <Picker x:Name="ReferenceScaleBox"
                        BindingContext="{x:Reference MyMapView}"
                        SelectedItem="{Binding Path=Map.ReferenceScale}"
                        ItemDisplayBinding="{Binding StringFormat='{0:n0}'}"
                        Margin="0,5,0,5" />
                <Label Text="Choose layers to apply scale to:" />
                <!-- Binding is used to display the operational layers for the map view's map, no code behind needed. -->
                <ListView BindingContext="{x:Reference MyMapView}"
                          ItemsSource="{Binding Path=Map.OperationalLayers}"
                          HeightRequest="125" SelectionMode="None"
                          Margin="0,5,0,5">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <!-- When the user interacts with the switch, 
                                 the two-way binding will update the ScaleSymbols (bool) property automatically. -->
                                <StackLayout Orientation="Horizontal">
                                    <Switch IsToggled="{Binding ScaleSymbols}" VerticalOptions="Center" />
                                    <Label Text="{Binding Name}" 
                                           VerticalOptions="Center" 
                                           HorizontalOptions="EndAndExpand"
                                           HorizontalTextAlignment="End"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <Label BindingContext="{x:Reference MyMapView}"
                       Text="{Binding Path=MapScale,Mode=OneWay,StringFormat='Current map scale: {0:n0}'}" />
            </StackLayout>
        </resources:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>


In this topic
  1. Code