diff options
Diffstat (limited to 'platform/android/src/style/sources/geojson_source.cpp')
-rw-r--r-- | platform/android/src/style/sources/geojson_source.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 7ab98e47c0..0c2d25f9fc 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -9,7 +9,7 @@ #include "../../conversion/conversion.hpp" #include "../../conversion/collection.hpp" #include "../../geometry/conversion/feature.hpp" -#include "../conversion/url_or_tileset.hpp" + #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/geojson_options.hpp> @@ -18,11 +18,26 @@ namespace mbgl { namespace android { + // This conversion is expected not to fail because it's used only in contexts where + // the value was originally a GeoJsonOptions object on the Java side. If it fails + // to convert, it's a bug in our serialization or Java-side static typing. + static style::GeoJSONOptions convertGeoJSONOptions(jni::JNIEnv& env, jni::Object<> options) { + using namespace mbgl::style::conversion; + if (!options) { + return style::GeoJSONOptions(); + } + Error error; + optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(Value(env, options), error); + if (!result) { + throw std::logic_error(error.message); + } + return *result; + } + GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> options) : Source(env, std::make_unique<mbgl::style::GeoJSONSource>( jni::Make<std::string>(env, sourceId), - options ? *style::conversion::convert<style::GeoJSONOptions>(Value(env, options)) : style::GeoJSONOptions() - ) + convertGeoJSONOptions(env, options)) ) { } @@ -36,9 +51,10 @@ namespace android { using namespace mbgl::style::conversion; // Convert the jni object - Result<GeoJSON> converted = convert<GeoJSON>(Value(env, json)); + Error error; + optional<GeoJSON> converted = convert<GeoJSON>(Value(env, json), error); if(!converted) { - mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + converted.error().message); + mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + error.message); return; } |