Click or drag to resize

MapViewSetViewpointScaleAsync Method

Zooms to the given scale.

Namespace:  Esri.ArcGISRuntime.UI.Controls
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.6.0.0
Syntax
public Task<bool> SetViewpointScaleAsync(
	double scale
)

Parameters

scale
Type: SystemDouble
The scale to zoom to, ie '50000' to zoom to 1:50,000 scale.

Return Value

Type: TaskBoolean
True if the zoom animation completed, false if it was interrupted by another view navigation.
Examples

WPF

Example Name: ChangeViewpoint

Set the map view to a new viewpoint.

Code example screen shot.

C#
// Copyright 2016 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.Mapping;
using Esri.ArcGISRuntime.Geometry;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.WPF.Samples.ChangeViewpoint
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Change viewpoint",
        "MapView",
        "This sample demonstrates different ways in which you can change the viewpoint of the MapView.",
        "Click any of the available buttons to change the current viewpoint")]
    public partial class ChangeViewpoint
    {
        // Coordinates for London
        private MapPoint _londonCoords = new MapPoint(
            -13881.7678417696, 6710726.57374296, SpatialReferences.WebMercator);

        private double _londonScale = 8762.7156655228955;

        // Coordinates for Redlands
        private Polygon _redlandsEnvelope = new Polygon(new List<MapPoint>
            {
                new MapPoint(-13049785.1566222, 4032064.6003424),
                new MapPoint(-13049785.1566222, 4040202.42595729),
                new MapPoint(-13037033.5780234, 4032064.6003424),
                new MapPoint(-13037033.5780234, 4040202.42595729)
            },
            SpatialReferences.WebMercator);

        // Coordinates for Edinburgh
        private Polygon _edinburghEnvelope = new Polygon(new List<MapPoint>
            {
                new MapPoint(-354262.156621384, 7548092.94093301),
                new MapPoint(-354262.156621384, 7548901.50684376),
                new MapPoint(-353039.164455303, 7548092.94093301),
                new MapPoint(-353039.164455303, 7548901.50684376)
            },
            SpatialReferences.WebMercator);

        public ChangeViewpoint()
        {
            InitializeComponent();
        }

        private async void OnButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get content from the selected item
                Button myButton = (Button)sender;

                switch (myButton.Content.ToString())
                {
                    case "Geometry":

                        // Set Viewpoint using Redlands envelope defined above and a padding of 20
                        await MyMapView.SetViewpointGeometryAsync(_redlandsEnvelope, 20);
                        break;

                    case "Center and scale":

                        // Set Viewpoint so that it is centered on the London coordinates defined above
                        await MyMapView.SetViewpointCenterAsync(_londonCoords);

                        // Set the Viewpoint scale to match the specified scale 
                        await MyMapView.SetViewpointScaleAsync(_londonScale);
                        break;

                    case "Animate":

                        // Navigate to full extent of the first baselayer before animating to specified geometry
                        await MyMapView.SetViewpointAsync(
                            new Viewpoint(Basemap.FullExtent));

                        // Create a new Viewpoint using the specified geometry
                        Viewpoint viewpoint = new Viewpoint(_edinburghEnvelope);

                        // Set Viewpoint of MapView to the Viewpoint created above and animate to it using a timespan of 5 seconds
                        await MyMapView.SetViewpointAsync(viewpoint, TimeSpan.FromSeconds(5));
                        break;

                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
    }
}
XAML
<UserControl
    x:Class="ArcGISRuntime.WPF.Samples.ChangeViewpoint.ChangeViewpoint"
    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">
    <UserControl.Resources>
        <Style TargetType="Button">
            <Setter Property="Padding" Value="5" />
            <Setter Property="Margin" Value="5,5,0,0" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <esri:MapView x:Name="MyMapView">
            <esri:Map>
                <esri:ArcGISTiledLayer x:Name="Basemap"
                                       Source="https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
            </esri:Map>
        </esri:MapView>
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="Use the buttons to set the viewpoint."
                           Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
                           HorizontalAlignment="Center" TextWrapping="Wrap"
                           FontWeight="SemiBold"/>
                <Button Content="Geometry"
                        Grid.Row="1" Grid.Column="0"
                        Margin="0,5,0,0"
                        ToolTip="Sets Viewpoint to a predefined Polygon's extent"
                        Click="OnButtonClick" />
                <Button Content="Center and scale"
                        Grid.Row="1" Grid.Column="1"
                        ToolTip="Sets Viewpoint a predefined point and scale"
                        Click="OnButtonClick" />
                <Button Content="Animate"
                        Grid.Row="1" Grid.Column="2"
                        ToolTip="Sets Viewpoint and animate repositioning of view"
                        Click="OnButtonClick" />
            </Grid>
        </Border>
    </Grid>
</UserControl>
See Also
Additional Examples
Hyperlink to ExampleDescription
Animate3DGraphicAn `OrbitGeoElementCameraController` follows a graphic while the graphic's position and rotation are animated.
ChangeViewpointSet the map view to a new viewpoint.