Skip to content

Commit

Permalink
Add the sample for 3d tiles layer (#1662)
Browse files Browse the repository at this point in the history
Co-authored-by: Tanner Yould <tyould@esri.com>
  • Loading branch information
jingyili1023 and tanneryould authored Apr 4, 2024
1 parent 1d3af1f commit 1d21ba7
Show file tree
Hide file tree
Showing 14 changed files with 545 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// [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 "ArcGISTiledElevationSource.h"
#include "Basemap.h"
#include "Camera.h"
#include "ElevationSourceListModel.h"
#include "Layer.h"
#include "LayerListModel.h"
#include "MapTypes.h"
#include "Ogc3dTilesLayer.h"
#include "Scene.h"
#include "SceneQuickView.h"
#include "Surface.h"

using namespace Esri::ArcGISRuntime;

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 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();

setInitialViewpoint();
}

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.8418;
constexpr double longitude = 9.1536;
constexpr double altitude = 1325.0;
constexpr double heading = 48.3497;
constexpr double pitch = 57.8414;
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,59 @@
// [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;
}

#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();

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();

void setInitialViewpoint();
};

#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>

34 changes: 34 additions & 0 deletions ArcGISRuntimeSDKQt_CppSamples/Scenes/Add3DTilesLayer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Add 3D tiles layer

Add a layer to visualize 3D tiles data that conforms to the OGC 3D Tiles specification.

![](screenshot.png)

## Use case

One possible use case could be is that when added to a scene, a 3D tiles layer can assist in performing visual analysis, such as line of sight analysis. A [line of sight analysis](https://developers.arcgis.com/documentation/mapping-apis-and-services/spatial-analysis/tutorials/apis/display-a-line-of-sight/) can be used to assess whether a view is obstructed between an observer and a target.

## How to use the sample

When loaded, the sample will display a scene with an `Ogc3DTilesLayer`. Pan around and zoom in to observe the scene of the `Ogc3DTilesLayer`. Notice how the layer's level of detail changes as you zoom in and out from the layer.

## How it works

1. Create a scene.
2. Create an `Ogc3DTilesLayer` with the URL to a 3D tiles layer service.
3. Add the layer to the scene's operational layers.

## Relevant API

* Ogc3DTilesLayer
* SceneView

## About the data

A layer to visualize 3D tiles data that conforms to the OGC 3D Tiles specification. As of 200.4, it supports analyses like viewshed and line of sight, but does not support other operations like individual feature identification.

The 3D Tiles Open Geospatial Consortium (OGC) specification defines a spatial data structure and a set of tile formats designed for streaming and rendering 3D geospatial content. A 3D Tiles data set, known as a tileset, defines one or more tile formats organized into a hierarchical spatial data structure. For more information, see the [OGC 3D Tiles specification](https://www.ogc.org/standard/3DTiles).

## Tags

3d tiles, layers, OGC, OGC API, scene, service
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"category": "Scenes",
"description": "Add a layer to visualize 3D tiles data that conforms to the OGC 3D Tiles specification.",
"featured": true,
"ignore": false,
"images": [
"screenshot.png"
],
"keywords": [
"3D tiles",
"layers",
"OGC",
"OGC API",
"scene",
"service"
],
"redirect_from": [
""
],
"relevant_apis": [
"Ogc3dTilesLayer",
"SceneView"
],
"snippets": [
"Add3DTilesLayer.cpp",
"Add3DTilesLayer.h",
"Add3DTilesLayer.qml"
],
"title": "Add a 3D Tiles Layer"
}
Loading

0 comments on commit 1d21ba7

Please sign in to comment.