diff options
author | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2016-09-21 11:04:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-21 11:04:32 +0200 |
commit | eb97dbe383ca7697feab5860995b97181c39c607 (patch) | |
tree | 70bdd7b6ebea32aec132413fa703e92a2a0f63d0 /platform/android/src/style/conversion | |
parent | 3b546b964609d0f596dac32e155b1489bb85645e (diff) | |
download | qtlocation-mapboxgl-eb97dbe383ca7697feab5860995b97181c39c607.tar.gz |
[android] Sources: peer model, mutability (#6054)
Diffstat (limited to 'platform/android/src/style/conversion')
-rw-r--r-- | platform/android/src/style/conversion/geojson.hpp | 57 | ||||
-rw-r--r-- | platform/android/src/style/conversion/url_or_tileset.hpp | 38 |
2 files changed, 95 insertions, 0 deletions
diff --git a/platform/android/src/style/conversion/geojson.hpp b/platform/android/src/style/conversion/geojson.hpp new file mode 100644 index 0000000000..920c670fcb --- /dev/null +++ b/platform/android/src/style/conversion/geojson.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "../value.hpp" + +#include <mapbox/geojson.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/geojson.hpp> +#include <mbgl/util/rapidjson.hpp> +#include <mbgl/platform/log.hpp> +#include <jni/jni.hpp> + +#include <sstream> +#include <string> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +Result<GeoJSON> convertGeoJSON(const mbgl::android::Value& value) { + + //Value should be a string wrapped in an object + mbgl::android::Value jsonValue = value.get("data"); + if(value.isNull()) { + return Error { "no json data found" }; + } + std::string jsonString = value.get("data").toString(); + + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d; + d.Parse(jsonString.c_str()); + + if (d.HasParseError()) { + std::stringstream message; + message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError()); + return Error { message.str() }; + } + + conversion::Result<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d); + if (!geoJSON) { + return Error { geoJSON.error().message }; + } + + return geoJSON; +} + +template <> +struct Converter<GeoJSON> { + + Result<GeoJSON> operator()(const mbgl::android::Value& value) const { + return convertGeoJSON(value); + } + +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl
\ No newline at end of file diff --git a/platform/android/src/style/conversion/url_or_tileset.hpp b/platform/android/src/style/conversion/url_or_tileset.hpp new file mode 100644 index 0000000000..c1801f56d0 --- /dev/null +++ b/platform/android/src/style/conversion/url_or_tileset.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include <mbgl/util/optional.hpp> +#include <mbgl/util/variant.hpp> + +#include <mbgl/util/tileset.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/tileset.hpp> + +#include <jni/jni.hpp> + +#include <string> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter<variant<std::string, Tileset>> { + + template <class V> + Result<variant<std::string, Tileset>> operator()(const V& value) const { + if (isObject(value)) { + Result<Tileset> tileset = convert<Tileset>(value); + if (!tileset) { + return tileset.error(); + } + return *tileset; + } else { + return *toString(value); + } + } + +}; + +} +} +}
\ No newline at end of file |