diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2018-03-26 21:33:52 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2018-08-20 22:49:01 +0300 |
commit | 4fedcf8d061d835e71df80dbc20a32ee4ec8fd21 (patch) | |
tree | d0e52c0017075867aae09726ff334e56bc97a0c2 /platform/android/src/offline/offline_region_definition.cpp | |
parent | fae099933b23a36176dcc8c4a91c37816fa9b7fe (diff) | |
download | qtlocation-mapboxgl-4fedcf8d061d835e71df80dbc20a32ee4ec8fd21.tar.gz |
[android] arbitrary offline region geometries
Diffstat (limited to 'platform/android/src/offline/offline_region_definition.cpp')
-rw-r--r-- | platform/android/src/offline/offline_region_definition.cpp | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/platform/android/src/offline/offline_region_definition.cpp b/platform/android/src/offline/offline_region_definition.cpp index 66a9bdf99d..a856672902 100644 --- a/platform/android/src/offline/offline_region_definition.cpp +++ b/platform/android/src/offline/offline_region_definition.cpp @@ -1,6 +1,9 @@ #include "offline_region_definition.hpp" #include "../geometry/lat_lng_bounds.hpp" +#include "../geojson/geometry.hpp" + +#include <exception> namespace mbgl { namespace android { @@ -13,9 +16,21 @@ void OfflineRegionDefinition::registerNative(jni::JNIEnv& env) { javaClass = *jni::Class<OfflineRegionDefinition>::Find(env).NewGlobalRef(env).release(); } +mbgl::OfflineRegionDefinition OfflineRegionDefinition::getDefinition(JNIEnv& env, + jni::Object<OfflineRegionDefinition> jDefinition) { + + if (jDefinition.IsInstanceOf(env, OfflineTilePyramidRegionDefinition::javaClass)) { + return OfflineTilePyramidRegionDefinition::getDefinition(env, jni::Object<OfflineTilePyramidRegionDefinition>(*jDefinition)); + } else if (jDefinition.IsInstanceOf(env, OfflineGeometryRegionDefinition::javaClass)) { + return OfflineGeometryRegionDefinition::getDefinition(env, jni::Object<OfflineGeometryRegionDefinition>(*jDefinition)); + } + + throw std::runtime_error("Unknown offline region definition java class"); +} + // OfflineTilePyramidRegionDefinition // -jni::Object<OfflineTilePyramidRegionDefinition> OfflineTilePyramidRegionDefinition::New(jni::JNIEnv& env, mbgl::OfflineTilePyramidRegionDefinition definition) { +jni::Object<OfflineTilePyramidRegionDefinition> OfflineTilePyramidRegionDefinition::New(jni::JNIEnv& env, const mbgl::OfflineTilePyramidRegionDefinition& definition) { //Convert objects auto styleURL = jni::Make<jni::String>(env, definition.styleURL); @@ -65,5 +80,56 @@ void OfflineTilePyramidRegionDefinition::registerNative(jni::JNIEnv& env) { javaClass = *jni::Class<OfflineTilePyramidRegionDefinition>::Find(env).NewGlobalRef(env).release(); } +// OfflineGeometryRegionDefinition // + +jni::Object<OfflineGeometryRegionDefinition> OfflineGeometryRegionDefinition::New(jni::JNIEnv& env, const mbgl::OfflineGeometryRegionDefinition& definition) { + //Convert objects + auto styleURL = jni::Make<jni::String>(env, definition.styleURL); + auto geometry = geojson::Geometry::New(env, definition.geometry); + + static auto constructor = javaClass.GetConstructor<jni::String, jni::Object<geojson::Geometry>, jni::jdouble, jni::jdouble, jni::jfloat>(env); + auto jdefinition = javaClass.New(env, constructor, styleURL, geometry, definition.minZoom, definition.maxZoom, definition.pixelRatio); + + //Delete References + jni::DeleteLocalRef(env, styleURL); + jni::DeleteLocalRef(env, geometry); + + return jdefinition; +} + +mbgl::OfflineGeometryRegionDefinition OfflineGeometryRegionDefinition::getDefinition(jni::JNIEnv& env, jni::Object<OfflineGeometryRegionDefinition> jDefinition) { + // Field references + static auto styleURLF = javaClass.GetField<jni::String>(env, "styleURL"); + static auto geometryF = javaClass.GetField<jni::Object<geojson::Geometry>>(env, "geometry"); + static auto minZoomF = javaClass.GetField<jni::jdouble>(env, "minZoom"); + static auto maxZoomF = javaClass.GetField<jni::jdouble>(env, "maxZoom"); + static auto pixelRatioF = javaClass.GetField<jni::jfloat>(env, "pixelRatio"); + + // Get objects + auto jStyleURL = jDefinition.Get(env, styleURLF); + auto jGeometry = jDefinition.Get(env, geometryF); + + // Create definition + mbgl::OfflineGeometryRegionDefinition definition( + jni::Make<std::string>(env, jStyleURL), + geojson::Geometry::convert(env, jGeometry), + jDefinition.Get(env, minZoomF), + jDefinition.Get(env, maxZoomF), + jDefinition.Get(env, pixelRatioF) + ); + + // Delete references + jni::DeleteLocalRef(env, jStyleURL); + jni::DeleteLocalRef(env, jGeometry); + + return definition; +} + +jni::Class<OfflineGeometryRegionDefinition> OfflineGeometryRegionDefinition::javaClass; + +void OfflineGeometryRegionDefinition::registerNative(jni::JNIEnv& env) { + javaClass = *jni::Class<OfflineGeometryRegionDefinition>::Find(env).NewGlobalRef(env).release(); +} + } // namespace android } // namespace mbgl |