Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the sample for the 3d tiles layer #1662

Merged
merged 19 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// [WriteFile Name=Add3DTilesLayer, Category=Scenes]
// [Legal]
// Copyright 2023 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 "Add3DTilesLayer.h"

#include "AnalysisListModel.h"
#include "AnalysisOverlay.h"
#include "AnalysisOverlayListModel.h"
tanneryould marked this conversation as resolved.
Show resolved Hide resolved
#include "ArcGISTiledElevationSource.h"
#include "Basemap.h"
#include "Camera.h"
#include "ElevationSourceListModel.h"
#include "Layer.h"
#include "LayerListModel.h"
#include "LocationLineOfSight.h"
tanneryould marked this conversation as resolved.
Show resolved Hide resolved
#include "MapTypes.h"
#include "Ogc3dTilesLayer.h"
#include "Point.h"
#include <PortalItem.h>
tanneryould marked this conversation as resolved.
Show resolved Hide resolved
#include "Scene.h"
#include "SceneQuickView.h"
#include "SpatialReference.h"
#include "Surface.h"
#include "TransformationCatalog.h"
tanneryould marked this conversation as resolved.
Show resolved Hide resolved

#include <MapView.h>
#include <QDebug>
#include <QFuture>
#include <QStandardPaths>
#include <QString>
#include <QUrl>
#include <QVariantMap>
#include <QMap>

using namespace Esri::ArcGISRuntime;

const QString DATAPATH = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+ "/ArcGIS/Runtime/Data/";
tanneryould marked this conversation as resolved.
Show resolved Hide resolved

jingyili1023 marked this conversation as resolved.
Show resolved Hide resolved
Add3DTilesLayer::Add3DTilesLayer(QObject* parent /* = nullptr */):
QObject(parent),
m_scene(new Scene(BasemapStyle::ArcGISDarkGray, this))
{
// create a new elevation source from Terrain3D REST service
ArcGISTiledElevationSource* elevationSource = new ArcGISTiledElevationSource(
QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this);
// add projection
TransformationCatalog::setProjectionEngineDirectory(DATAPATH + "/pedata");
if (TransformationCatalog::projectionEngineDirectory().isEmpty())
qWarning() << ("Projection Engine Directory not found at: " + DATAPATH + "/pedata");
tanneryould marked this conversation as resolved.
Show resolved Hide resolved

// add the elevation source to the scene to display elevation
m_scene->baseSurface()->elevationSources()->append(elevationSource);

add3DTilesLayer();
}

Add3DTilesLayer::~Add3DTilesLayer() = default;

void Add3DTilesLayer::init()
{
// Register classes for QML
qmlRegisterType<SceneQuickView>("Esri.Samples", 1, 0, "SceneView");
qmlRegisterType<Add3DTilesLayer>("Esri.Samples", 1, 0, "Add3DTilesLayerSample");
}

SceneQuickView* Add3DTilesLayer::sceneView() const
{
return m_sceneView;
}

// Set the view (created in QML)
void Add3DTilesLayer::setSceneView(SceneQuickView* sceneView)
{
if (!sceneView || sceneView == m_sceneView)
return;

m_sceneView = sceneView;
m_sceneView->setArcGISScene(m_scene);

emit sceneViewChanged();

initialize();
}

void Add3DTilesLayer::initialize()
{
// add an Analysis Overlay
m_analysisOverlay = new AnalysisOverlay(this);
m_sceneView->analysisOverlays()->append(m_analysisOverlay);
// set initial viewpoint
setInitialViewpoint();
}
tanneryould marked this conversation as resolved.
Show resolved Hide resolved

void Add3DTilesLayer::add3DTilesLayer()
{
const QUrl modelPath = QUrl("https://tiles.arcgis.com/tiles/N82JbI5EYtAkuUKU/arcgis/rest/services/Stuttgart/3DTilesServer/tileset.json");
m_ogc3dTilesLayer = new Ogc3dTilesLayer(modelPath, this);
m_scene->operationalLayers()->append(m_ogc3dTilesLayer);
}

void Add3DTilesLayer::setInitialViewpoint()
{
// add a camera
constexpr double latitude = 48.84553;
constexpr double longitude = 9.16275;
constexpr double altitude = 350.0;
constexpr double heading = 0;
constexpr double pitch = 60;
constexpr double roll = 0.0;
const Camera sceneCamera(latitude, longitude, altitude, heading, pitch, roll);
m_sceneView->setViewpointCameraAndWait(sceneCamera);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// [WriteFile Name=Add3DTilesLayer, Category=Scenes]
// [Legal]
// Copyright 2023 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]

#ifndef ADD3DTILESLAYER_H
#define ADD3DTILESLAYER_H

namespace Esri::ArcGISRuntime
{
class Scene;
class SceneQuickView;
class Ogc3dTilesLayer;
class LocationLineOfSight;
class AnalysisOverlay;
tanneryould marked this conversation as resolved.
Show resolved Hide resolved
}

#include <QObject>

Q_MOC_INCLUDE("SceneQuickView.h");

class Add3DTilesLayer : public QObject
{
Q_OBJECT

Q_PROPERTY(Esri::ArcGISRuntime::SceneQuickView* sceneView READ sceneView WRITE setSceneView NOTIFY sceneViewChanged)

public:
explicit Add3DTilesLayer(QObject* parent = nullptr);
~Add3DTilesLayer() override;
static void init();

signals:
void sceneViewChanged();

jingyili1023 marked this conversation as resolved.
Show resolved Hide resolved
private:
Esri::ArcGISRuntime::SceneQuickView* sceneView() const;
void setSceneView(Esri::ArcGISRuntime::SceneQuickView* sceneView);

Esri::ArcGISRuntime::Scene* m_scene = nullptr;
Esri::ArcGISRuntime::SceneQuickView* m_sceneView = nullptr;

// add 3D tiles layer
Esri::ArcGISRuntime::Ogc3dTilesLayer* m_ogc3dTilesLayer = nullptr;
void add3DTilesLayer();

// add lineofsight analysis
Esri::ArcGISRuntime::LocationLineOfSight* m_lineOfSight = nullptr;
Esri::ArcGISRuntime::AnalysisOverlay* m_analysisOverlay = nullptr;
bool m_calculating = false;
void createLineOfSight();
void initialize();
tanneryould marked this conversation as resolved.
Show resolved Hide resolved
void setInitialViewpoint();
void connectSignals();
};

#endif // ADD3DTILESLAYER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#-------------------------------------------------
# Copyright 2023 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.
#-------------------------------------------------

mac {
cache()
}

#-------------------------------------------------------------------------------

CONFIG += c++17
#CONFIG+=build_from_setup

# additional modules are pulled in via arcgisruntime.pri
QT += opengl qml quick

TEMPLATE = app
TARGET = Add3DTilesLayer

ARCGIS_RUNTIME_VERSION = 200.4.0
include($$PWD/arcgisruntime.pri)

#-------------------------------------------------------------------------------

HEADERS += \
Add3DTilesLayer.h

SOURCES += \
main.cpp \
Add3DTilesLayer.cpp

RESOURCES += Add3DTilesLayer.qrc

#-------------------------------------------------------------------------------

win32 {
LIBS += \
Ole32.lib
}

ios {
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

OTHER_FILES += \
$$PWD/Info.plist

QMAKE_INFO_PLIST = $$PWD/Info.plist
}

android {
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// [WriteFile Name=Add3DTilesLayer, Category=Scenes]
// [Legal]
// Copyright 2023 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
import QtQuick.Controls
import Esri.Samples

Item {

SceneView {
id: view
anchors.fill: parent

Component.onCompleted: {
// Set and keep the focus on SceneView to enable keyboard navigation
forceActiveFocus();
}
}

// Declare the C++ instance which creates the scene etc. and supply the view
Add3DTilesLayerSample {
id: model
sceneView: view
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/Samples/Scenes/Add3DTilesLayer">
<file alias="sample.json">README.metadata.json</file>
<file>Add3DTilesLayer.qml</file>
<file>Add3DTilesLayer.h</file>
<file>Add3DTilesLayer.cpp</file>
<file>main.qml</file>
<file>screenshot.png</file>
<file>README.md</file>
</qresource>
</RCC>
55 changes: 55 additions & 0 deletions ArcGISRuntimeSDKQt_CppSamples/Scenes/Add3DTilesLayer/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Add3DTilesLayer</string>
<key>CFBundleExecutable</key>
<string>Add3DTilesLayer</string>
<key>CFBundleGetInfoString</key>
<string>ArcGIS</string>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>com.esri.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NOTE</key>
<string>This app is cool</string>
<key>UIFileSharingEnabled</key>
<string>FALSE</string>
<key>UIRequiresPersistentWiFi</key>
<string>NO</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
</dict>
</plist>

Loading
Loading