summaryrefslogtreecommitdiff
path: root/platform/android/src/style
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/style')
-rw-r--r--platform/android/src/style/android_conversion.hpp5
-rw-r--r--platform/android/src/style/conversion/function.hpp211
-rw-r--r--platform/android/src/style/conversion/geojson.hpp4
-rw-r--r--platform/android/src/style/conversion/property_value.hpp67
-rw-r--r--platform/android/src/style/conversion/types.hpp2
-rw-r--r--platform/android/src/style/conversion/types.hpp.ejs2
-rw-r--r--platform/android/src/style/conversion/types_string_values.hpp24
-rw-r--r--platform/android/src/style/conversion/types_string_values.hpp.ejs6
-rw-r--r--platform/android/src/style/conversion/url_or_tileset.hpp2
-rw-r--r--platform/android/src/style/functions/categorical_stops.cpp18
-rw-r--r--platform/android/src/style/functions/categorical_stops.hpp23
-rw-r--r--platform/android/src/style/functions/exponential_stops.cpp18
-rw-r--r--platform/android/src/style/functions/exponential_stops.hpp24
-rw-r--r--platform/android/src/style/functions/identity_stops.cpp18
-rw-r--r--platform/android/src/style/functions/identity_stops.hpp21
-rw-r--r--platform/android/src/style/functions/interval_stops.cpp18
-rw-r--r--platform/android/src/style/functions/interval_stops.hpp23
-rw-r--r--platform/android/src/style/functions/stop.cpp21
-rw-r--r--platform/android/src/style/functions/stop.hpp36
-rw-r--r--platform/android/src/style/layers/background_layer.cpp17
-rw-r--r--platform/android/src/style/layers/background_layer.hpp2
-rw-r--r--platform/android/src/style/layers/circle_layer.cpp17
-rw-r--r--platform/android/src/style/layers/circle_layer.hpp2
-rw-r--r--platform/android/src/style/layers/custom_layer.cpp4
-rw-r--r--platform/android/src/style/layers/fill_layer.cpp17
-rw-r--r--platform/android/src/style/layers/fill_layer.hpp2
-rw-r--r--platform/android/src/style/layers/layer.cpp35
-rw-r--r--platform/android/src/style/layers/layer.cpp.ejs20
-rw-r--r--platform/android/src/style/layers/layer.hpp27
-rw-r--r--platform/android/src/style/layers/layer.hpp.ejs2
-rw-r--r--platform/android/src/style/layers/layers.cpp64
-rw-r--r--platform/android/src/style/layers/layers.hpp12
-rw-r--r--platform/android/src/style/layers/line_layer.cpp17
-rw-r--r--platform/android/src/style/layers/line_layer.hpp2
-rw-r--r--platform/android/src/style/layers/raster_layer.cpp17
-rw-r--r--platform/android/src/style/layers/raster_layer.hpp2
-rw-r--r--platform/android/src/style/layers/symbol_layer.cpp17
-rw-r--r--platform/android/src/style/layers/symbol_layer.hpp2
-rw-r--r--platform/android/src/style/layers/unknown_layer.cpp49
-rw-r--r--platform/android/src/style/layers/unknown_layer.hpp30
-rw-r--r--platform/android/src/style/sources/geojson_source.cpp10
-rw-r--r--platform/android/src/style/sources/raster_source.cpp4
-rw-r--r--platform/android/src/style/sources/source.cpp18
-rw-r--r--platform/android/src/style/sources/source.hpp16
-rw-r--r--platform/android/src/style/sources/sources.cpp10
-rw-r--r--platform/android/src/style/sources/sources.hpp8
-rw-r--r--platform/android/src/style/sources/unknown_source.cpp42
-rw-r--r--platform/android/src/style/sources/unknown_source.hpp28
-rw-r--r--platform/android/src/style/sources/vector_source.cpp4
-rw-r--r--platform/android/src/style/value.cpp2
50 files changed, 889 insertions, 153 deletions
diff --git a/platform/android/src/style/android_conversion.hpp b/platform/android/src/style/android_conversion.hpp
index de0ac91502..d9b88ab52b 100644
--- a/platform/android/src/style/android_conversion.hpp
+++ b/platform/android/src/style/android_conversion.hpp
@@ -4,7 +4,6 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/style/conversion.hpp>
-#include <mbgl/util/feature.hpp>
#include <mbgl/util/optional.hpp>
#include <jni/jni.hpp>
@@ -45,7 +44,7 @@ inline optional<mbgl::android::Value> objectMember(const mbgl::android::Value& v
template <class Fn>
optional<Error> eachMember(const mbgl::android::Value&, Fn&&) {
- //TODO
+ // TODO
mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented");
return {};
}
@@ -82,7 +81,7 @@ inline optional<Value> toValue(const mbgl::android::Value& value) {
} else if (value.isString()) {
return { value.toString() };
} else if (value.isNumber()) {
- //Need to cast to a double here as the float is otherwise considered a bool...
+ // Need to cast to a double here as the float is otherwise considered a bool...
return { (double) value.toNumber() };
} else {
return {};
diff --git a/platform/android/src/style/conversion/function.hpp b/platform/android/src/style/conversion/function.hpp
index 26dd5c21fd..ad01a7afc2 100644
--- a/platform/android/src/style/conversion/function.hpp
+++ b/platform/android/src/style/conversion/function.hpp
@@ -4,51 +4,224 @@
#include "../../conversion/conversion.hpp"
#include "../../conversion/constant.hpp"
#include "types.hpp"
-#include "function.hpp"
+#include "../../java/lang.hpp"
+#include "../functions/stop.hpp"
+#include "../functions/categorical_stops.hpp"
+#include "../functions/exponential_stops.hpp"
+#include "../functions/identity_stops.hpp"
+#include "../functions/interval_stops.hpp"
#include <jni/jni.hpp>
#include <tuple>
-#include <vector>
+#include <map>
namespace mbgl {
namespace android {
namespace conversion {
-template <class T>
-inline jni::jobject* toFunctionStopJavaArray(jni::JNIEnv& env, std::vector<std::pair<float, T>> value) {
- static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function$Stop")).release();
+/**
+ * Conversion from core composite value to java type
+ */
+class CategoricalValueEvaluator {
+public:
+
+ CategoricalValueEvaluator(jni::JNIEnv& _env) : env(_env) {}
+
+ template <class T>
+ jni::jobject* operator()(const T &value) const {
+ return *convert<jni::jobject*, T>(env, value);
+ }
+
+private:
+ jni::JNIEnv& env;
+};
+
+/**
+ * Conversion from core composite value to java type
+ */
+template <>
+struct Converter<jni::jobject*, mbgl::style::CategoricalValue> {
+
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CategoricalValue& value) const {
+ CategoricalValueEvaluator evaluator(env);
+ return apply_visitor(evaluator, value);
+ }
+};
+
+template <class I, class O>
+jni::Array<jni::Object<Stop>> toFunctionStopJavaArray(jni::JNIEnv& env, std::map<I, O> value) {
+
+ auto jarray = jni::Array<jni::Object<Stop>>::New(env, value.size(), Stop::javaClass);
+
+ size_t i = 0;
+ for (auto const& stop : value) {
+ jni::jobject* in = *convert<jni::jobject*, I>(env, stop.first);
+ jni::jobject* out = *convert<jni::jobject*, O>(env, stop.second);
+
+ auto jstop = Stop::New(env, jni::Object<>(in), jni::Object<>(out));
+ jarray.Set(env, i, jstop);
+
+ jni::DeleteLocalRef(env, in);
+ jni::DeleteLocalRef(env, out);
+ jni::DeleteLocalRef(env, jstop);
+
+ i++;
+ }
+
+ return jarray;
+}
+
+template <class I, class O>
+jni::Array<jni::Object<Stop>> toFunctionStopJavaArray(jni::JNIEnv& env, std::map<float, std::map<I, O>> value) {
+
+ auto jarray = jni::Array<jni::Object<Stop>>::New(env, value.size(), Stop::javaClass);
+
+ for (auto const& zoomLevelMap : value) {
+ size_t i = 0;
+ for (auto const& stop: zoomLevelMap.second) {
+ auto zoom = jni::Object<java::lang::Number>(*convert<jni::jobject*>(env, zoomLevelMap.first));
+ auto in = jni::Object<>(*convert<jni::jobject*, I>(env, stop.first));
+ auto out = jni::Object<>(*convert<jni::jobject*, O>(env, stop.second));
+ auto compositeValue = Stop::CompositeValue::New(env, zoom, in);
+
+ auto jstop = Stop::New(env, compositeValue, out);
+ jarray.Set(env, i, jstop);
+
+ jni::DeleteLocalRef(env, zoom);
+ jni::DeleteLocalRef(env, in);
+ jni::DeleteLocalRef(env, out);
+ jni::DeleteLocalRef(env, compositeValue);
+ jni::DeleteLocalRef(env, jstop);
+
+ i++;
+ }
+ }
+
+ return jarray;
+}
+
+template <class I, typename O>
+inline jni::jobject* convertCompositeStopsArray(jni::JNIEnv& env, std::map<float, std::map<I, O>> value) {
+ static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/Stop")).release();
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/Object;Ljava/lang/Object;)V");
jni::jarray<jni::jobject>& jarray = jni::NewObjectArray(env, value.size(), *javaClass);
- for(size_t i = 0; i < value.size(); i = i + 1) {
- jni::jobject* in = *convert<jni::jobject*, float>(env, value[i].first);
- jni::jobject* out = *convert<jni::jobject*, T>(env, value[i].second);
+ size_t i = 0;
+ for (auto const& stop : value) {
+ jni::jobject* in = *convert<jni::jobject*, I>(env, stop.first);
+ jni::jobject* out = *convert<jni::jobject*, O>(env, stop.second);
jni::SetObjectArrayElement(env, jarray, i, &jni::NewObject(env, *javaClass, *constructor, in, out));
+ i++;
+ jni::DeleteLocalRef(env, in);
+ jni::DeleteLocalRef(env, out);
}
return &jarray;
}
+/**
+ * Conversion from core function stops to Stops java subclasses
+ */
+template <class T>
+class StopsEvaluator {
+public:
+
+ StopsEvaluator(jni::JNIEnv& _env) : env(_env) {}
+
+ jni::jobject* operator()(const mbgl::style::CategoricalStops<T> &value) const {
+ return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::CompositeCategoricalStops<T> &value) const {
+ return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::ExponentialStops<T> &value) const {
+ return ExponentialStops::New(env, jni::Object<java::lang::Float>(*convert<jni::jobject*>(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::CompositeExponentialStops<T> &value) const {
+ return ExponentialStops::New(env, jni::Object<java::lang::Float>(*convert<jni::jobject*>(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::IdentityStops<T> &) const {
+ return IdentityStops::New(env).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::IntervalStops<T> &value) const {
+ return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+ jni::jobject* operator()(const mbgl::style::CompositeIntervalStops<T> &value) const {
+ return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
+ }
+
+private:
+ jni::JNIEnv& env;
+};
+
template <class T>
-struct Converter<jni::jobject*, mbgl::style::Function<T>> {
+struct Converter<jni::jobject*, mbgl::style::CameraFunction<T>> {
+
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction<T>& value) const {
+ static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/CameraFunction")).release();
+ static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>", "(Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
+
+ StopsEvaluator<T> evaluator(env);
+ jni::jobject* stops = apply_visitor(evaluator, value.stops);
+ jni::jobject* converted = &jni::NewObject(env, *clazz, *constructor, stops);
+
+ return { converted };
+ }
+};
+
+template <class T>
+struct Converter<jni::jobject*, mbgl::style::SourceFunction<T>> {
+
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::SourceFunction<T>& value) const {
+ static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/SourceFunction")).release();
+ static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>",
+ "(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
+
+ // Convert stops
+ StopsEvaluator<T> evaluator(env);
+ jni::jobject* stops = apply_visitor(evaluator, value.stops);
+
+ // Convert default value
+ jni::jobject* defaultValue = nullptr;
+ if (value.defaultValue) {
+ defaultValue = *convert<jni::jobject*>(env, *value.defaultValue);
+ }
+
+ return { &jni::NewObject(env, *clazz, *constructor, defaultValue, jni::Make<jni::String>(env, value.property).Get(), stops) };
+ }
+};
+
+template <class T>
+struct Converter<jni::jobject*, mbgl::style::CompositeFunction<T>> {
+
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction<T>& value) const {
+ static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/CompositeFunction")).release();
+ static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>",
+ "(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
- Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::Function<T>& value) const {
- static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function")).release();
- static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "([Lcom/mapbox/mapboxsdk/style/layers/Function$Stop;)V");
- static jni::jmethodID* withBase = &jni::GetMethodID(env, *javaClass, "withBase", "(F)Lcom/mapbox/mapboxsdk/style/layers/Function;");
+ // Convert stops
+ StopsEvaluator<T> evaluator(env);
+ jni::jobject* stops = apply_visitor(evaluator, value.stops);
- //Create object
- jni::jobject* jfunction = &jni::NewObject(env, *javaClass, *constructor, *toFunctionStopJavaArray(env, value.getStops()));
- //Set base
- jni::CallMethod<jni::jobject*>(env, jfunction, *withBase, value.getBase());
+ // Convert default value
+ jni::jobject* defaultValue = nullptr;
+ if (value.defaultValue) {
+ defaultValue = *convert<jni::jobject*>(env, *value.defaultValue);
+ }
- return {jfunction};
+ return { &jni::NewObject(env, *clazz, *constructor, defaultValue, jni::Make<jni::String>(env, value.property).Get(), stops) };
}
};
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/geojson.hpp b/platform/android/src/style/conversion/geojson.hpp
index 6bc48b3700..415d96f467 100644
--- a/platform/android/src/style/conversion/geojson.hpp
+++ b/platform/android/src/style/conversion/geojson.hpp
@@ -19,7 +19,7 @@ namespace conversion {
template <>
Result<GeoJSON> convertGeoJSON(const mbgl::android::Value& value) {
- //Value should be a string wrapped in an object
+ // 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" };
@@ -54,4 +54,4 @@ struct Converter<GeoJSON> {
} // namespace conversion
} // namespace style
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/property_value.hpp b/platform/android/src/style/conversion/property_value.hpp
index 4121192f3f..a58cf975a7 100644
--- a/platform/android/src/style/conversion/property_value.hpp
+++ b/platform/android/src/style/conversion/property_value.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/data_driven_property_value.hpp>
#include "../../conversion/conversion.hpp"
#include "../../conversion/constant.hpp"
#include "types.hpp"
@@ -10,29 +11,65 @@ namespace mbgl {
namespace android {
namespace conversion {
+/**
+ * Conversion from core property value types to Java property value types
+ */
+template <typename T>
+class PropertyValueEvaluator {
+public:
+
+ PropertyValueEvaluator(jni::JNIEnv& _env) : env(_env) {}
+
+ jni::jobject* operator()(const mbgl::style::Undefined) const {
+ return nullptr;
+ }
+
+ jni::jobject* operator()(const T &value) const {
+ Result<jni::jobject*> result = convert<jni::jobject*>(env, value);
+ return *result;
+ }
+
+ jni::jobject* operator()(const mbgl::style::CameraFunction<T> &value) const {
+ return *convert<jni::jobject*, mbgl::style::CameraFunction<T>>(env, value);
+ }
+
+ jni::jobject* operator()(const mbgl::style::SourceFunction<T> &value) const {
+ return *convert<jni::jobject*, mbgl::style::SourceFunction<T>>(env, value);
+ }
+
+ jni::jobject* operator()(const mbgl::style::CompositeFunction<T> &value) const {
+ return *convert<jni::jobject*, mbgl::style::CompositeFunction<T>>(env, value);
+ }
+
+private:
+ jni::JNIEnv& env;
+
+};
+
+/**
+ * Convert core property values to java
+ */
template <class T>
struct Converter<jni::jobject*, mbgl::style::PropertyValue<T>> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::PropertyValue<T>& value) const {
+ PropertyValueEvaluator<T> evaluator(env);
+ return value.evaluate(evaluator);
+ }
+};
- if(value.isUndefined()) {
- //Return a nullptr representing a Java null value
- return {nullptr};
- } else if (value.isConstant()) {
- //Time to convert the constant value
- Result<jni::jobject*> result = convert<jni::jobject*, T>(env, value.asConstant());
- return {*result};
- //return converted;
- } else if (value.isFunction()) {
- //Must be a function than
- return convert<jni::jobject*, mbgl::style::Function<T>>(env, value.asFunction());
- } else {
- throw std::runtime_error("Unknown property value type");
- }
+/**
+ * Convert core data driven property values to java
+ */
+template <class T>
+struct Converter<jni::jobject*, mbgl::style::DataDrivenPropertyValue<T>> {
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::DataDrivenPropertyValue<T>& value) const {
+ PropertyValueEvaluator<T> evaluator(env);
+ return value.evaluate(evaluator);
}
};
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/types.hpp b/platform/android/src/style/conversion/types.hpp
index 1c433bb264..d9921e582e 100644
--- a/platform/android/src/style/conversion/types.hpp
+++ b/platform/android/src/style/conversion/types.hpp
@@ -95,4 +95,4 @@ struct Converter<jni::jobject*, mbgl::style::CirclePitchScaleType> {
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/types.hpp.ejs b/platform/android/src/style/conversion/types.hpp.ejs
index d248d42b72..3cd4764015 100644
--- a/platform/android/src/style/conversion/types.hpp.ejs
+++ b/platform/android/src/style/conversion/types.hpp.ejs
@@ -37,4 +37,4 @@ struct Converter<jni::jobject*, mbgl::style::<%- propertyNativeType(property) %>
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/types_string_values.hpp b/platform/android/src/style/conversion/types_string_values.hpp
index 9f21a2fed9..e3108fdf5b 100644
--- a/platform/android/src/style/conversion/types_string_values.hpp
+++ b/platform/android/src/style/conversion/types_string_values.hpp
@@ -10,7 +10,7 @@ namespace mbgl {
namespace android {
namespace conversion {
- //visibility
+ // visibility
inline std::string toString(mbgl::style::VisibilityType value) {
switch (value) {
case mbgl::style::VisibilityType::Visible:
@@ -24,7 +24,7 @@ namespace conversion {
}
}
- //line-cap
+ // line-cap
inline std::string toString(mbgl::style::LineCapType value) {
switch (value) {
case mbgl::style::LineCapType::Butt:
@@ -41,7 +41,7 @@ namespace conversion {
}
}
- //line-join
+ // line-join
inline std::string toString(mbgl::style::LineJoinType value) {
switch (value) {
case mbgl::style::LineJoinType::Bevel:
@@ -58,7 +58,7 @@ namespace conversion {
}
}
- //symbol-placement
+ // symbol-placement
inline std::string toString(mbgl::style::SymbolPlacementType value) {
switch (value) {
case mbgl::style::SymbolPlacementType::Point:
@@ -72,7 +72,7 @@ namespace conversion {
}
}
- //icon-rotation-alignment
+ // icon-rotation-alignment
inline std::string toString(mbgl::style::AlignmentType value) {
switch (value) {
case mbgl::style::AlignmentType::Map:
@@ -89,7 +89,7 @@ namespace conversion {
}
}
- //icon-text-fit
+ // icon-text-fit
inline std::string toString(mbgl::style::IconTextFitType value) {
switch (value) {
case mbgl::style::IconTextFitType::None:
@@ -109,7 +109,7 @@ namespace conversion {
}
}
- //text-justify
+ // text-justify
inline std::string toString(mbgl::style::TextJustifyType value) {
switch (value) {
case mbgl::style::TextJustifyType::Left:
@@ -126,7 +126,7 @@ namespace conversion {
}
}
- //text-anchor
+ // text-anchor
inline std::string toString(mbgl::style::TextAnchorType value) {
switch (value) {
case mbgl::style::TextAnchorType::Center:
@@ -161,7 +161,7 @@ namespace conversion {
}
}
- //text-transform
+ // text-transform
inline std::string toString(mbgl::style::TextTransformType value) {
switch (value) {
case mbgl::style::TextTransformType::None:
@@ -178,7 +178,7 @@ namespace conversion {
}
}
- //fill-translate-anchor
+ // fill-translate-anchor
inline std::string toString(mbgl::style::TranslateAnchorType value) {
switch (value) {
case mbgl::style::TranslateAnchorType::Map:
@@ -192,7 +192,7 @@ namespace conversion {
}
}
- //circle-pitch-scale
+ // circle-pitch-scale
inline std::string toString(mbgl::style::CirclePitchScaleType value) {
switch (value) {
case mbgl::style::CirclePitchScaleType::Map:
@@ -209,4 +209,4 @@ namespace conversion {
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/types_string_values.hpp.ejs b/platform/android/src/style/conversion/types_string_values.hpp.ejs
index c1646baa1a..bf52919741 100644
--- a/platform/android/src/style/conversion/types_string_values.hpp.ejs
+++ b/platform/android/src/style/conversion/types_string_values.hpp.ejs
@@ -13,7 +13,7 @@ namespace mbgl {
namespace android {
namespace conversion {
- //visibility
+ // visibility
inline std::string toString(mbgl::style::VisibilityType value) {
switch (value) {
case mbgl::style::VisibilityType::Visible:
@@ -28,7 +28,7 @@ namespace conversion {
}
<% for (const property of properties) { -%>
- //<%- property.name %>
+ // <%- property.name %>
inline std::string toString(mbgl::style::<%- propertyNativeType(property) %> value) {
switch (value) {
<% for (const value in property.values) { -%>
@@ -45,4 +45,4 @@ namespace conversion {
} // namespace conversion
} // namespace android
-} // namespace mbgl \ No newline at end of file
+} // namespace mbgl
diff --git a/platform/android/src/style/conversion/url_or_tileset.hpp b/platform/android/src/style/conversion/url_or_tileset.hpp
index c1801f56d0..4e502324d0 100644
--- a/platform/android/src/style/conversion/url_or_tileset.hpp
+++ b/platform/android/src/style/conversion/url_or_tileset.hpp
@@ -35,4 +35,4 @@ struct Converter<variant<std::string, Tileset>> {
}
}
-} \ No newline at end of file
+}
diff --git a/platform/android/src/style/functions/categorical_stops.cpp b/platform/android/src/style/functions/categorical_stops.cpp
new file mode 100644
index 0000000000..2aff9730a7
--- /dev/null
+++ b/platform/android/src/style/functions/categorical_stops.cpp
@@ -0,0 +1,18 @@
+#include "categorical_stops.hpp"
+
+namespace mbgl {
+namespace android {
+
+jni::Object<CategoricalStops> CategoricalStops::New(jni::JNIEnv& env, jni::Array<jni::Object<Stop>> stops) {
+ static auto constructor = CategoricalStops::javaClass.GetConstructor<jni::Array<jni::Object<Stop>>>(env);
+ return CategoricalStops::javaClass.New(env, constructor, stops);
+}
+
+jni::Class<CategoricalStops> CategoricalStops::javaClass;
+
+void CategoricalStops::registerNative(jni::JNIEnv& env) {
+ CategoricalStops::javaClass = *jni::Class<CategoricalStops>::Find(env).NewGlobalRef(env).release();
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/categorical_stops.hpp b/platform/android/src/style/functions/categorical_stops.hpp
new file mode 100644
index 0000000000..a198c8d5c9
--- /dev/null
+++ b/platform/android/src/style/functions/categorical_stops.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <jni/jni.hpp>
+
+#include "stop.hpp"
+
+namespace mbgl {
+namespace android {
+
+class CategoricalStops : private mbgl::util::noncopyable {
+public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops"; };
+
+ static jni::Object<CategoricalStops> New(jni::JNIEnv&, jni::Array<jni::Object<Stop>>);
+
+ static jni::Class<CategoricalStops> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+};
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/exponential_stops.cpp b/platform/android/src/style/functions/exponential_stops.cpp
new file mode 100644
index 0000000000..6390a0ec35
--- /dev/null
+++ b/platform/android/src/style/functions/exponential_stops.cpp
@@ -0,0 +1,18 @@
+#include "exponential_stops.hpp"
+
+namespace mbgl {
+namespace android {
+
+jni::Object<ExponentialStops> ExponentialStops::New(jni::JNIEnv& env, jni::Object<java::lang::Float> base, jni::Array<jni::Object<Stop>> stops) {
+ static auto constructor = ExponentialStops::javaClass.GetConstructor<jni::Object<java::lang::Float>, jni::Array<jni::Object<Stop>>>(env);
+ return ExponentialStops::javaClass.New(env, constructor, base, stops);
+}
+
+jni::Class<ExponentialStops> ExponentialStops::javaClass;
+
+void ExponentialStops::registerNative(jni::JNIEnv& env) {
+ ExponentialStops::javaClass = *jni::Class<ExponentialStops>::Find(env).NewGlobalRef(env).release();
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/exponential_stops.hpp b/platform/android/src/style/functions/exponential_stops.hpp
new file mode 100644
index 0000000000..391d723cef
--- /dev/null
+++ b/platform/android/src/style/functions/exponential_stops.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <jni/jni.hpp>
+
+#include "../../java/lang.hpp"
+#include "stop.hpp"
+
+namespace mbgl {
+namespace android {
+
+class ExponentialStops : private mbgl::util::noncopyable {
+public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops"; };
+
+ static jni::Object<ExponentialStops> New(jni::JNIEnv&, jni::Object<java::lang::Float>, jni::Array<jni::Object<Stop>>);
+
+ static jni::Class<ExponentialStops> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+};
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/identity_stops.cpp b/platform/android/src/style/functions/identity_stops.cpp
new file mode 100644
index 0000000000..239b0ddb88
--- /dev/null
+++ b/platform/android/src/style/functions/identity_stops.cpp
@@ -0,0 +1,18 @@
+#include "identity_stops.hpp"
+
+namespace mbgl {
+namespace android {
+
+jni::Object<IdentityStops> IdentityStops::New(jni::JNIEnv& env) {
+ static auto constructor = IdentityStops::javaClass.GetConstructor<>(env);
+ return IdentityStops::javaClass.New(env, constructor);
+}
+
+jni::Class<IdentityStops> IdentityStops::javaClass;
+
+void IdentityStops::registerNative(jni::JNIEnv& env) {
+ IdentityStops::javaClass = *jni::Class<IdentityStops>::Find(env).NewGlobalRef(env).release();
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/identity_stops.hpp b/platform/android/src/style/functions/identity_stops.hpp
new file mode 100644
index 0000000000..150b2135f0
--- /dev/null
+++ b/platform/android/src/style/functions/identity_stops.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <jni/jni.hpp>
+
+namespace mbgl {
+namespace android {
+
+class IdentityStops : private mbgl::util::noncopyable {
+public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IdentityStops"; };
+
+ static jni::Object<IdentityStops> New(jni::JNIEnv&);
+
+ static jni::Class<IdentityStops> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+};
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/interval_stops.cpp b/platform/android/src/style/functions/interval_stops.cpp
new file mode 100644
index 0000000000..c3d9b6513f
--- /dev/null
+++ b/platform/android/src/style/functions/interval_stops.cpp
@@ -0,0 +1,18 @@
+#include "interval_stops.hpp"
+
+namespace mbgl {
+namespace android {
+
+jni::Object<IntervalStops> IntervalStops::New(jni::JNIEnv& env, jni::Array<jni::Object<Stop>> stops) {
+ static auto constructor = IntervalStops::javaClass.GetConstructor<jni::Array<jni::Object<Stop>>>(env);
+ return IntervalStops::javaClass.New(env, constructor, stops);
+}
+
+jni::Class<IntervalStops> IntervalStops::javaClass;
+
+void IntervalStops::registerNative(jni::JNIEnv& env) {
+ IntervalStops::javaClass = *jni::Class<IntervalStops>::Find(env).NewGlobalRef(env).release();
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/interval_stops.hpp b/platform/android/src/style/functions/interval_stops.hpp
new file mode 100644
index 0000000000..e3f75159cf
--- /dev/null
+++ b/platform/android/src/style/functions/interval_stops.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <jni/jni.hpp>
+
+#include "stop.hpp"
+
+namespace mbgl {
+namespace android {
+
+class IntervalStops : private mbgl::util::noncopyable {
+public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IntervalStops"; };
+
+ static jni::Object<IntervalStops> New(jni::JNIEnv&, jni::Array<jni::Object<Stop>>);
+
+ static jni::Class<IntervalStops> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+};
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/stop.cpp b/platform/android/src/style/functions/stop.cpp
new file mode 100644
index 0000000000..f9ed4b7368
--- /dev/null
+++ b/platform/android/src/style/functions/stop.cpp
@@ -0,0 +1,21 @@
+#include "interval_stops.hpp"
+
+namespace mbgl {
+namespace android {
+
+jni::Object<Stop::CompositeValue> Stop::CompositeValue::New(jni::JNIEnv& env, jni::Object<java::lang::Number> zoom, jni::Object<> value) {
+ static auto constructor = Stop::CompositeValue::javaClass.GetConstructor<jni::Object<java::lang::Number>, jni::Object<>>(env);
+ return Stop::CompositeValue::javaClass.New(env, constructor, zoom, value);
+}
+
+jni::Class<Stop> Stop::javaClass;
+
+jni::Class<Stop::CompositeValue> Stop::CompositeValue::javaClass;
+
+void Stop::registerNative(jni::JNIEnv& env) {
+ Stop::javaClass = *jni::Class<Stop>::Find(env).NewGlobalRef(env).release();
+ Stop::CompositeValue::javaClass = *jni::Class<Stop::CompositeValue>::Find(env).NewGlobalRef(env).release();
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/functions/stop.hpp b/platform/android/src/style/functions/stop.hpp
new file mode 100644
index 0000000000..7c697db65d
--- /dev/null
+++ b/platform/android/src/style/functions/stop.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <jni/jni.hpp>
+
+#include "../../java/lang.hpp"
+
+namespace mbgl {
+namespace android {
+
+class Stop : private mbgl::util::noncopyable {
+public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop"; };
+
+ template<class I, class O>
+ static jni::Object<Stop> New(jni::JNIEnv& env, jni::Object<I> in, jni::Object<O> out) {
+ static auto constructor = Stop::javaClass.GetConstructor<jni::Object<>, jni::Object<>>(env);
+ return Stop::javaClass.New(env, constructor, (jni::Object<>) in, (jni::Object<>) out);
+ }
+
+ static jni::Class<Stop> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+
+ class CompositeValue : private mbgl::util::noncopyable {
+ public:
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop$CompositeValue"; };
+
+ static jni::Object<Stop::CompositeValue> New(jni::JNIEnv&, jni::Object<java::lang::Number>, jni::Object<>);
+
+ static jni::Class<Stop::CompositeValue> javaClass;
+ };
+};
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/layers/background_layer.cpp b/platform/android/src/style/layers/background_layer.cpp
index 021ac947ad..9915f3894e 100644
--- a/platform/android/src/style/layers/background_layer.cpp
+++ b/platform/android/src/style/layers/background_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
BackgroundLayer::BackgroundLayer(jni::JNIEnv& env, jni::String layerId)
: Layer(env, std::make_unique<mbgl::style::BackgroundLayer>(jni::Make<std::string>(env, layerId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
BackgroundLayer::BackgroundLayer(mbgl::Map& map, mbgl::style::BackgroundLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ BackgroundLayer::BackgroundLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::BackgroundLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
BackgroundLayer::~BackgroundLayer() = default;
// Property getters
@@ -47,12 +60,12 @@ namespace android {
}
void BackgroundLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
BackgroundLayer::javaClass = *jni::Class<BackgroundLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<BackgroundLayer>(
env, BackgroundLayer::javaClass, "nativePtr",
std::make_unique<BackgroundLayer, JNIEnv&, jni::String>,
diff --git a/platform/android/src/style/layers/background_layer.hpp b/platform/android/src/style/layers/background_layer.hpp
index bd62c024f4..2fdc948892 100644
--- a/platform/android/src/style/layers/background_layer.hpp
+++ b/platform/android/src/style/layers/background_layer.hpp
@@ -22,6 +22,8 @@ public:
BackgroundLayer(mbgl::Map&, mbgl::style::BackgroundLayer&);
+ BackgroundLayer(mbgl::Map&, std::unique_ptr<mbgl::style::BackgroundLayer>);
+
~BackgroundLayer();
// Property getters
diff --git a/platform/android/src/style/layers/circle_layer.cpp b/platform/android/src/style/layers/circle_layer.cpp
index 4a6ba95d31..948c397829 100644
--- a/platform/android/src/style/layers/circle_layer.cpp
+++ b/platform/android/src/style/layers/circle_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
CircleLayer::CircleLayer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::CircleLayer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
CircleLayer::CircleLayer(mbgl::Map& map, mbgl::style::CircleLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ CircleLayer::CircleLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::CircleLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
CircleLayer::~CircleLayer() = default;
// Property getters
@@ -89,12 +102,12 @@ namespace android {
}
void CircleLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
CircleLayer::javaClass = *jni::Class<CircleLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<CircleLayer>(
env, CircleLayer::javaClass, "nativePtr",
std::make_unique<CircleLayer, JNIEnv&, jni::String, jni::String>,
diff --git a/platform/android/src/style/layers/circle_layer.hpp b/platform/android/src/style/layers/circle_layer.hpp
index d45984f23b..ee988d7c57 100644
--- a/platform/android/src/style/layers/circle_layer.hpp
+++ b/platform/android/src/style/layers/circle_layer.hpp
@@ -22,6 +22,8 @@ public:
CircleLayer(mbgl::Map&, mbgl::style::CircleLayer&);
+ CircleLayer(mbgl::Map&, std::unique_ptr<mbgl::style::CircleLayer>);
+
~CircleLayer();
// Property getters
diff --git a/platform/android/src/style/layers/custom_layer.cpp b/platform/android/src/style/layers/custom_layer.cpp
index d5d330a019..9bdc308d85 100644
--- a/platform/android/src/style/layers/custom_layer.cpp
+++ b/platform/android/src/style/layers/custom_layer.cpp
@@ -40,12 +40,12 @@ namespace android {
}
void CustomLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
CustomLayer::javaClass = *jni::Class<CustomLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<CustomLayer>(
env, CustomLayer::javaClass, "nativePtr",
std::make_unique<CustomLayer, JNIEnv&, jni::String, jni::jlong, jni::jlong, jni::jlong, jni::jlong>,
diff --git a/platform/android/src/style/layers/fill_layer.cpp b/platform/android/src/style/layers/fill_layer.cpp
index 84d47b6afe..fc1dfccfcc 100644
--- a/platform/android/src/style/layers/fill_layer.cpp
+++ b/platform/android/src/style/layers/fill_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
FillLayer::FillLayer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::FillLayer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
FillLayer::FillLayer(mbgl::Map& map, mbgl::style::FillLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ FillLayer::FillLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::FillLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
FillLayer::~FillLayer() = default;
// Property getters
@@ -71,12 +84,12 @@ namespace android {
}
void FillLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
FillLayer::javaClass = *jni::Class<FillLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<FillLayer>(
env, FillLayer::javaClass, "nativePtr",
std::make_unique<FillLayer, JNIEnv&, jni::String, jni::String>,
diff --git a/platform/android/src/style/layers/fill_layer.hpp b/platform/android/src/style/layers/fill_layer.hpp
index 7609a5742f..f43c263ab8 100644
--- a/platform/android/src/style/layers/fill_layer.hpp
+++ b/platform/android/src/style/layers/fill_layer.hpp
@@ -22,6 +22,8 @@ public:
FillLayer(mbgl::Map&, mbgl::style::FillLayer&);
+ FillLayer(mbgl::Map&, std::unique_ptr<mbgl::style::FillLayer>);
+
~FillLayer();
// Property getters
diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp
index c0c57c839d..dbf71fd2af 100644
--- a/platform/android/src/style/layers/layer.cpp
+++ b/platform/android/src/style/layers/layer.cpp
@@ -5,12 +5,12 @@
#include <mbgl/util/logging.hpp>
-//Java -> C++ conversion
+// Java -> C++ conversion
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/source.hpp>
-//C++ -> Java conversion
+// C++ -> Java conversion
#include "../conversion/property_value.hpp"
#include <string>
@@ -26,22 +26,35 @@ namespace android {
, layer(*ownedLayer) {
}
+ /**
+ * Takes a non-owning reference. For lookup methods
+ */
Layer::Layer(mbgl::Map& coreMap, mbgl::style::Layer& coreLayer) : layer(coreLayer) , map(&coreMap) {
}
+ /**
+ * Takes a owning reference. Ownership is transfered to this peer, eg after removing
+ * from the map
+ */
+ Layer::Layer(mbgl::Map& coreMap, std::unique_ptr<mbgl::style::Layer> coreLayer)
+ : ownedLayer(std::move(coreLayer))
+ , layer(*ownedLayer)
+ , map(&coreMap) {
+ }
+
Layer::~Layer() {
}
void Layer::addToMap(mbgl::Map& _map, mbgl::optional<std::string> before) {
- //Check to see if we own the layer first
+ // Check to see if we own the layer first
if (!ownedLayer) {
throw std::runtime_error("Cannot add layer twice");
}
- //Add layer to map
+ // Add layer to map
_map.addLayer(releaseCoreLayer(), before);
- //Save pointer to the map
+ // Save pointer to the map
this->map = &_map;
}
@@ -65,7 +78,7 @@ namespace android {
void Layer::setLayoutProperty(jni::JNIEnv& env, jni::String jname, jni::Object<> jvalue) {
Value value(env, jvalue);
- //Convert and set property
+ // Convert and set property
optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setLayoutProperty(layer, jni::Make<std::string>(env, jname), value);
if (error) {
mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make<std::string>(env, jname) + " " + error->message);
@@ -76,7 +89,7 @@ namespace android {
void Layer::setPaintProperty(jni::JNIEnv& env, jni::String jname, jni::Object<> jvalue) {
Value value(env, jvalue);
- //Convert and set property
+ // Convert and set property
optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setPaintProperty(layer, jni::Make<std::string>(env, jname), value, mbgl::optional<std::string>());
if (error) {
mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make<std::string>(env, jname) + " " + error->message);
@@ -153,12 +166,12 @@ namespace android {
jni::Class<Layer> Layer::javaClass;
void Layer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
Layer::javaClass = *jni::Class<Layer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<Layer>(env, Layer::javaClass, "nativePtr",
METHOD(&Layer::getId, "nativeGetId"),
METHOD(&Layer::setLayoutProperty, "nativeSetLayoutProperty"),
@@ -174,5 +187,5 @@ namespace android {
}
-} //android
-} //mbgl \ No newline at end of file
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/layers/layer.cpp.ejs b/platform/android/src/style/layers/layer.cpp.ejs
index 500c76ea7a..5da397d77d 100644
--- a/platform/android/src/style/layers/layer.cpp.ejs
+++ b/platform/android/src/style/layers/layer.cpp.ejs
@@ -14,18 +14,34 @@ namespace mbgl {
namespace android {
<% if (type === 'background') { -%>
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId)
: Layer(env, std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId))) {
<% } else { -%>
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::<%- camelize(type) %>Layer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
<% } -%>
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::Map& map, mbgl::style::<%- camelize(type) %>Layer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::Map& map, std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;
// Property getters
@@ -46,12 +62,12 @@ namespace android {
}
void <%- camelize(type) %>Layer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
<%- camelize(type) %>Layer::javaClass = *jni::Class<<%- camelize(type) %>Layer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<<%- camelize(type) %>Layer>(
env, <%- camelize(type) %>Layer::javaClass, "nativePtr",
<% if (type === 'background') { -%>
diff --git a/platform/android/src/style/layers/layer.hpp b/platform/android/src/style/layers/layer.hpp
index f3cd073552..deea7a6613 100644
--- a/platform/android/src/style/layers/layer.hpp
+++ b/platform/android/src/style/layers/layer.hpp
@@ -21,11 +21,16 @@ public:
static void registerNative(jni::JNIEnv&);
/*
- * Called when a Java object is created on the c++ side
+ * Called when a non-owning peer object is created on the c++ side
*/
Layer(mbgl::Map&, mbgl::style::Layer&);
/*
+ * Called when a owning peer object is created on the c++ side
+ */
+ Layer(mbgl::Map&, std::unique_ptr<mbgl::style::Layer>);
+
+ /*
* Called when a Java object was created from the jvm side
*/
Layer(jni::JNIEnv&, std::unique_ptr<mbgl::style::Layer>);
@@ -49,7 +54,7 @@ public:
void setPaintProperty(jni::JNIEnv&, jni::String, jni::Object<> value);
- //Zoom
+ // Zoom
jni::jfloat getMinZoom(jni::JNIEnv&);
@@ -65,28 +70,24 @@ public:
void setSourceLayer(jni::JNIEnv& env, jni::String sourceLayer);
- //Property getters
+ // Property getters
jni::Object<jni::ObjectTag> getVisibility(jni::JNIEnv&);
protected:
- //Release the owned view and return it
+ // Release the owned view and return it
std::unique_ptr<mbgl::style::Layer> releaseCoreLayer();
- //Owned layer is set when creating a new layer, before adding it to the map
+ // Owned layer is set when creating a new layer, before adding it to the map
std::unique_ptr<mbgl::style::Layer> ownedLayer;
- //Raw reference to the layer
+ // Raw reference to the layer
mbgl::style::Layer& layer;
- //Map is set when the layer is retrieved or after adding to the map
+ // Map is set when the layer is retrieved or after adding to the map
mbgl::Map* map;
};
-} //android
-} //mbgl
-
-
-
-
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/layers/layer.hpp.ejs b/platform/android/src/style/layers/layer.hpp.ejs
index 3d715746ff..102efd2d4d 100644
--- a/platform/android/src/style/layers/layer.hpp.ejs
+++ b/platform/android/src/style/layers/layer.hpp.ejs
@@ -30,6 +30,8 @@ public:
<%- camelize(type) %>Layer(mbgl::Map&, mbgl::style::<%- camelize(type) %>Layer&);
+ <%- camelize(type) %>Layer(mbgl::Map&, std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer>);
+
~<%- camelize(type) %>Layer();
// Property getters
diff --git a/platform/android/src/style/layers/layers.cpp b/platform/android/src/style/layers/layers.cpp
index 57dbf6f4b1..5c6ee1ae8f 100644
--- a/platform/android/src/style/layers/layers.cpp
+++ b/platform/android/src/style/layers/layers.cpp
@@ -1,5 +1,6 @@
#include "layers.hpp"
+#include <mbgl/style/layer.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -10,55 +11,86 @@
#include "background_layer.hpp"
#include "circle_layer.hpp"
+#include "custom_layer.hpp"
#include "fill_layer.hpp"
#include "line_layer.hpp"
#include "raster_layer.hpp"
#include "symbol_layer.hpp"
-#include "custom_layer.hpp"
+#include "unknown_layer.hpp"
namespace mbgl {
namespace android {
-Layer* initializeLayerPeer(mbgl::Map& map, mbgl::style::Layer& coreLayer) {
- Layer* layer;
+static Layer* initializeLayerPeer(mbgl::Map& map, mbgl::style::Layer& coreLayer) {
if (coreLayer.is<mbgl::style::BackgroundLayer>()) {
- layer = new BackgroundLayer(map, *coreLayer.as<mbgl::style::BackgroundLayer>());
+ return new BackgroundLayer(map, *coreLayer.as<mbgl::style::BackgroundLayer>());
} else if (coreLayer.is<mbgl::style::CircleLayer>()) {
- layer = new CircleLayer(map, *coreLayer.as<mbgl::style::CircleLayer>());
+ return new CircleLayer(map, *coreLayer.as<mbgl::style::CircleLayer>());
} else if (coreLayer.is<mbgl::style::FillLayer>()) {
- layer = new FillLayer(map, *coreLayer.as<mbgl::style::FillLayer>());
+ return new FillLayer(map, *coreLayer.as<mbgl::style::FillLayer>());
} else if (coreLayer.is<mbgl::style::LineLayer>()) {
- layer = new LineLayer(map, *coreLayer.as<mbgl::style::LineLayer>());
+ return new LineLayer(map, *coreLayer.as<mbgl::style::LineLayer>());
} else if (coreLayer.is<mbgl::style::RasterLayer>()) {
- layer = new RasterLayer(map, *coreLayer.as<mbgl::style::RasterLayer>());
+ return new RasterLayer(map, *coreLayer.as<mbgl::style::RasterLayer>());
} else if (coreLayer.is<mbgl::style::SymbolLayer>()) {
- layer = new SymbolLayer(map, *coreLayer.as<mbgl::style::SymbolLayer>());
+ return new SymbolLayer(map, *coreLayer.as<mbgl::style::SymbolLayer>());
} else if (coreLayer.is<mbgl::style::CustomLayer>()) {
- layer = new CustomLayer(map, *coreLayer.as<mbgl::style::CustomLayer>());
+ return new CustomLayer(map, *coreLayer.as<mbgl::style::CustomLayer>());
} else {
- throw new std::runtime_error("Layer type not implemented");
+ return new UnknownLayer(map, coreLayer);
}
+}
- return layer;
+template <class LayerType, class PeerType>
+static PeerType* createPeer(Map& map, std::unique_ptr<mbgl::style::Layer> layer) {
+ return new PeerType(map, std::move(std::unique_ptr<LayerType>(layer.release()->as<LayerType>())));
+}
+
+static Layer* initializeLayerPeer(Map& map, std::unique_ptr<mbgl::style::Layer> coreLayer) {
+ if (coreLayer->is<style::BackgroundLayer>()) {
+ return createPeer<style::BackgroundLayer, BackgroundLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<style::CircleLayer>()) {
+ return createPeer<style::CircleLayer, CircleLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<style::FillLayer>()) {
+ return createPeer<style::FillLayer, FillLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<style::LineLayer>()) {
+ return createPeer<style::LineLayer, LineLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<style::RasterLayer>()) {
+ return createPeer<style::RasterLayer, RasterLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<style::SymbolLayer>()) {
+ return createPeer<style::SymbolLayer, SymbolLayer>(map, std::move(coreLayer));
+ } else if (coreLayer->is<mbgl::style::CustomLayer>()) {
+ return createPeer<style::SymbolLayer, SymbolLayer>(map, std::move(coreLayer));
+ } else {
+ return new UnknownLayer(map, std::move(coreLayer));
+ }
}
-jni::jobject* createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, mbgl::style::Layer& coreLayer) {
+jni::jobject* createJavaLayerPeer(jni::JNIEnv& env, Map& map, style::Layer& coreLayer) {
std::unique_ptr<Layer> peerLayer = std::unique_ptr<Layer>(initializeLayerPeer(map, coreLayer));
jni::jobject* result = peerLayer->createJavaPeer(env);
peerLayer.release();
return result;
}
+jni::jobject* createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, std::unique_ptr<mbgl::style::Layer> coreLayer) {
+ std::unique_ptr<Layer> peerLayer = std::unique_ptr<Layer>(initializeLayerPeer(map, std::move(coreLayer)));
+ jni::jobject* result = peerLayer->createJavaPeer(env);
+ peerLayer.release();
+ return result;
+}
+
void registerNativeLayers(jni::JNIEnv& env) {
Layer::registerNative(env);
BackgroundLayer::registerNative(env);
CircleLayer::registerNative(env);
+ CustomLayer::registerNative(env);
FillLayer::registerNative(env);
LineLayer::registerNative(env);
RasterLayer::registerNative(env);
SymbolLayer::registerNative(env);
- CustomLayer::registerNative(env);
+ UnknownLayer::registerNative(env);
}
-} //android
-} //mbgl \ No newline at end of file
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/layers/layers.hpp b/platform/android/src/style/layers/layers.hpp
index 0c979ec2cf..75863a324a 100644
--- a/platform/android/src/style/layers/layers.hpp
+++ b/platform/android/src/style/layers/layers.hpp
@@ -10,11 +10,17 @@
namespace mbgl {
namespace android {
-mbgl::android::Layer* initializeLayerPeer(mbgl::Map&, mbgl::style::Layer&);
-
+/**
+ * Create a non-owning peer
+ */
jni::jobject* createJavaLayerPeer(jni::JNIEnv&, mbgl::Map&, mbgl::style::Layer&);
+/**
+ * Create an owning peer
+ */
+jni::jobject* createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, std::unique_ptr<mbgl::style::Layer>);
+
void registerNativeLayers(jni::JNIEnv&);
}
-} \ No newline at end of file
+}
diff --git a/platform/android/src/style/layers/line_layer.cpp b/platform/android/src/style/layers/line_layer.cpp
index 2dce8b618a..1a3a666a7b 100644
--- a/platform/android/src/style/layers/line_layer.cpp
+++ b/platform/android/src/style/layers/line_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
LineLayer::LineLayer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::LineLayer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
LineLayer::LineLayer(mbgl::Map& map, mbgl::style::LineLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ LineLayer::LineLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::LineLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
LineLayer::~LineLayer() = default;
// Property getters
@@ -113,12 +126,12 @@ namespace android {
}
void LineLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
LineLayer::javaClass = *jni::Class<LineLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<LineLayer>(
env, LineLayer::javaClass, "nativePtr",
std::make_unique<LineLayer, JNIEnv&, jni::String, jni::String>,
diff --git a/platform/android/src/style/layers/line_layer.hpp b/platform/android/src/style/layers/line_layer.hpp
index e2fc93329e..a79c8b9021 100644
--- a/platform/android/src/style/layers/line_layer.hpp
+++ b/platform/android/src/style/layers/line_layer.hpp
@@ -22,6 +22,8 @@ public:
LineLayer(mbgl::Map&, mbgl::style::LineLayer&);
+ LineLayer(mbgl::Map&, std::unique_ptr<mbgl::style::LineLayer>);
+
~LineLayer();
// Property getters
diff --git a/platform/android/src/style/layers/raster_layer.cpp b/platform/android/src/style/layers/raster_layer.cpp
index 25b26155ae..8a324b88f2 100644
--- a/platform/android/src/style/layers/raster_layer.cpp
+++ b/platform/android/src/style/layers/raster_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
RasterLayer::RasterLayer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::RasterLayer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
RasterLayer::RasterLayer(mbgl::Map& map, mbgl::style::RasterLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ RasterLayer::RasterLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::RasterLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
RasterLayer::~RasterLayer() = default;
// Property getters
@@ -71,12 +84,12 @@ namespace android {
}
void RasterLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
RasterLayer::javaClass = *jni::Class<RasterLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<RasterLayer>(
env, RasterLayer::javaClass, "nativePtr",
std::make_unique<RasterLayer, JNIEnv&, jni::String, jni::String>,
diff --git a/platform/android/src/style/layers/raster_layer.hpp b/platform/android/src/style/layers/raster_layer.hpp
index 3cc2d96dde..2f5d4f6fcd 100644
--- a/platform/android/src/style/layers/raster_layer.hpp
+++ b/platform/android/src/style/layers/raster_layer.hpp
@@ -22,6 +22,8 @@ public:
RasterLayer(mbgl::Map&, mbgl::style::RasterLayer&);
+ RasterLayer(mbgl::Map&, std::unique_ptr<mbgl::style::RasterLayer>);
+
~RasterLayer();
// Property getters
diff --git a/platform/android/src/style/layers/symbol_layer.cpp b/platform/android/src/style/layers/symbol_layer.cpp
index 9318d42d5b..e42eeb4c77 100644
--- a/platform/android/src/style/layers/symbol_layer.cpp
+++ b/platform/android/src/style/layers/symbol_layer.cpp
@@ -9,14 +9,27 @@
namespace mbgl {
namespace android {
+ /**
+ * Creates an owning peer object (for layers not attached to the map) from the JVM side
+ */
SymbolLayer::SymbolLayer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId)
: Layer(env, std::make_unique<mbgl::style::SymbolLayer>(jni::Make<std::string>(env, layerId), jni::Make<std::string>(env, sourceId))) {
}
+ /**
+ * Creates a non-owning peer object (for layers currently attached to the map)
+ */
SymbolLayer::SymbolLayer(mbgl::Map& map, mbgl::style::SymbolLayer& coreLayer)
: Layer(map, coreLayer) {
}
+ /**
+ * Creates an owning peer object (for layers not attached to the map)
+ */
+ SymbolLayer::SymbolLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::SymbolLayer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
SymbolLayer::~SymbolLayer() = default;
// Property getters
@@ -317,12 +330,12 @@ namespace android {
}
void SymbolLayer::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
SymbolLayer::javaClass = *jni::Class<SymbolLayer>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<SymbolLayer>(
env, SymbolLayer::javaClass, "nativePtr",
std::make_unique<SymbolLayer, JNIEnv&, jni::String, jni::String>,
diff --git a/platform/android/src/style/layers/symbol_layer.hpp b/platform/android/src/style/layers/symbol_layer.hpp
index 1048b01b14..98ce5572e9 100644
--- a/platform/android/src/style/layers/symbol_layer.hpp
+++ b/platform/android/src/style/layers/symbol_layer.hpp
@@ -22,6 +22,8 @@ public:
SymbolLayer(mbgl::Map&, mbgl::style::SymbolLayer&);
+ SymbolLayer(mbgl::Map&, std::unique_ptr<mbgl::style::SymbolLayer>);
+
~SymbolLayer();
// Property getters
diff --git a/platform/android/src/style/layers/unknown_layer.cpp b/platform/android/src/style/layers/unknown_layer.cpp
new file mode 100644
index 0000000000..9ec963a41b
--- /dev/null
+++ b/platform/android/src/style/layers/unknown_layer.cpp
@@ -0,0 +1,49 @@
+#include "unknown_layer.hpp"
+
+#include <string>
+
+namespace {
+
+ // Dummy initializer (We don't support initializing this from the JVM)
+ std::unique_ptr<mbgl::android::UnknownLayer> init(jni::JNIEnv&) {
+ throw new std::runtime_error("UnknownLayer should not be initialized from the JVM");
+ }
+
+} // namespace
+
+namespace mbgl {
+namespace android {
+
+ UnknownLayer::UnknownLayer(mbgl::Map& map, mbgl::style::Layer& coreLayer)
+ : Layer(map, coreLayer) {
+ }
+
+ UnknownLayer::UnknownLayer(mbgl::Map& map, std::unique_ptr<mbgl::style::Layer> coreLayer)
+ : Layer(map, std::move(coreLayer)) {
+ }
+
+ jni::Class<UnknownLayer> UnknownLayer::javaClass;
+
+ jni::jobject* UnknownLayer::createJavaPeer(jni::JNIEnv& env) {
+ static auto constructor = UnknownLayer::javaClass.template GetConstructor<jni::jlong>(env);
+ return UnknownLayer::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
+ }
+
+ void UnknownLayer::registerNative(jni::JNIEnv& env) {
+ // Lookup the class
+ UnknownLayer::javaClass = *jni::Class<UnknownLayer>::Find(env).NewGlobalRef(env).release();
+
+ #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
+
+ std::function<std::unique_ptr<UnknownLayer>(JNIEnv&)> initializer = nullptr;
+
+ // Register the peer
+ jni::RegisterNativePeer<UnknownLayer>(
+ env, UnknownLayer::javaClass, "nativePtr",
+ init,
+ "initialize",
+ "finalize");
+ }
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/layers/unknown_layer.hpp b/platform/android/src/style/layers/unknown_layer.hpp
new file mode 100644
index 0000000000..67992ea007
--- /dev/null
+++ b/platform/android/src/style/layers/unknown_layer.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "layer.hpp"
+#include <mbgl/style/layer.hpp>
+#include <jni/jni.hpp>
+
+namespace mbgl {
+namespace android {
+
+class UnknownLayer : public Layer {
+public:
+
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/layers/UnknownLayer"; };
+
+ static jni::Class<UnknownLayer> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+
+ UnknownLayer(mbgl::Map&, mbgl::style::Layer&);
+
+ UnknownLayer(mbgl::Map&, std::unique_ptr<mbgl::style::Layer>);
+
+ ~UnknownLayer() = default;
+
+ jni::jobject* createJavaPeer(jni::JNIEnv&);
+
+}; // class UnknownLayer
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp
index 234dccb315..37ce0644c1 100644
--- a/platform/android/src/style/sources/geojson_source.cpp
+++ b/platform/android/src/style/sources/geojson_source.cpp
@@ -27,19 +27,19 @@ namespace android {
void GeoJSONSource::setGeoJSON(jni::JNIEnv& env, jni::Object<> json) {
using namespace mbgl::style::conversion;
- //Convert the jni object
+ // Convert the jni object
Result<GeoJSON> converted = convert<GeoJSON>(Value(env, json));
if(!converted) {
mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + converted.error().message);
return;
}
- //Update the core source
+ // Update the core source
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(*converted);
}
void GeoJSONSource::setURL(jni::JNIEnv& env, jni::String url) {
- //Update the core source
+ // Update the core source
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setURL(jni::Make<std::string>(env, url));
}
@@ -51,12 +51,12 @@ namespace android {
}
void GeoJSONSource::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
GeoJSONSource::javaClass = *jni::Class<GeoJSONSource>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<GeoJSONSource>(
env, GeoJSONSource::javaClass, "nativePtr",
std::make_unique<GeoJSONSource, JNIEnv&, jni::String, jni::Object<>>,
diff --git a/platform/android/src/style/sources/raster_source.cpp b/platform/android/src/style/sources/raster_source.cpp
index b56b56676d..42ac4cda99 100644
--- a/platform/android/src/style/sources/raster_source.cpp
+++ b/platform/android/src/style/sources/raster_source.cpp
@@ -36,12 +36,12 @@ namespace android {
}
void RasterSource::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
RasterSource::javaClass = *jni::Class<RasterSource>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<RasterSource>(
env, RasterSource::javaClass, "nativePtr",
std::make_unique<RasterSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>,
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp
index aca7bd6a84..b780de5627 100644
--- a/platform/android/src/style/sources/source.cpp
+++ b/platform/android/src/style/sources/source.cpp
@@ -5,11 +5,11 @@
#include <mbgl/util/logging.hpp>
-//Java -> C++ conversion
+// Java -> C++ conversion
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/source.hpp>
-//C++ -> Java conversion
+// C++ -> Java conversion
#include "../conversion/property_value.hpp"
#include <string>
@@ -44,15 +44,15 @@ namespace android {
}
void Source::addToMap(mbgl::Map& _map) {
- //Check to see if we own the source first
+ // Check to see if we own the source first
if (!ownedSource) {
throw std::runtime_error("Cannot add source twice");
}
- //Add source to map
+ // Add source to map
_map.addSource(releaseCoreSource());
- //Save pointer to the map
+ // Save pointer to the map
this->map = &_map;
}
@@ -64,17 +64,17 @@ namespace android {
jni::Class<Source> Source::javaClass;
void Source::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
Source::javaClass = *jni::Class<Source>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<Source>(env, Source::javaClass, "nativePtr",
METHOD(&Source::getId, "nativeGetId")
);
}
-} //android
-} //mbgl \ No newline at end of file
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/source.hpp b/platform/android/src/style/sources/source.hpp
index 0e5d354d93..9a9d504d68 100644
--- a/platform/android/src/style/sources/source.hpp
+++ b/platform/android/src/style/sources/source.hpp
@@ -46,22 +46,18 @@ public:
jni::String getId(jni::JNIEnv&);
protected:
- //Release the owned view and return it
+ // Release the owned view and return it
std::unique_ptr<mbgl::style::Source> releaseCoreSource();
- //Set on newly created sources until added to the map
+ // Set on newly created sources until added to the map
std::unique_ptr<mbgl::style::Source> ownedSource;
- //Raw pointer that is valid until the source is removed from the map
+ // Raw pointer that is valid until the source is removed from the map
mbgl::style::Source& source;
- //Map pointer is valid for newly created sources only after adding to the map
+ // Map pointer is valid for newly created sources only after adding to the map
mbgl::Map* map;
};
-} //android
-} //mbgl
-
-
-
-
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/sources.cpp b/platform/android/src/style/sources/sources.cpp
index 210acd607f..b4e70202b4 100644
--- a/platform/android/src/style/sources/sources.cpp
+++ b/platform/android/src/style/sources/sources.cpp
@@ -8,6 +8,7 @@
#include "source.hpp"
#include "geojson_source.hpp"
#include "raster_source.hpp"
+#include "unknown_source.hpp"
#include "vector_source.hpp"
namespace mbgl {
@@ -22,7 +23,7 @@ Source* initializeSourcePeer(mbgl::Map& map, mbgl::style::Source& coreSource) {
} else if (coreSource.is<mbgl::style::GeoJSONSource>()) {
source = new GeoJSONSource(map, *coreSource.as<mbgl::style::GeoJSONSource>());
} else {
- throw new std::runtime_error("Source type not implemented");
+ source = new UnknownSource(map, coreSource);
}
return source;
@@ -37,10 +38,11 @@ jni::jobject* createJavaSourcePeer(jni::JNIEnv& env, mbgl::Map& map, mbgl::style
void registerNativeSources(jni::JNIEnv& env) {
Source::registerNative(env);
- VectorSource::registerNative(env);
- RasterSource::registerNative(env);
GeoJSONSource::registerNative(env);
+ RasterSource::registerNative(env);
+ UnknownSource::registerNative(env);
+ VectorSource::registerNative(env);
}
}
-} \ No newline at end of file
+}
diff --git a/platform/android/src/style/sources/sources.hpp b/platform/android/src/style/sources/sources.hpp
index 3038873733..09a8b35067 100644
--- a/platform/android/src/style/sources/sources.hpp
+++ b/platform/android/src/style/sources/sources.hpp
@@ -9,12 +9,12 @@
namespace mbgl {
namespace android {
-
+
mbgl::android::Source* initializeSourcePeer(mbgl::Map&, mbgl::style::Source&);
-
+
jni::jobject* createJavaSourcePeer(jni::JNIEnv&, mbgl::Map&, mbgl::style::Source&);
-
+
void registerNativeSources(jni::JNIEnv&);
}
-} \ No newline at end of file
+}
diff --git a/platform/android/src/style/sources/unknown_source.cpp b/platform/android/src/style/sources/unknown_source.cpp
new file mode 100644
index 0000000000..c1b1cc8c02
--- /dev/null
+++ b/platform/android/src/style/sources/unknown_source.cpp
@@ -0,0 +1,42 @@
+#include "unknown_source.hpp"
+
+namespace {
+
+ // Dummy initializer (We don't support initializing this from the JVM)
+ std::unique_ptr<mbgl::android::UnknownSource> init(jni::JNIEnv&) {
+ throw new std::runtime_error("UnknownSource should not be initialized from the JVM");
+ }
+
+} // namespace
+
+namespace mbgl {
+namespace android {
+
+ UnknownSource::UnknownSource(mbgl::Map& map, mbgl::style::Source& coreSource)
+ : Source(map, coreSource) {
+ }
+
+ jni::Class<UnknownSource> UnknownSource::javaClass;
+
+ jni::jobject* UnknownSource::createJavaPeer(jni::JNIEnv& env) {
+ static auto constructor = UnknownSource::javaClass.template GetConstructor<jni::jlong>(env);
+ return UnknownSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
+ }
+
+ void UnknownSource::registerNative(jni::JNIEnv& env) {
+ // Lookup the class
+ UnknownSource::javaClass = *jni::Class<UnknownSource>::Find(env).NewGlobalRef(env).release();
+
+ #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
+
+ // Register the peer
+ jni::RegisterNativePeer<UnknownSource>(
+ env, UnknownSource::javaClass, "nativePtr",
+ init,
+ "initialize",
+ "finalize"
+ );
+ }
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/unknown_source.hpp b/platform/android/src/style/sources/unknown_source.hpp
new file mode 100644
index 0000000000..3c37239792
--- /dev/null
+++ b/platform/android/src/style/sources/unknown_source.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "source.hpp"
+#include <mbgl/style/source.hpp>
+#include <jni/jni.hpp>
+
+namespace mbgl {
+namespace android {
+
+class UnknownSource : public Source {
+public:
+
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/UnknownSource"; };
+
+ static jni::Class<UnknownSource> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+
+ UnknownSource(mbgl::Map&, mbgl::style::Source&);
+
+ ~UnknownSource() = default;
+
+ jni::jobject* createJavaPeer(jni::JNIEnv&);
+
+}; // class UnknownSource
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp
index 0d065a3348..e60d8d4641 100644
--- a/platform/android/src/style/sources/vector_source.cpp
+++ b/platform/android/src/style/sources/vector_source.cpp
@@ -35,12 +35,12 @@ namespace android {
}
void VectorSource::registerNative(jni::JNIEnv& env) {
- //Lookup the class
+ // Lookup the class
VectorSource::javaClass = *jni::Class<VectorSource>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
- //Register the peer
+ // Register the peer
jni::RegisterNativePeer<VectorSource>(
env, VectorSource::javaClass, "nativePtr",
std::make_unique<VectorSource, JNIEnv&, jni::String, jni::Object<>>,
diff --git a/platform/android/src/style/value.cpp b/platform/android/src/style/value.cpp
index c8aad1682b..0b5d81feb1 100644
--- a/platform/android/src/style/value.cpp
+++ b/platform/android/src/style/value.cpp
@@ -20,7 +20,7 @@ namespace android {
JNIEnv& env;
};
- //Instance
+ // Instance
Value::Value(jni::JNIEnv& env, jni::jobject* _value) : jenv(env), value(_value, ObjectDeleter(env)) {}