From 9632aa11827ee8cdf58be888ae5bf52eb812f1d3 Mon Sep 17 00:00:00 2001 From: Jason Beverage Date: Fri, 15 Sep 2023 13:08:51 -0400 Subject: [PATCH] Actually using the token if it's specified in the cesium layers instead of always relying on the environment variable. --- src/osgEarthCesium/CesiumLayer.cpp | 12 ++++++++++-- src/osgEarthCesium/CesiumTilesetNode | 4 ++-- src/osgEarthCesium/CesiumTilesetNode.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/osgEarthCesium/CesiumLayer.cpp b/src/osgEarthCesium/CesiumLayer.cpp index b3096e9e6c..22594d8a22 100644 --- a/src/osgEarthCesium/CesiumLayer.cpp +++ b/src/osgEarthCesium/CesiumLayer.cpp @@ -19,6 +19,7 @@ * along with this program. If not, see */ #include "CesiumLayer" +#include "Settings" #include @@ -80,6 +81,13 @@ CesiumNative3DTilesLayer::openImplementation() osg::ref_ptr< osgDB::Options > readOptions = osgEarth::Registry::instance()->cloneOrCreateOptions(this->getReadOptions()); + std::string token = options().token().get(); + if (token.empty()) + { + token = getCesiumIonKey(); + + } + if (_options->url().isSet()) { std::vector overlays; @@ -87,7 +95,7 @@ CesiumNative3DTilesLayer::openImplementation() { overlays.push_back(*_options->rasterOverlay()); } - _tilesetNode = new CesiumTilesetNode(_options->url()->full(), *_options->maximumScreenSpaceError(), overlays); + _tilesetNode = new CesiumTilesetNode(_options->url()->full(), token, *_options->maximumScreenSpaceError(), overlays); } else if (_options->assetId().isSet()) { @@ -96,7 +104,7 @@ CesiumNative3DTilesLayer::openImplementation() { overlays.push_back(*_options->rasterOverlay()); } - _tilesetNode = new CesiumTilesetNode(*_options->assetId(), *_options->maximumScreenSpaceError(), overlays); + _tilesetNode = new CesiumTilesetNode(*_options->assetId(), token, *_options->maximumScreenSpaceError(), overlays); } if (!_tilesetNode.valid()) diff --git a/src/osgEarthCesium/CesiumTilesetNode b/src/osgEarthCesium/CesiumTilesetNode index 3f5a9347f3..628c5c0f5d 100644 --- a/src/osgEarthCesium/CesiumTilesetNode +++ b/src/osgEarthCesium/CesiumTilesetNode @@ -32,8 +32,8 @@ namespace osgEarth { namespace Cesium class OSGEARTHCESIUM_EXPORT CesiumTilesetNode : public osg::Group { public: - CesiumTilesetNode(unsigned int assetID, float maximumScreenSpaceError = 16.0f, std::vector overlays = std::vector()); - CesiumTilesetNode(const std::string& url, float maximumScreenSpaceError = 16.0f, std::vector overlays = std::vector()); + CesiumTilesetNode(unsigned int assetID, const std::string& token = "", float maximumScreenSpaceError = 16.0f, std::vector overlays = std::vector()); + CesiumTilesetNode(const std::string& url, const std::string& token = "", float maximumScreenSpaceError = 16.0f, std::vector overlays = std::vector()); ~CesiumTilesetNode(); diff --git a/src/osgEarthCesium/CesiumTilesetNode.cpp b/src/osgEarthCesium/CesiumTilesetNode.cpp index 92c3f9fa0d..97948307ae 100644 --- a/src/osgEarthCesium/CesiumTilesetNode.cpp +++ b/src/osgEarthCesium/CesiumTilesetNode.cpp @@ -29,7 +29,7 @@ using namespace osgEarth::Cesium; -CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, float maximumScreenSpaceError, std::vector overlays) +CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, const std::string& token, float maximumScreenSpaceError, std::vector overlays) { Cesium3DTilesSelection::TilesetExternals externals{ Context::instance().assetAccessor, Context::instance().prepareRenderResources, Context::instance().asyncSystem, Context::instance().creditSystem, Context::instance().logger, nullptr @@ -39,12 +39,12 @@ CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, float maximumScreenSp options.forbidHoles = true; options.enableOcclusionCulling = false; options.maximumScreenSpaceError = maximumScreenSpaceError; - Cesium3DTilesSelection::Tileset* tileset = new Cesium3DTilesSelection::Tileset(externals, assetID, getCesiumIonKey(), options); + Cesium3DTilesSelection::Tileset* tileset = new Cesium3DTilesSelection::Tileset(externals, assetID, token, options); for (auto& overlay = overlays.begin(); overlay != overlays.end(); ++overlay) { Cesium3DTilesSelection::RasterOverlayOptions rasterOptions; - const auto ionRasterOverlay = new Cesium3DTilesSelection::IonRasterOverlay("", *overlay, getCesiumIonKey(), rasterOptions); + const auto ionRasterOverlay = new Cesium3DTilesSelection::IonRasterOverlay("", *overlay, token, rasterOptions); tileset->getOverlays().add(ionRasterOverlay); } _tileset = tileset; @@ -52,7 +52,7 @@ CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, float maximumScreenSp setCullingActive(false); } -CesiumTilesetNode::CesiumTilesetNode(const std::string& url, float maximumScreenSpaceError, std::vector overlays) +CesiumTilesetNode::CesiumTilesetNode(const std::string& url, const std::string& token, float maximumScreenSpaceError, std::vector overlays) { Cesium3DTilesSelection::TilesetExternals externals{ Context::instance().assetAccessor, Context::instance().prepareRenderResources, Context::instance().asyncSystem, Context::instance().creditSystem, Context::instance().logger, nullptr @@ -66,7 +66,7 @@ CesiumTilesetNode::CesiumTilesetNode(const std::string& url, float maximumScreen for (auto& overlay = overlays.begin(); overlay != overlays.end(); ++overlay) { Cesium3DTilesSelection::RasterOverlayOptions rasterOptions; - const auto ionRasterOverlay = new Cesium3DTilesSelection::IonRasterOverlay("", *overlay, getCesiumIonKey(), rasterOptions); + const auto ionRasterOverlay = new Cesium3DTilesSelection::IonRasterOverlay("", *overlay, token, rasterOptions); tileset->getOverlays().add(ionRasterOverlay); } _tileset = tileset;