summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2020-03-25 10:38:03 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-03-25 07:01:42 -0400
commit2b37d81d73820b7393a134b865dc38a742ca90ca (patch)
treed58f1a0dd2b227b174b64df1485e15ab1fd10148 /platform/android
parent77d95d27ceeec502bf3d316660594abf4ed61517 (diff)
downloadqtlocation-mapboxgl-2b37d81d73820b7393a134b865dc38a742ca90ca.tar.gz
[android] Expose getLayer, getSource and Observer interface for snapshotter
So that users can modify properties of an existing layer / source objects
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp27
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.hpp2
-rw-r--r--platform/android/src/style/sources/custom_geometry_source.cpp5
-rw-r--r--platform/android/src/style/sources/custom_geometry_source.hpp2
-rw-r--r--platform/android/src/style/sources/geojson_source.cpp2
-rw-r--r--platform/android/src/style/sources/geojson_source.hpp2
-rw-r--r--platform/android/src/style/sources/image_source.cpp7
-rw-r--r--platform/android/src/style/sources/image_source.hpp2
-rw-r--r--platform/android/src/style/sources/raster_dem_source.cpp7
-rw-r--r--platform/android/src/style/sources/raster_dem_source.hpp2
-rw-r--r--platform/android/src/style/sources/raster_source.cpp7
-rw-r--r--platform/android/src/style/sources/raster_source.hpp2
-rw-r--r--platform/android/src/style/sources/source.cpp43
-rw-r--r--platform/android/src/style/sources/source.hpp3
-rw-r--r--platform/android/src/style/sources/unknown_source.cpp19
-rw-r--r--platform/android/src/style/sources/unknown_source.hpp2
-rw-r--r--platform/android/src/style/sources/vector_source.cpp7
-rw-r--r--platform/android/src/style/sources/vector_source.hpp2
18 files changed, 84 insertions, 59 deletions
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index 5bccbd1ba8..a02c9e5c93 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -7,6 +7,7 @@
#include <mbgl/util/string.hpp>
#include "../attach_env.hpp"
+#include "../style/layers/layer_manager.hpp"
#include "map_snapshot.hpp"
namespace mbgl {
@@ -282,6 +283,30 @@ void MapSnapshotter::addImages(JNIEnv& env, const jni::Array<jni::Object<mbgl::a
}
}
+jni::Local<jni::Object<Layer>> MapSnapshotter::getLayer(JNIEnv& env, const jni::String& layerId) {
+ // Find the layer
+ mbgl::style::Layer* coreLayer = snapshotter->getStyle().getLayer(jni::Make<std::string>(env, layerId));
+ if (!coreLayer) {
+ mbgl::Log::Debug(mbgl::Event::JNI, "No layer found");
+ return jni::Local<jni::Object<Layer>>();
+ }
+
+ // Create and return the layer's native peer
+ return LayerManagerAndroid::get()->createJavaLayerPeer(env, *coreLayer);
+}
+
+jni::Local<jni::Object<Source>> MapSnapshotter::getSource(JNIEnv& env, const jni::String& sourceId) {
+ // Find the source
+ mbgl::style::Source* coreSource = snapshotter->getStyle().getSource(jni::Make<std::string>(env, sourceId));
+ if (!coreSource) {
+ mbgl::Log::Debug(mbgl::Event::JNI, "No source found");
+ return jni::Local<jni::Object<Source>>();
+ }
+
+ // Create and return the source's native peer
+ return jni::NewLocal(env, Source::peerForCoreSource(env, *coreSource));
+}
+
// Static methods //
void MapSnapshotter::registerNative(jni::JNIEnv& env) {
@@ -314,6 +339,8 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
METHOD(&MapSnapshotter::addLayerAbove, "nativeAddLayerAbove"),
METHOD(&MapSnapshotter::addSource, "nativeAddSource"),
METHOD(&MapSnapshotter::addImages, "nativeAddImages"),
+ METHOD(&MapSnapshotter::getLayer, "nativeGetLayer"),
+ METHOD(&MapSnapshotter::getSource, "nativeGetSource"),
METHOD(&MapSnapshotter::setStyleJson, "setStyleJson"),
METHOD(&MapSnapshotter::setSize, "setSize"),
METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"),
diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp
index c7a9ce14ad..4d0186e7f8 100644
--- a/platform/android/src/snapshotter/map_snapshotter.hpp
+++ b/platform/android/src/snapshotter/map_snapshotter.hpp
@@ -58,6 +58,8 @@ public:
void addLayerAbove(JNIEnv&, jlong, const jni::String&);
void addSource(JNIEnv&, const jni::Object<Source>&, jlong nativePtr);
void addImages(JNIEnv&, const jni::Array<jni::Object<mbgl::android::Image>>&);
+ jni::Local<jni::Object<Layer>> getLayer(JNIEnv&, const jni::String&);
+ jni::Local<jni::Object<Source>> getSource(JNIEnv&, const jni::String&);
// MapSnapshotterObserver overrides
void onDidFailLoadingStyle(const std::string&) override;
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp
index dccca4cf46..0d96a09916 100644
--- a/platform/android/src/style/sources/custom_geometry_source.cpp
+++ b/platform/android/src/style/sources/custom_geometry_source.cpp
@@ -51,9 +51,8 @@ namespace android {
CustomGeometrySource::CustomGeometrySource(jni::JNIEnv& env,
mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
+ AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
CustomGeometrySource::~CustomGeometrySource() {
releaseThreads();
diff --git a/platform/android/src/style/sources/custom_geometry_source.hpp b/platform/android/src/style/sources/custom_geometry_source.hpp
index 52e4027dd8..6979ecc25d 100644
--- a/platform/android/src/style/sources/custom_geometry_source.hpp
+++ b/platform/android/src/style/sources/custom_geometry_source.hpp
@@ -21,7 +21,7 @@ public:
static void registerNative(jni::JNIEnv&);
CustomGeometrySource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
- CustomGeometrySource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ CustomGeometrySource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~CustomGeometrySource();
bool removeFromMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map&) override;
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp
index f68c9d8f42..0a287eb6da 100644
--- a/platform/android/src/style/sources/geojson_source.cpp
+++ b/platform/android/src/style/sources/geojson_source.cpp
@@ -50,7 +50,7 @@ GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, const jni::String& sourceId, cons
converter(std::make_unique<Actor<FeatureConverter>>(Scheduler::GetBackground(),
source.as<style::GeoJSONSource>()->impl().getOptions())) {}
-GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend)
+GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend* frontend)
: Source(env, coreSource, createJavaPeer(env), frontend),
converter(std::make_unique<Actor<FeatureConverter>>(Scheduler::GetBackground(),
source.as<style::GeoJSONSource>()->impl().getOptions())) {}
diff --git a/platform/android/src/style/sources/geojson_source.hpp b/platform/android/src/style/sources/geojson_source.hpp
index 668e944e1c..c7ef6e54de 100644
--- a/platform/android/src/style/sources/geojson_source.hpp
+++ b/platform/android/src/style/sources/geojson_source.hpp
@@ -43,7 +43,7 @@ public:
static void registerNative(jni::JNIEnv&);
GeoJSONSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
- GeoJSONSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ GeoJSONSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~GeoJSONSource();
private:
diff --git a/platform/android/src/style/sources/image_source.cpp b/platform/android/src/style/sources/image_source.cpp
index b42e0e5a51..448ecd2160 100644
--- a/platform/android/src/style/sources/image_source.cpp
+++ b/platform/android/src/style/sources/image_source.cpp
@@ -23,11 +23,8 @@ namespace android {
) {
}
- ImageSource::ImageSource(jni::JNIEnv& env,
- mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
+ ImageSource::ImageSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
ImageSource::~ImageSource() = default;
diff --git a/platform/android/src/style/sources/image_source.hpp b/platform/android/src/style/sources/image_source.hpp
index 6c359bf0ee..da88feac74 100644
--- a/platform/android/src/style/sources/image_source.hpp
+++ b/platform/android/src/style/sources/image_source.hpp
@@ -19,7 +19,7 @@ public:
ImageSource(jni::JNIEnv&, const jni::String&, const jni::Object<LatLngQuad>&);
- ImageSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ ImageSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~ImageSource();
diff --git a/platform/android/src/style/sources/raster_dem_source.cpp b/platform/android/src/style/sources/raster_dem_source.cpp
index f60526a9b7..a33e002598 100644
--- a/platform/android/src/style/sources/raster_dem_source.cpp
+++ b/platform/android/src/style/sources/raster_dem_source.cpp
@@ -24,10 +24,9 @@ namespace android {
}
RasterDEMSource::RasterDEMSource(jni::JNIEnv& env,
- mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
+ mbgl::style::Source& coreSource,
+ AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
RasterDEMSource::~RasterDEMSource() = default;
diff --git a/platform/android/src/style/sources/raster_dem_source.hpp b/platform/android/src/style/sources/raster_dem_source.hpp
index 0b31c4ecd3..581e8f8bc6 100644
--- a/platform/android/src/style/sources/raster_dem_source.hpp
+++ b/platform/android/src/style/sources/raster_dem_source.hpp
@@ -15,7 +15,7 @@ public:
static void registerNative(jni::JNIEnv&);
RasterDEMSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&, jni::jint);
- RasterDEMSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ RasterDEMSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~RasterDEMSource();
jni::Local<jni::String> getURL(jni::JNIEnv&);
diff --git a/platform/android/src/style/sources/raster_source.cpp b/platform/android/src/style/sources/raster_source.cpp
index 535f899c99..67603e74cd 100644
--- a/platform/android/src/style/sources/raster_source.cpp
+++ b/platform/android/src/style/sources/raster_source.cpp
@@ -22,11 +22,8 @@ namespace android {
) {
}
- RasterSource::RasterSource(jni::JNIEnv& env,
- mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
+ RasterSource::RasterSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
RasterSource::~RasterSource() = default;
diff --git a/platform/android/src/style/sources/raster_source.hpp b/platform/android/src/style/sources/raster_source.hpp
index 08648f79aa..e1bc5ca7ae 100644
--- a/platform/android/src/style/sources/raster_source.hpp
+++ b/platform/android/src/style/sources/raster_source.hpp
@@ -15,7 +15,7 @@ public:
static void registerNative(jni::JNIEnv&);
RasterSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&, jni::jint);
- RasterSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ RasterSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~RasterSource();
jni::Local<jni::String> getURL(jni::JNIEnv&);
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp
index f4040a5718..5c43c2ae7c 100644
--- a/platform/android/src/style/sources/source.cpp
+++ b/platform/android/src/style/sources/source.cpp
@@ -34,33 +34,42 @@
namespace mbgl {
namespace android {
- static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) {
- if (coreSource.is<mbgl::style::VectorSource>()) {
- return std::make_unique<VectorSource>(env, *coreSource.as<mbgl::style::VectorSource>(), frontend);
- } else if (coreSource.is<mbgl::style::RasterSource>()) {
- return std::make_unique<RasterSource>(env, *coreSource.as<mbgl::style::RasterSource>(), frontend);
- } else if (coreSource.is<mbgl::style::GeoJSONSource>()) {
- return std::make_unique<GeoJSONSource>(env, *coreSource.as<mbgl::style::GeoJSONSource>(), frontend);
- } else if (coreSource.is<mbgl::style::ImageSource>()) {
- return std::make_unique<ImageSource>(env, *coreSource.as<mbgl::style::ImageSource>(), frontend);
- } else {
- return std::make_unique<UnknownSource>(env, coreSource, frontend);
- }
+static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
+ mbgl::style::Source& coreSource,
+ AndroidRendererFrontend* frontend) {
+ if (coreSource.is<mbgl::style::VectorSource>()) {
+ return std::make_unique<VectorSource>(env, *coreSource.as<mbgl::style::VectorSource>(), frontend);
+ } else if (coreSource.is<mbgl::style::RasterSource>()) {
+ return std::make_unique<RasterSource>(env, *coreSource.as<mbgl::style::RasterSource>(), frontend);
+ } else if (coreSource.is<mbgl::style::GeoJSONSource>()) {
+ return std::make_unique<GeoJSONSource>(env, *coreSource.as<mbgl::style::GeoJSONSource>(), frontend);
+ } else if (coreSource.is<mbgl::style::ImageSource>()) {
+ return std::make_unique<ImageSource>(env, *coreSource.as<mbgl::style::ImageSource>(), frontend);
+ } else {
+ return std::make_unique<UnknownSource>(env, coreSource, frontend);
}
+}
const jni::Object<Source>& Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) {
if (!coreSource.peer.has_value()) {
- coreSource.peer = createSourcePeer(env, coreSource, frontend);
+ coreSource.peer = createSourcePeer(env, coreSource, &frontend);
}
return coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer;
}
- Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, const jni::Object<Source>& obj, AndroidRendererFrontend& frontend)
- : source(coreSource)
- , javaPeer(jni::NewGlobal(env, obj))
- , rendererFrontend(&frontend) {
+ const jni::Object<Source>& Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource) {
+ if (!coreSource.peer.has_value()) {
+ coreSource.peer = createSourcePeer(env, coreSource, nullptr);
+ }
+ return coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer;
}
+ Source::Source(jni::JNIEnv& env,
+ mbgl::style::Source& coreSource,
+ const jni::Object<Source>& obj,
+ AndroidRendererFrontend* frontend)
+ : source(coreSource), javaPeer(jni::NewGlobal(env, obj)), rendererFrontend(frontend) {}
+
Source::Source(jni::JNIEnv&, std::unique_ptr<mbgl::style::Source> coreSource)
: ownedSource(std::move(coreSource))
, source(*ownedSource) {
diff --git a/platform/android/src/style/sources/source.hpp b/platform/android/src/style/sources/source.hpp
index a87972ce79..e0f2b2229f 100644
--- a/platform/android/src/style/sources/source.hpp
+++ b/platform/android/src/style/sources/source.hpp
@@ -19,12 +19,13 @@ public:
static void registerNative(jni::JNIEnv&);
+ static const jni::Object<Source>& peerForCoreSource(jni::JNIEnv&, mbgl::style::Source&);
static const jni::Object<Source>& peerForCoreSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
/*
* Called when a Java object is created for a core source that belongs to a map.
*/
- Source(jni::JNIEnv&, mbgl::style::Source&, const jni::Object<Source>&, AndroidRendererFrontend&);
+ Source(jni::JNIEnv&, mbgl::style::Source&, const jni::Object<Source>&, AndroidRendererFrontend*);
/*
* Called when a Java object is created for a new core source that does not belong to a map.
diff --git a/platform/android/src/style/sources/unknown_source.cpp b/platform/android/src/style/sources/unknown_source.cpp
index b5285a5f9f..acfd52db8d 100644
--- a/platform/android/src/style/sources/unknown_source.cpp
+++ b/platform/android/src/style/sources/unknown_source.cpp
@@ -12,17 +12,14 @@ namespace {
namespace mbgl {
namespace android {
- UnknownSource::UnknownSource(jni::JNIEnv& env,
- mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
-
- jni::Local<jni::Object<Source>> UnknownSource::createJavaPeer(jni::JNIEnv& env) {
- static auto& javaClass = jni::Class<UnknownSource>::Singleton(env);
- static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
- return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
- }
+UnknownSource::UnknownSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
+
+jni::Local<jni::Object<Source>> UnknownSource::createJavaPeer(jni::JNIEnv& env) {
+ static auto& javaClass = jni::Class<UnknownSource>::Singleton(env);
+ static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
+ return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
+}
void UnknownSource::registerNative(jni::JNIEnv& env) {
// Lookup the class
diff --git a/platform/android/src/style/sources/unknown_source.hpp b/platform/android/src/style/sources/unknown_source.hpp
index f042e2042c..ab5a2da82f 100644
--- a/platform/android/src/style/sources/unknown_source.hpp
+++ b/platform/android/src/style/sources/unknown_source.hpp
@@ -14,7 +14,7 @@ public:
static void registerNative(jni::JNIEnv&);
- UnknownSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ UnknownSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~UnknownSource() = default;
diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp
index e46fc1a94e..2be1a78119 100644
--- a/platform/android/src/style/sources/vector_source.cpp
+++ b/platform/android/src/style/sources/vector_source.cpp
@@ -30,11 +30,8 @@ namespace android {
) {
}
- VectorSource::VectorSource(jni::JNIEnv& env,
- mbgl::style::Source& coreSource,
- AndroidRendererFrontend& frontend)
- : Source(env, coreSource, createJavaPeer(env), frontend) {
- }
+ VectorSource::VectorSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend* frontend)
+ : Source(env, coreSource, createJavaPeer(env), frontend) {}
VectorSource::~VectorSource() = default;
diff --git a/platform/android/src/style/sources/vector_source.hpp b/platform/android/src/style/sources/vector_source.hpp
index 4cb46c6c62..7ae2e8c9e7 100644
--- a/platform/android/src/style/sources/vector_source.hpp
+++ b/platform/android/src/style/sources/vector_source.hpp
@@ -16,7 +16,7 @@ public:
static void registerNative(jni::JNIEnv&);
VectorSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
- VectorSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
+ VectorSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend*);
~VectorSource();
private: