Before loading the MobileScenePackage, it is important to first check if direct read is supported. The MobileScenePackage could contain certain data types that would require the data to be unpacked. For example, Scenes containing raster data will need to be unpacked.
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
// [WriteFile Name=OpenMobileScenePackage, Category=Scenes]// [Legal]// Copyright 2019 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"OpenMobileScenePackage.h"#include"Error.h"#include"MobileScenePackage.h"#include"Scene.h"#include"SceneQuickView.h"#include<QtCore/qglobal.h>#include<QStandardPaths>usingnamespace Esri::ArcGISRuntime;
// helper method to get cross platform data pathnamespace{
QString defaultDataPath(){
QString dataPath;
#ifdef Q_OS_IOS dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#else dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#endifreturn dataPath;
}
} // namespaceOpenMobileScenePackage::OpenMobileScenePackage(QObject* parent /* = nullptr */):
QObject(parent)
{
// create the MSPK data path// data is downloaded automatically by the sample viewer app. Instructions to download// separately are specified in the readme.const QString dataPath = defaultDataPath() + "/ArcGIS/Runtime/Data/mspk/philadelphia.mspk";
// connect to the Mobile Scene Package instance to know when errors occurconnect(MobileScenePackage::instance(), &MobileScenePackage::errorOccurred,
[](const Error& e)
{
if (e.isEmpty())
return;
qDebug() << QString("Error: %1 %2").arg(e.message(), e.additionalMessage());
});
// Create the Scene PackagecreateScenePackage(dataPath);
}
OpenMobileScenePackage::~OpenMobileScenePackage() = default;
voidOpenMobileScenePackage::init(){
// Register classes for QML qmlRegisterType<SceneQuickView>("Esri.Samples", 1, 0, "SceneView");
qmlRegisterType<OpenMobileScenePackage>("Esri.Samples", 1, 0, "OpenMobileScenePackageSample");
}
SceneQuickView* OpenMobileScenePackage::sceneView()const{
return m_sceneView;
}
// Set the view (created in QML)voidOpenMobileScenePackage::setSceneView(SceneQuickView* sceneView){
if (!sceneView || sceneView == m_sceneView)
{
return;
}
m_sceneView = sceneView;
// set the scene on the scene view to displayif (m_scene && m_sceneView)
m_sceneView->setArcGISScene(m_scene);
emit sceneViewChanged();
}
// Slot for handling when the package loadsvoidOpenMobileScenePackage::packageLoaded(const Error& e){
if (!e.isEmpty())
{
qDebug() << QString("Package load error: %1 %2").arg(e.message(), e.additionalMessage());
return;
}
if (m_scenePackage->scenes().isEmpty())
return;
// The package contains a list of scenes that could be show in a UI for selection.// For simplicity, obtain the first scene in the list of scenes m_scene = m_scenePackage->scenes().at(0);
// set the scene on the scene view to displayif (m_scene && m_sceneView)
m_sceneView->setArcGISScene(m_scene);
}
// create scene package and connect to signalsvoidOpenMobileScenePackage::createScenePackage(const QString& path){
m_scenePackage = newMobileScenePackage(path, this);
connect(m_scenePackage, &MobileScenePackage::doneLoading, this, &OpenMobileScenePackage::packageLoaded);
m_scenePackage->load();
}