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
// [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
#include "ChangeViewpoint.h"
#include "Map.h"
#include "MapQuickView.h"
#include "Basemap.h"
#include "Point.h"
#include "SpatialReference.h"
#include "Envelope.h"
#include "Viewpoint.h"
#include "MapTypes.h"
#include "MapViewTypes.h"
#include "TaskWatcher.h"
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->setViewpointCenter(ptEsriHeadquarters);
}
else if (viewpoint == "Center and scale")
{
Point ptHawaii(-157.564, 20.677, SpatialReference(4236));
m_mapView->setViewpointCenter(ptHawaii, 4000000.0);
}
else if (viewpoint == "Geometry")
{
Envelope envBeijing(116.380, 39.920, 116.400, 39.940, SpatialReference(4236));
m_mapView->setViewpointGeometry(envBeijing);
}
else if (viewpoint == "Geometry and padding")
{
Envelope envBeijing(116.380, 39.920, 116.400, 39.940, SpatialReference(4236));
m_mapView->setViewpointGeometry(envBeijing, 200 * screenRatio());
}
else if (viewpoint == "Rotation")
{
m_rotationValue = (m_rotationValue + 45) % 360;
m_mapView->setViewpointRotation(m_rotationValue);
}
else if (viewpoint == "Scale 1:5,000,000")
{
m_mapView->setViewpointScale(5000000.0);
}
else if (viewpoint == "Scale 1:10,000,000")
{
m_mapView->setViewpointScale(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->setViewpointAnimated(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;
}