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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// [WriteFile Name=LocalServerFeatureLayer, Category=LocalServer]// [Legal]// Copyright 2017 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"LocalServerFeatureLayer.h"#include"Basemap.h"#include"Envelope.h"#include"MapQuickView.h"#include"Map.h"#include"LocalServer.h"#include"LocalFeatureService.h"#include"ServiceFeatureTable.h"#include"FeatureLayer.h"#include"Viewpoint.h"#include"MapViewTypes.h"#include"MapTypes.h"#include"LocalServerTypes.h"#include"TaskWatcher.h"#include"LayerListModel.h"#include<QDir>#include<QTemporaryDir>#include<QFile>usingnamespace Esri::ArcGISRuntime;
LocalServerFeatureLayer::LocalServerFeatureLayer(QQuickItem* parent) :
QQuickItem(parent)
{
// Create a temporary directory for the local server if one has not already been createdif (!LocalServer::appDataPath().isEmpty() && !LocalServer::tempDataPath().isEmpty())
return;
// create temp/data pathconst QString tempPath = LocalServerFeatureLayer::shortestTempPath() + "/EsriQtTemp";
// create the directory m_tempDir = std::make_unique<QTemporaryDir>(tempPath);
// set the temp & app data path for the local server LocalServer::instance()->setTempDataPath(m_tempDir->path());
LocalServer::instance()->setAppDataPath(m_tempDir->path());
}
LocalServerFeatureLayer::~LocalServerFeatureLayer() = default;
voidLocalServerFeatureLayer::init(){
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<LocalServerFeatureLayer>("Esri.Samples", 1, 0, "LocalServerFeatureLayerSample");
}
voidLocalServerFeatureLayer::componentComplete(){
QQuickItem::componentComplete();
// find QML MapView component m_mapView = findChild<MapQuickView*>("mapView");
m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);
// Create a map using the topographic BaseMap m_map = newMap(BasemapStyle::ArcGISTopographic, this);
// Set map to map view m_mapView->setMap(m_map);
// Check for ArcGIS Pro map package filesconst QString fileName = "PointsofInterest.mpkx";
const QString dataPath = QDir::homePath() + "/ArcGIS/Runtime/Data/mpkx/" + fileName;
// Check to see if map package existsif (!QFile::exists(dataPath))
{
qDebug() << "ArcGIS Pro .mpkx file not found at" << dataPath;
}
// create a feature service m_localFeatureService = newLocalFeatureService(dataPath, this);
if (LocalServer::instance()->isInstallValid())
{
connectSignals();
if (LocalServer::status() == LocalServerStatus::Started)
{
qDebug() << "Local server was already running";
// The local server can already be running if it was started in a different application.// We start up the local feature service here because there will be no status change signal to otherwise trigger it.startFeatureService();
}
elseif (LocalServer::status() != LocalServerStatus::Starting)
{
LocalServer::start();
}
}
elseqDebug() << "Local server install invalid";
}
voidLocalServerFeatureLayer::connectSignals(){
// Local server statusconnect(LocalServer::instance(), &LocalServer::statusChanged, this, [this]()
{
// If the local server was not previously running, our local feature service will start here if the local server has successfully started.if (LocalServer::status() == LocalServerStatus::Started)
{
startFeatureService();
}
});
// local feature service statusconnect(m_localFeatureService, &LocalFeatureService::statusChanged, this, [this]()
{
if (m_localFeatureService->status() == LocalServerStatus::Starting)
{
qDebug() << "Local feature service starting up";
}
elseif (m_localFeatureService->status() == LocalServerStatus::Started)
{
qDebug() << "Successfully hosting local feature service at:" << m_localFeatureService->url().toString();
// create the feature layer ServiceFeatureTable* svt = newServiceFeatureTable(QUrl(m_localFeatureService->url().toString() + "/0"), this);
FeatureLayer* featureLayer = newFeatureLayer(svt, this);
connect(featureLayer, &FeatureLayer::loadStatusChanged, this, [this, featureLayer](LoadStatus status)
{
if (status == LoadStatus::Loaded)
{
m_mapView->setViewpoint(Viewpoint(featureLayer->fullExtent()));
}
});
m_map->operationalLayers()->append(featureLayer);
}
elseif (m_localFeatureService->status() == LocalServerStatus::Failed)
{
qDebug() << "Local feature service failed to start";
}
});
}
voidLocalServerFeatureLayer::startFeatureService()const{
if (m_localFeatureService->status() != LocalServerStatus::Started || m_localFeatureService->status() != LocalServerStatus::Starting)
m_localFeatureService->start();
}
QString LocalServerFeatureLayer::shortestTempPath(){
// get tmp and home pathsconst QString tmpPath = QDir::tempPath();
const QString homePath = QDir::homePath();
// return whichever is shorter, temp or home pathif (homePath.length() > tmpPath.length())
return tmpPath;
elsereturn homePath;
}