|
| 1 | +// Copyright 2020-2024 CesiumGS, Inc. and Contributors |
| 2 | + |
| 3 | +#include "CesiumGeoJsonDocumentRasterOverlay.h" |
| 4 | + |
| 5 | +#include "CesiumCustomVersion.h" |
| 6 | +#include "CesiumGeometry/QuadtreeTilingScheme.h" |
| 7 | +#include "CesiumGeospatial/GlobeRectangle.h" |
| 8 | +#include "CesiumGeospatial/Projection.h" |
| 9 | +#include "CesiumRasterOverlays/GeoJsonDocumentRasterOverlay.h" |
| 10 | +#include "CesiumVectorData/VectorStyle.h" |
| 11 | + |
| 12 | +#include "CesiumRuntime.h" |
| 13 | + |
| 14 | +std::unique_ptr<CesiumRasterOverlays::RasterOverlay> |
| 15 | +UCesiumGeoJsonDocumentRasterOverlay::CreateOverlay( |
| 16 | + const CesiumRasterOverlays::RasterOverlayOptions& options) { |
| 17 | + if (this->Source == ECesiumGeoJsonDocumentRasterOverlaySource::FromDocument && |
| 18 | + !this->GeoJsonDocument.IsValid()) { |
| 19 | + // Don't create an overlay with an invalid document. |
| 20 | + return nullptr; |
| 21 | + } |
| 22 | + |
| 23 | + CesiumGeospatial::Projection projection; |
| 24 | + if (this->Projection == |
| 25 | + ECesiumGeoJsonDocumentRasterOverlayProjection::Geographic) { |
| 26 | + projection = CesiumGeospatial::GeographicProjection(options.ellipsoid); |
| 27 | + } else { |
| 28 | + projection = CesiumGeospatial::WebMercatorProjection(options.ellipsoid); |
| 29 | + } |
| 30 | + |
| 31 | + std::optional<CesiumRasterOverlays::GeoJsonDocumentRasterOverlayStyleCallback> |
| 32 | + callbackOpt = std::nullopt; |
| 33 | + |
| 34 | + if (this->StyleCallback.IsBound()) { |
| 35 | + callbackOpt = |
| 36 | + [Callback = this->StyleCallback]( |
| 37 | + const std::shared_ptr<CesiumVectorData::GeoJsonDocument>& doc, |
| 38 | + const CesiumVectorData::GeoJsonObject* pNode) |
| 39 | + -> std::optional<CesiumVectorData::VectorStyle> { |
| 40 | + FCesiumVectorStyle style; |
| 41 | + if (Callback.Execute(FCesiumGeoJsonObject(doc, pNode), style)) { |
| 42 | + return style.toNative(); |
| 43 | + } |
| 44 | + |
| 45 | + return std::nullopt; |
| 46 | + }; |
| 47 | + } |
| 48 | + |
| 49 | + CesiumRasterOverlays::GeoJsonDocumentRasterOverlayOptions vectorOptions{ |
| 50 | + this->DefaultStyle.toNative(), |
| 51 | + callbackOpt, |
| 52 | + std::move(projection), |
| 53 | + options.ellipsoid, |
| 54 | + this->MipLevels}; |
| 55 | + |
| 56 | + if (this->Source == |
| 57 | + ECesiumGeoJsonDocumentRasterOverlaySource::FromCesiumIon) { |
| 58 | + if (!IsValid(this->CesiumIonServer)) { |
| 59 | + this->CesiumIonServer = UCesiumIonServer::GetServerForNewObjects(); |
| 60 | + } |
| 61 | + |
| 62 | + return std::make_unique<CesiumRasterOverlays::GeoJsonDocumentRasterOverlay>( |
| 63 | + TCHAR_TO_UTF8(*this->MaterialLayerKey), |
| 64 | + CesiumRasterOverlays::IonGeoJsonDocumentRasterOverlaySource{ |
| 65 | + this->IonAssetID, |
| 66 | + TCHAR_TO_UTF8(*this->CesiumIonServer->DefaultIonAccessToken), |
| 67 | + TCHAR_TO_UTF8(*this->CesiumIonServer->ApiUrl)}, |
| 68 | + vectorOptions, |
| 69 | + options); |
| 70 | + } else if ( |
| 71 | + this->Source == ECesiumGeoJsonDocumentRasterOverlaySource::FromUrl) { |
| 72 | + std::vector<CesiumAsync::IAssetAccessor::THeader> headers; |
| 73 | + headers.reserve(this->RequestHeaders.Num()); |
| 74 | + |
| 75 | + for (auto& [k, v] : this->RequestHeaders) { |
| 76 | + headers.push_back({TCHAR_TO_UTF8(*k), TCHAR_TO_UTF8(*v)}); |
| 77 | + } |
| 78 | + |
| 79 | + return std::make_unique<CesiumRasterOverlays::GeoJsonDocumentRasterOverlay>( |
| 80 | + TCHAR_TO_UTF8(*this->MaterialLayerKey), |
| 81 | + CesiumRasterOverlays::UrlGeoJsonDocumentRasterOverlaySource{ |
| 82 | + TCHAR_TO_UTF8(*this->Url), |
| 83 | + std::move(headers)}, |
| 84 | + vectorOptions, |
| 85 | + options); |
| 86 | + } |
| 87 | + |
| 88 | + return std::make_unique<CesiumRasterOverlays::GeoJsonDocumentRasterOverlay>( |
| 89 | + TCHAR_TO_UTF8(*this->MaterialLayerKey), |
| 90 | + this->GeoJsonDocument.GetDocument(), |
| 91 | + vectorOptions, |
| 92 | + options); |
| 93 | +} |
0 commit comments