Change viewpoint

View inQMLC++
View on GitHub
Sample viewer app

Set the map view to a new viewpoint.

screenshot

Use case

Programatically navigate to a specified location in the map or scene. Use this to focus on a particular point or area of interest.

How to use the sample

The map view has several methods for setting its current viewpoint. Select a viewpoint from the UI to see the viewpoint changed using that method.

How it works

  1. Create a new Map object and set it to the MapView object.
  2. Change the map's Viewpoint using one of the available methods:
  3. Use MapView::setViewpointAnimated(viewPoint, duration, AnimationCurve) to pan to a viewpoint over the specified length of time.
  4. Use MapView::setViewpointCenter() to center the viewpoint on a Point and set a distance from the ground using a scale.
  5. Use MapView::setViewpointGeometry() to set the viewpoint to a given Geometry.

Relevant API

  • AnimationCurve
  • Map
  • Geometry
  • MapView
  • Point
  • Viewpoint

Additional information

Below are some other ways to set a viewpoint:

  • setViewpoint
  • setViewpointCenter
  • setViewpointGeometry
  • setViewpointRotation
  • setViewpointScale

Tags

animate, extent, pan, rotate, scale, view, zoom

Sample Code

ChangeViewpoint.qmlChangeViewpoint.cppChangeViewpoint.h
                                                                         
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
// [WriteFile Name=ChangeViewpoint, Category=Maps]
// [Legal]
// 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.Samples 1.0

ChangeViewpointSample {
    id: changeViewpointSample
    width: 800
    height: 600

    // add a mapView component
    MapView {
        id: mapQuickView
        anchors.fill: parent
    }
    mapView: mapQuickView

    ComboBox {
        id: comboBoxViewpoint
        anchors {
            left: parent.left
            top: parent.top
            margins: 15
        }

        property int bestWidth: implicitWidth

        width: bestWidth + indicator.width + rightPadding + leftPadding

        model: [ "Center",
                 "Center and scale",
                 "Geometry",
                 "Geometry and padding",
                 "Rotation",
                 "Scale 1:5,000,000",
                 "Scale 1:10,000,000",
                 "Animation" ]

        onCurrentTextChanged: {
            // Call C++ invokable function to change the viewpoint
            changeViewpointSample.changeViewpoint(comboBoxViewpoint.currentText);
        }

        onModelChanged: {
            let w = bestWidth;
            for (let i = 0; i < comboBoxViewpoint.model.length; ++i) {
                metrics.text = comboBoxViewpoint.model[i];
                w = Math.max(w, metrics.width);
            }
            bestWidth = w;
        }

        TextMetrics {
            id: metrics
            font: comboBoxViewpoint.font
        }
    }
}

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