Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions src/vsgCs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ set(LIB_PUBLIC_HEADERS
${PROJECT_BINARY_DIR}/include/vsgCs/Config.h
CRS.h
CsDebugColorizeTilesOverlay.h
CsWebMapServiceRasterOverlay.h
CsWebMapTileServiceRasterOverlay.h
CsTileMapServiceRasterOverlay.h
CsUrlTemplateRasterOverlay.h
CsOverlay.h
CesiumGltfBuilder.h
${CMAKE_CURRENT_BINARY_DIR}/Export.h
Expand All @@ -32,6 +36,10 @@ set(LIB_PUBLIC_HEADERS
set(SOURCES
CRS.cpp
CsDebugColorizeTilesOverlay.cpp
CsWebMapServiceRasterOverlay.cpp
CsWebMapTileServiceRasterOverlay.cpp
CsTileMapServiceRasterOverlay.cpp
CsUrlTemplateRasterOverlay.cpp
CsOverlay.cpp
CesiumGltfBuilder.cpp
CompilableImage.cpp
Expand Down
82 changes: 82 additions & 0 deletions src/vsgCs/CsTileMapServiceRasterOverlay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* <editor-fold desc="MIT License">

Copyright(c) 2023 Timothy Moore

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

</editor-fold> */

#include "CsTileMapServiceRasterOverlay.h"

#include "jsonUtils.h"
#include <CesiumRasterOverlays/TileMapServiceRasterOverlay.h>
#include <CesiumUtility/JsonHelpers.h>

using namespace vsgCs;

CesiumRasterOverlays::RasterOverlay* CsTileMapServiceRasterOverlay::createOverlay(
const CesiumRasterOverlays::RasterOverlayOptions& options)
{
if (this->Url.empty())
{
// Don't create an overlay with an empty URL.
return nullptr;
}

CesiumRasterOverlays::TileMapServiceRasterOverlayOptions tmsOptions;
if (MaximumLevel > MinimumLevel && bSpecifyZoomLevels)
{
tmsOptions.minimumLevel = MinimumLevel;
tmsOptions.maximumLevel = MaximumLevel;
}

std::vector<CesiumAsync::IAssetAccessor::THeader> headers;

for (const auto& [Key, Value] : this->RequestHeaders)
{
headers.push_back(CesiumAsync::IAssetAccessor::THeader{
(Key),
(Value) });
}

return new CesiumRasterOverlays::TileMapServiceRasterOverlay(
(this->MaterialLayerKey),
(this->Url),
headers,
tmsOptions,
options);
}

namespace vsgCs
{
vsg::ref_ptr<vsg::Object> buildCsTileMapServiceRasterOverlay(const rapidjson::Value& json,
JSONObjectFactory* factory,
const vsg::ref_ptr<vsg::Object>& object)
{
auto overlay = create_or<CsTileMapServiceRasterOverlay>(object);
factory->build(json, "CsOverlay", overlay);
overlay->MaterialLayerKey = CesiumUtility::JsonHelpers::getStringOrDefault(json, "materialKey",
"Overlay0");
overlay->Url = CesiumUtility::JsonHelpers::getStringOrDefault(json, "url", "");

return overlay;
}

// XXX See jsonUtils for registration.
}
71 changes: 71 additions & 0 deletions src/vsgCs/CsTileMapServiceRasterOverlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* <editor-fold desc="MIT License">

Copyright(c) 2023 Timothy Moore

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

</editor-fold> */

#pragma once

#include "CsOverlay.h"

namespace vsgCs
{
class VSGCS_EXPORT CsTileMapServiceRasterOverlay : public vsg::Inherit<CsOverlay,
CsTileMapServiceRasterOverlay>
{
public:
CsTileMapServiceRasterOverlay(
std::string in_Url = std::string())
: Url(in_Url)
{
}

/**
* The base URL of the Tile Map Service (TMS).
*/
std::string Url;
Comment thread
timoore marked this conversation as resolved.
Outdated

/**
* True to directly specify minum and maximum zoom levels available from the
* server, or false to automatically determine the minimum and maximum zoom
* levels from the server's tilemapresource.xml file.
*/
bool bSpecifyZoomLevels = false;

/**
* Minimum zoom level.
*/
int32_t MinimumLevel = 0;

/**
* Maximum zoom level.
*/
int32_t MaximumLevel = 10;

/**
* HTTP headers to be attached to each request made for this raster overlay.
*/
std::map<std::string, std::string> RequestHeaders;

CesiumRasterOverlays::RasterOverlay* createOverlay(
const CesiumRasterOverlays::RasterOverlayOptions& options) override;
};
}
118 changes: 118 additions & 0 deletions src/vsgCs/CsUrlTemplateRasterOverlay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* <editor-fold desc="MIT License">

Copyright(c) 2023 Timothy Moore

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

</editor-fold> */

#include "CsUrlTemplateRasterOverlay.h"

#include "jsonUtils.h"
#include <CesiumRasterOverlays/UrlTemplateRasterOverlay.h>
#include <CesiumUtility/JsonHelpers.h>

using namespace vsgCs;

CesiumRasterOverlays::RasterOverlay* CsUrlTemplateRasterOverlay::createOverlay(
const CesiumRasterOverlays::RasterOverlayOptions& options)
{
if (this->TemplateUrl.empty())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use this-> in member functions. I feel it should be clear enough that an identifier refers to a class member.

{
// Don't create an overlay with an empty base URL.
return nullptr;
}

CesiumRasterOverlays::UrlTemplateRasterOverlayOptions urlTemplateOptions;

urlTemplateOptions.minimumLevel = MinimumLevel;
urlTemplateOptions.maximumLevel = MaximumLevel;

urlTemplateOptions.tileWidth = this->TileWidth;
urlTemplateOptions.tileHeight = this->TileHeight;

const CesiumGeospatial::Ellipsoid& ellipsoid = options.ellipsoid;

if (this->Projection ==
ECesiumUrlTemplateRasterOverlayProjection::Geographic)
{
urlTemplateOptions.projection =
CesiumGeospatial::GeographicProjection(ellipsoid);
}
else
{
urlTemplateOptions.projection =
CesiumGeospatial::WebMercatorProjection(ellipsoid);
}

if (bSpecifyTilingScheme)
{
CesiumGeospatial::GlobeRectangle globeRectangle =
CesiumGeospatial::GlobeRectangle::fromDegrees(
RectangleWest,
RectangleSouth,
RectangleEast,
RectangleNorth);
CesiumGeometry::Rectangle coverageRectangle =
CesiumGeospatial::projectRectangleSimple(
*urlTemplateOptions.projection,
globeRectangle);
urlTemplateOptions.coverageRectangle = coverageRectangle;
urlTemplateOptions.tilingScheme = CesiumGeometry::QuadtreeTilingScheme(
coverageRectangle,
RootTilesX,
RootTilesY);
}

std::vector<CesiumAsync::IAssetAccessor::THeader> headers;

for (const auto& [Key, Value] : this->RequestHeaders)
{
headers.push_back(CesiumAsync::IAssetAccessor::THeader{
(Key),
(Value) });
}

return new CesiumRasterOverlays::UrlTemplateRasterOverlay(
(this->MaterialLayerKey),
Comment thread
timoore marked this conversation as resolved.
Outdated
(this->TemplateUrl),
headers,
urlTemplateOptions,
options);
}

namespace vsgCs
{
vsg::ref_ptr<vsg::Object> buildCsUrlTemplateRasterOverlay(const rapidjson::Value& json,
JSONObjectFactory* factory,
const vsg::ref_ptr<vsg::Object>& object)
{
auto overlay = create_or<CsUrlTemplateRasterOverlay>(object);
factory->build(json, "CsOverlay", overlay);
overlay->MaterialLayerKey = CesiumUtility::JsonHelpers::getStringOrDefault(json, "materialKey",
"Overlay0");
overlay->TemplateUrl = CesiumUtility::JsonHelpers::getStringOrDefault(json, "url", "");
std::string projection = CesiumUtility::JsonHelpers::getStringOrDefault(json, "projection", "");
overlay->Projection = projection == "geographic" ? ECesiumUrlTemplateRasterOverlayProjection::Geographic : ECesiumUrlTemplateRasterOverlayProjection::WebMercator;

return overlay;
}

// XXX See jsonUtils for registration.
}
Loading