Skip to content

Commit

Permalink
Loading OSM buildings scene service
Browse files Browse the repository at this point in the history
- animated startup
- using material styles for UI
  • Loading branch information
esride-jts committed Nov 22, 2024
1 parent 6e1b8f3 commit 35bd5a3
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

#include "UrbanHeatAnalyzer.h"

#include "ArcGISSceneLayer.h"
#include "ArcGISTiledElevationSource.h"
#include "ArcGISVectorTiledLayer.h"
#include "AttributeListModel.h"
#include "Camera.h"
#include "CoreTypes.h"
#include "ElevationSourceListModel.h"
#include "Envelope.h"
Expand All @@ -36,10 +38,12 @@
#include "LayerListModel.h"
#include "MapTypes.h"
#include "OrderBy.h"
#include "Point.h"
#include "QueryParameters.h"
#include "Scene.h"
#include "SceneQuickView.h"
#include "ServiceFeatureTable.h"
#include "SpatialReference.h"
#include "Surface.h"
#include "VectorTileCache.h"
#include "Viewpoint.h"
Expand All @@ -55,13 +59,26 @@ UrbanHeatAnalyzer::UrbanHeatAnalyzer(QObject *parent /* = nullptr */)
: QObject(parent)
, m_scene(new Scene(BasemapStyle::OsmStandard, this))
{
// create a new scene layer from OSM Buildings rest service
ArcGISSceneLayer *osmSceneLayer = new ArcGISSceneLayer(
QUrl("https://basemaps3d.arcgis.com/arcgis/rest/services/"
"OpenStreetMap3D_Buildings_v1/SceneServer"),
this);
osmSceneLayer->setOpacity(0.75f);

// add the scene layer to the scene
m_scene->operationalLayers()->append(osmSceneLayer);

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

// add vector tile cache
// create a new vector tile cache from the exported vector tile package
VectorTileCache *tileCache = new VectorTileCache(
"/data/Germany/Bonn/heat_risk_index_bonn.vtpk",
this);
Expand All @@ -70,14 +87,52 @@ UrbanHeatAnalyzer::UrbanHeatAnalyzer(QObject *parent /* = nullptr */)
ArcGISVectorTiledLayer *tiledLayer = new ArcGISVectorTiledLayer(
tileCache,
this);
tiledLayer->setOpacity(0.33f);

connect(tiledLayer, &ArcGISVectorTiledLayer::doneLoading, this, [tiledLayer, this]()
{
Envelope layerExtent = tiledLayer->fullExtent();
Viewpoint viewpoint = Viewpoint(layerExtent);
m_sceneView->setViewpointAsync(viewpoint, 2.5);
//Envelope layerExtent = tiledLayer->fullExtent();
//Viewpoint viewpoint = Viewpoint(layerExtent);
//m_sceneView->setViewpointAsync(viewpoint, 2.5);
//m_sceneView->currentViewpointCamera();
//m_sceneView->setViewpointCameraAsync()

// Set the viewpoint on a specific target
Point targetLocation(7.11661 , 50.718 , 343.663, SpatialReference(4326));
Camera targetCamera(targetLocation, 93.2121 , 60.7764 , -5.68434e-14);
Viewpoint targetViewpoint(targetLocation, targetCamera);
if (m_sceneView)
{
m_sceneView->setViewpointAsync(targetViewpoint, 10);
}

//loadHeatRiskFeatures();
});
m_scene->operationalLayers()->append(tiledLayer);
}

UrbanHeatAnalyzer::~UrbanHeatAnalyzer() {}

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

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

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

emit sceneViewChanged();
}

void UrbanHeatAnalyzer::loadHeatRiskFeatures()
{
// add the features
Geodatabase *gdb = new Geodatabase(
"/data/Germany/Bonn/HRI Bonn.geodatabase",
Expand All @@ -103,8 +158,8 @@ UrbanHeatAnalyzer::UrbanHeatAnalyzer(QObject *parent /* = nullptr */)
auto queryResult = std::unique_ptr<FeatureQueryResult>(rawQueryResult);
if (queryResult && !queryResult->iterator().hasNext())
{
// No results or invalid pointer
return;
// No results or invalid pointer
return;
}

QMap<double, QList<Feature*>> analysisGroups;
Expand Down Expand Up @@ -143,27 +198,12 @@ UrbanHeatAnalyzer::UrbanHeatAnalyzer(QObject *parent /* = nullptr */)
featureTable->load();
});
gdb->load();

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

UrbanHeatAnalyzer::~UrbanHeatAnalyzer() {}

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

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

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

emit sceneViewChanged();
auto camera = m_sceneView->currentViewpointCamera();
auto location = camera.location();
qDebug() << location.x() << "," << location.y() << "," << location.z();
qDebug() << camera.heading() << "," << camera.pitch() << "," << camera.roll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
//
// See the Sample code usage restrictions document for further information.
//
// This "Urban Heat Analyzer" sample app is licensed as
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Additional permission under GNU GPL version 3 section 4 and 5
// If you modify this Program, or any covered work, by linking or combining
// it with ArcGIS Runtime for Qt (or a modified version of that library),
// containing parts covered by the terms of ArcGIS Runtime for Qt,
// the licensors of this Program grant you additional permission to convey the resulting work.
// See <https://developers.arcgis.com/qt/> for further information.
//

#ifndef URBANHEATANALYZER_H
#define URBANHEATANALYZER_H
Expand All @@ -33,10 +43,14 @@ class UrbanHeatAnalyzer : public QObject
explicit UrbanHeatAnalyzer(QObject *parent = nullptr);
~UrbanHeatAnalyzer() override;

Q_INVOKABLE void printCamera();

signals:
void sceneViewChanged();

private:
void loadHeatRiskFeatures();

Esri::ArcGISRuntime::SceneQuickView *sceneView() const;
void setSceneView(Esri::ArcGISRuntime::SceneQuickView *sceneView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@
//
// See the Sample code usage restrictions document for further information.
//
// This "Urban Heat Analyzer" sample app is licensed as
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Additional permission under GNU GPL version 3 section 4 and 5
// If you modify this Program, or any covered work, by linking or combining
// it with ArcGIS Runtime for Qt (or a modified version of that library),
// containing parts covered by the terms of ArcGIS Runtime for Qt,
// the licensors of this Program grant you additional permission to convey the resulting work.
// See <https://developers.arcgis.com/qt/> for further information.
//

import QtQuick
import QtQuick.Controls
import Esri.UrbanHeatAnalyzer

Item {

function printCamera() {
model.printCamera();
}

// Create SceneQuickView here, and create its Scene etc. in C++ code
SceneView {
id: view
Expand Down
43 changes: 43 additions & 0 deletions native-apps/urban-heat-analyzer/UrbanHeatAnalyzer/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,59 @@
//
// See the Sample code usage restrictions document for further information.
//
// This "Urban Heat Analyzer" sample app is licensed as
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Additional permission under GNU GPL version 3 section 4 and 5
// If you modify this Program, or any covered work, by linking or combining
// it with ArcGIS Runtime for Qt (or a modified version of that library),
// containing parts covered by the terms of ArcGIS Runtime for Qt,
// the licensors of this Program grant you additional permission to convey the resulting work.
// See <https://developers.arcgis.com/qt/> for further information.
//

import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts

import Esri.UrbanHeatAnalyzer

ApplicationWindow {
visible: true
width: 800
height: 600

Material.theme: Material.Dark
Material.accent: "#C9F2FF"
Material.background: "#0289C3"
Material.foreground: "#FFFFFF"
Material.primary: "#035799"

font.pixelSize: 14

footer: ToolBar {

RowLayout {
anchors.fill: parent

Label {
id: messageLabel
horizontalAlignment: Qt.AlignLeft
Layout.leftMargin: 15
Layout.fillWidth: true
text: qsTr("Analyzing urban heat risks...")
}

Button {
onClicked: {
mapForm.printCamera();
}
}
}
}

UrbanHeatAnalyzerForm {
id: mapForm
anchors.fill: parent
}
}

0 comments on commit 35bd5a3

Please sign in to comment.