#pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace CesiumVectorData { /** * @brief Attribution that must be included with a vector document. */ struct VectorDocumentAttribution { /** @brief The HTML string containing attribution information to show. */ std::string html; /** * @brief If true, the attribution must be shown on screen. If false, it can * be included in a popover instead. */ bool showOnScreen; }; /** * @brief A vector document parsed from GeoJSON. * * The document is represented as a hierarchy of \ref GeoJsonObject values * starting with the root object. */ class CESIUMVECTORDATA_API GeoJsonDocument { public: /** * @brief Attempts to parse a \ref GeoJsonDocument from the provided GeoJSON. * * @param bytes The GeoJSON data to parse. * @param attributions Any attributions to attach to the document. * @returns A \ref CesiumUtility::Result containing the parsed * \ref GeoJsonDocument or any errors and warnings that came up while parsing. */ static CesiumUtility::Result fromGeoJson( const std::span& bytes, std::vector&& attributions = {}); /** * @brief Attempts to parse a \ref GeoJsonDocument from the provided JSON * document. * * @param document The GeoJSON JSON document. * @param attributions Any attributions to attach to the document. * @returns A \ref CesiumUtility::Result containing the parsed * \ref GeoJsonDocument or any errors and warnings that came up while parsing. */ static CesiumUtility::Result fromGeoJson( const rapidjson::Document& document, std::vector&& attributions = {}); /** * @brief Attempts to load a \ref GeoJsonDocument from a Cesium ion asset. * * @param asyncSystem The \ref CesiumAsync::AsyncSystem. * @param pAssetAccessor The \ref CesiumAsync::IAssetAccessor. * @param ionAssetID The ID of the Cesium ion asset to load. This asset must * be a GeoJSON document. * @param ionAccessToken The access token that has access to the given asset. * @param ionAssetEndpointUrl The base URL of the ion REST API server, if * different from `https://api.cesium.com/`. * @returns A future that resolves into a \ref CesiumUtility::Result * containing the parsed \ref GeoJsonDocument or any errors and warnings that * came up while loading or parsing the data. */ static CesiumAsync::Future> fromCesiumIonAsset( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, int64_t ionAssetID, const std::string& ionAccessToken, const std::string& ionAssetEndpointUrl = "https://api.cesium.com/"); /** * @brief Attempts to load a \ref GeoJsonDocument from the provided URL. * * @param asyncSystem The \ref CesiumAsync::AsyncSystem. * @param pAssetAccessor The \ref CesiumAsync::IAssetAccessor. * @param url The URL that this method will attempt to get a GeoJSON document * from. * @param headers Any additional headers to attach to the HTTP request to * obtain the GeoJSON document. * @returns A future that resolves into a \ref CesiumUtility::Result * containing the parsed \ref GeoJsonDocument or any errors and warnings that * came up while loading or parsing the data. */ static CesiumAsync::Future> fromUrl( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& headers = {}); /** * @brief Creates a new \ref GeoJsonDocument directly from a \ref * GeoJsonObject. */ GeoJsonDocument( GeoJsonObject&& rootObject, std::vector&& attributions); GeoJsonDocument() = default; /** * @brief The root object of the parsed GeoJSON. */ GeoJsonObject rootObject = GeoJsonObject{GeoJsonPoint{glm::dvec3(0, 0, 0)}}; /** * @brief Attribution information for this document. */ std::vector attributions; private: static CesiumUtility::Result parseGeoJson(const rapidjson::Document& doc); static CesiumUtility::Result parseGeoJson(const std::span& bytes); }; } // namespace CesiumVectorData