View on GitHub Sample viewer app
Set the map view to a new viewpoint.
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 sampleThe 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 worksMap
object and set it to the MapView
object.Viewpoint
using one of the available methods:MapView::setViewpointAsync(viewPoint, duration, AnimationCurve)
to pan to a viewpoint over the specified length of time.MapView::setViewpointCenterAsync()
to center the viewpoint on a Point
and set a distance from the ground using a scale.MapView::setViewpointGeometryAsync()
to set the viewpoint to a given Geometry
MapView::setViewpointRotationAsync()
to set the viewpoint to a given degree.MapView::setViewpointScaleAsync()
to set the viewpoint to a given scale.Below are some other ways to set a viewpoint:
animate, extent, pan, rotate, scale, view, zoom
Sample CodeChangeViewpoint.cpp ChangeViewpoint.cpp ChangeViewpoint.h ChangeViewpoint.qml
Use dark colors for code blocks Copy
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
// [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]
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
// sample headers
#include "ChangeViewpoint.h"
// ArcGIS Maps SDK headers
#include "Basemap.h"
#include "Envelope.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "MapViewTypes.h"
#include "Point.h"
#include "SpatialReference.h"
#include "Viewpoint.h"
// Qt headers
#include <QFuture>
using namespace Esri::ArcGISRuntime;
ChangeViewpoint::ChangeViewpoint(QQuickItem* parent) :
QQuickItem(parent)
{
}
ChangeViewpoint::~ChangeViewpoint() = default;
void ChangeViewpoint::init()
{
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<ChangeViewpoint>("Esri.Samples", 1, 0, "ChangeViewpointSample");
}
void ChangeViewpoint::componentComplete()
{
QQuickItem::componentComplete();
// create a new basemap instance
Basemap* basemap = new Basemap(BasemapStyle::ArcGISImagery, this);
// create a new map instance
m_map = new Map(basemap, this);
// set map on the map view
m_mapView->setMap(m_map);
}
void ChangeViewpoint::changeViewpoint(QString viewpoint)
{
if (viewpoint == "Center")
{
Point ptEsriHeadquarters(-117.195681,34.056218, SpatialReference(4326));
m_mapView->setViewpointCenterAsync(ptEsriHeadquarters);
}
else if (viewpoint == "Center and scale")
{
Point ptHawaii(-157.564, 20.677, SpatialReference(4236));
m_mapView->setViewpointCenterAsync(ptHawaii, 4000000.0);
}
else if (viewpoint == "Geometry")
{
Envelope envBeijing(116.380, 39.920, 116.400, 39.940, SpatialReference(4236));
m_mapView->setViewpointGeometryAsync(envBeijing);
}
else if (viewpoint == "Geometry and padding")
{
Envelope envBeijing(116.380, 39.920, 116.400, 39.940, SpatialReference(4236));
m_mapView->setViewpointGeometryAsync(envBeijing, 200 * screenRatio());
}
else if (viewpoint == "Rotation")
{
m_rotationValue = (m_rotationValue + 45) % 360;
m_mapView->setViewpointRotationAsync(m_rotationValue);
}
else if (viewpoint == "Scale 1:5,000,000")
{
m_mapView->setViewpointScaleAsync(5000000.0);
}
else if (viewpoint == "Scale 1:10,000,000")
{
m_mapView->setViewpointScaleAsync(10000000.0);
}
else if (viewpoint == "Animation")
{
//! [set viewpoint api snippet]
constexpr double xMin = -12338668.348591767;
constexpr double yMin = 5546908.424239618;
constexpr double xMax = -12338247.594362013;
constexpr double yMax = 5547223.989911933;
constexpr int wkid = 102100;
Viewpoint vpSpring(Envelope(xMin, yMin, xMax, yMax, SpatialReference(wkid)));
constexpr float duration = 4.0f;
m_mapView->setViewpointAsync(vpSpring, duration, AnimationCurve::EaseInOutCubic);
//! [set viewpoint api snippet]
}
}
MapQuickView* ChangeViewpoint::mapQuickView() const
{
return m_mapView;
}
void ChangeViewpoint::setMapQuickView(MapQuickView* mapView)
{
m_mapView = mapView;
emit mapQuickViewChanged();
}
double ChangeViewpoint::screenRatio() const
{
const double width = static_cast<double>(m_mapView->width());
const double height = static_cast<double>(m_mapView->height());
return height > width ? width / height : height / width;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4