|
| 1 | +#include "CesiumGeoJsonDocument.h" |
| 2 | +#include "CesiumRuntime.h" |
| 3 | + |
| 4 | +#include "CesiumUtility/Result.h" |
| 5 | + |
| 6 | +#include <span> |
| 7 | + |
| 8 | +bool UCesiumGeoJsonDocumentBlueprintLibrary::LoadGeoJsonFromString( |
| 9 | + const FString& InString, |
| 10 | + FCesiumGeoJsonDocument& OutVectorDocument) { |
| 11 | + const std::string str = TCHAR_TO_UTF8(*InString); |
| 12 | + std::span<const std::byte> bytes( |
| 13 | + reinterpret_cast<const std::byte*>(str.data()), |
| 14 | + str.size()); |
| 15 | + CesiumUtility::Result< |
| 16 | + CesiumUtility::IntrusivePointer<CesiumVectorData::GeoJsonDocument>> |
| 17 | + documentResult = CesiumVectorData::GeoJsonDocument::fromGeoJson(bytes); |
| 18 | + |
| 19 | + if (!documentResult.errors.errors.empty()) { |
| 20 | + documentResult.errors.logError( |
| 21 | + spdlog::default_logger(), |
| 22 | + "Errors while loading GeoJSON from string"); |
| 23 | + } |
| 24 | + |
| 25 | + if (!documentResult.errors.warnings.empty()) { |
| 26 | + documentResult.errors.logWarning( |
| 27 | + spdlog::default_logger(), |
| 28 | + "Warnings while loading GeoJSON from string"); |
| 29 | + } |
| 30 | + |
| 31 | + if (documentResult.pValue) { |
| 32 | + OutVectorDocument = |
| 33 | + FCesiumGeoJsonDocument(std::move(documentResult.pValue)); |
| 34 | + return true; |
| 35 | + } |
| 36 | + |
| 37 | + return false; |
| 38 | +} |
| 39 | + |
| 40 | +FCesiumGeoJsonObject UCesiumGeoJsonDocumentBlueprintLibrary::GetRootObject( |
| 41 | + const FCesiumGeoJsonDocument& InVectorDocument) { |
| 42 | + if (!InVectorDocument._document) { |
| 43 | + return FCesiumGeoJsonObject(); |
| 44 | + } |
| 45 | + |
| 46 | + return FCesiumGeoJsonObject( |
| 47 | + InVectorDocument._document, |
| 48 | + &InVectorDocument._document->getRootObject()); |
| 49 | +} |
| 50 | + |
| 51 | +UCesiumLoadVectorDocumentFromIonAsyncAction* |
| 52 | +UCesiumLoadVectorDocumentFromIonAsyncAction::LoadFromIon( |
| 53 | + int64 AssetId, |
| 54 | + const FString& IonAccessToken, |
| 55 | + const FString& IonAssetEndpointUrl) { |
| 56 | + UCesiumLoadVectorDocumentFromIonAsyncAction* pAction = |
| 57 | + NewObject<UCesiumLoadVectorDocumentFromIonAsyncAction>(); |
| 58 | + pAction->AssetId = AssetId; |
| 59 | + pAction->IonAccessToken = IonAccessToken; |
| 60 | + pAction->IonAssetEndpointUrl = IonAssetEndpointUrl; |
| 61 | + return pAction; |
| 62 | +} |
| 63 | + |
| 64 | +void UCesiumLoadVectorDocumentFromIonAsyncAction::Activate() { |
| 65 | + CesiumVectorData::GeoJsonDocument::fromCesiumIonAsset( |
| 66 | + getAsyncSystem(), |
| 67 | + getAssetAccessor(), |
| 68 | + this->AssetId, |
| 69 | + TCHAR_TO_UTF8(*this->IonAccessToken), |
| 70 | + TCHAR_TO_UTF8(*this->IonAssetEndpointUrl)) |
| 71 | + .thenInMainThread( |
| 72 | + [Callback = this->OnLoadResult]( |
| 73 | + CesiumUtility::Result<CesiumUtility::IntrusivePointer< |
| 74 | + CesiumVectorData::GeoJsonDocument>>&& result) { |
| 75 | + if (result.errors.hasErrors()) { |
| 76 | + result.errors.logError( |
| 77 | + spdlog::default_logger(), |
| 78 | + "Errors loading GeoJSON:"); |
| 79 | + result.errors.logWarning( |
| 80 | + spdlog::default_logger(), |
| 81 | + "Warnings loading GeoJSON:"); |
| 82 | + } |
| 83 | + |
| 84 | + if (result.pValue) { |
| 85 | + Callback.Broadcast( |
| 86 | + true, |
| 87 | + FCesiumGeoJsonDocument(MoveTemp(result.pValue))); |
| 88 | + } else { |
| 89 | + Callback.Broadcast(false, {}); |
| 90 | + } |
| 91 | + }); |
| 92 | +} |
0 commit comments