Skip to content

Commit

Permalink
Actually using the token if it's specified in the cesium layers inste…
Browse files Browse the repository at this point in the history
…ad of always relying on the environment variable.
  • Loading branch information
jasonbeverage committed Sep 15, 2023
1 parent 289192c commit 9632aa1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/osgEarthCesium/CesiumLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include "CesiumLayer"
#include "Settings"

#include <osgEarth/Registry>

Expand Down Expand Up @@ -80,14 +81,21 @@ 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<int> overlays;
if (_options->rasterOverlay().isSet())
{
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())
{
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/osgEarthCesium/CesiumTilesetNode
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> overlays = std::vector<int>());
CesiumTilesetNode(const std::string& url, float maximumScreenSpaceError = 16.0f, std::vector<int> overlays = std::vector<int>());
CesiumTilesetNode(unsigned int assetID, const std::string& token = "", float maximumScreenSpaceError = 16.0f, std::vector<int> overlays = std::vector<int>());
CesiumTilesetNode(const std::string& url, const std::string& token = "", float maximumScreenSpaceError = 16.0f, std::vector<int> overlays = std::vector<int>());

~CesiumTilesetNode();

Expand Down
10 changes: 5 additions & 5 deletions src/osgEarthCesium/CesiumTilesetNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

using namespace osgEarth::Cesium;

CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, float maximumScreenSpaceError, std::vector<int> overlays)
CesiumTilesetNode::CesiumTilesetNode(unsigned int assetID, const std::string& token, float maximumScreenSpaceError, std::vector<int> overlays)
{
Cesium3DTilesSelection::TilesetExternals externals{
Context::instance().assetAccessor, Context::instance().prepareRenderResources, Context::instance().asyncSystem, Context::instance().creditSystem, Context::instance().logger, nullptr
Expand All @@ -39,20 +39,20 @@ 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;

setCullingActive(false);
}

CesiumTilesetNode::CesiumTilesetNode(const std::string& url, float maximumScreenSpaceError, std::vector<int> overlays)
CesiumTilesetNode::CesiumTilesetNode(const std::string& url, const std::string& token, float maximumScreenSpaceError, std::vector<int> overlays)
{
Cesium3DTilesSelection::TilesetExternals externals{
Context::instance().assetAccessor, Context::instance().prepareRenderResources, Context::instance().asyncSystem, Context::instance().creditSystem, Context::instance().logger, nullptr
Expand All @@ -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;
Expand Down

0 comments on commit 9632aa1

Please sign in to comment.