From 5d46cd662fe5c441618204241f61c986af200f48 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 2 Dec 2019 18:04:06 +0200 Subject: [android][node][qt] Update platform code for style::Layer::setProperty() --- platform/android/src/style/layers/layer.cpp | 28 ++++++++------------ platform/android/src/style/layers/layer.hpp | 4 +-- platform/node/src/node_map.cpp | 40 +++-------------------------- platform/node/src/node_map.hpp | 3 +-- platform/qt/src/qmapboxgl.cpp | 4 +-- 5 files changed, 19 insertions(+), 60 deletions(-) diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp index 2f335b6ff3..b90d670a4b 100644 --- a/platform/android/src/style/layers/layer.cpp +++ b/platform/android/src/style/layers/layer.cpp @@ -91,18 +91,10 @@ namespace android { return layer; } - void Layer::setLayoutProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) { + void Layer::setProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) { // Convert and set property - optional error = layer.setLayoutProperty(jni::Make(env, jname), Value(env, jvalue)); - if (error) { - mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make(env, jname) + " " + error->message); - return; - } - } - - void Layer::setPaintProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) { - // Convert and set property - optional error = layer.setPaintProperty(jni::Make(env, jname), Value(env, jvalue)); + optional error = + layer.setProperty(jni::Make(env, jname), Value(env, jvalue)); if (error) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make(env, jname) + " " + error->message); return; @@ -176,10 +168,14 @@ namespace android { #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer - jni::RegisterNativePeer(env, javaClass, "nativePtr", + jni::RegisterNativePeer( + env, + javaClass, + "nativePtr", METHOD(&Layer::getId, "nativeGetId"), - METHOD(&Layer::setLayoutProperty, "nativeSetLayoutProperty"), - METHOD(&Layer::setPaintProperty, "nativeSetPaintProperty"), + METHOD(&Layer::setProperty, + "nativeSetLayoutProperty"), // TODO : Export only nativeSetProperty() when #15970 lands. + METHOD(&Layer::setProperty, "nativeSetPaintProperty"), METHOD(&Layer::setFilter, "nativeSetFilter"), METHOD(&Layer::getFilter, "nativeGetFilter"), METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"), @@ -189,9 +185,7 @@ namespace android { METHOD(&Layer::getMaxZoom, "nativeGetMaxZoom"), METHOD(&Layer::setMinZoom, "nativeSetMinZoom"), METHOD(&Layer::setMaxZoom, "nativeSetMaxZoom"), - METHOD(&Layer::getVisibility, "nativeGetVisibility") - ); - + METHOD(&Layer::getVisibility, "nativeGetVisibility")); } } // namespace android diff --git a/platform/android/src/style/layers/layer.hpp b/platform/android/src/style/layers/layer.hpp index 0fb679152b..bde351f708 100644 --- a/platform/android/src/style/layers/layer.hpp +++ b/platform/android/src/style/layers/layer.hpp @@ -35,9 +35,7 @@ public: style::Layer& get(); - void setLayoutProperty(jni::JNIEnv&, const jni::String&, const jni::Object<>& value); - - void setPaintProperty(jni::JNIEnv&, const jni::String&, const jni::Object<>& value); + void setProperty(jni::JNIEnv&, const jni::String&, const jni::Object<>& value); // Zoom diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 5ce201da2e..e55460fa29 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -106,8 +106,8 @@ ParseError)JS").ToLocalChecked()).ToLocalChecked(); Nan::SetPrototypeMethod(tpl, "addImage", AddImage); Nan::SetPrototypeMethod(tpl, "removeImage", RemoveImage); Nan::SetPrototypeMethod(tpl, "setLayerZoomRange", SetLayerZoomRange); - Nan::SetPrototypeMethod(tpl, "setLayoutProperty", SetLayoutProperty); - Nan::SetPrototypeMethod(tpl, "setPaintProperty", SetPaintProperty); + Nan::SetPrototypeMethod(tpl, "setLayoutProperty", SetLayerProperty); + Nan::SetPrototypeMethod(tpl, "setPaintProperty", SetLayerProperty); Nan::SetPrototypeMethod(tpl, "setFilter", SetFilter); Nan::SetPrototypeMethod(tpl, "setCenter", SetCenter); Nan::SetPrototypeMethod(tpl, "setZoom", SetZoom); @@ -850,7 +850,7 @@ void NodeMap::SetLayerZoomRange(const Nan::FunctionCallbackInfo& info layer->setMaxZoom(info[2]->NumberValue()); } -void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo& info) { +void NodeMap::SetLayerProperty(const Nan::FunctionCallbackInfo& info) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -874,39 +874,7 @@ void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo& info return Nan::ThrowTypeError("Second argument must be a string"); } - mbgl::optional error = layer->setLayoutProperty(*Nan::Utf8String(info[1]), Convertible(info[2])); - if (error) { - return Nan::ThrowTypeError(error->message.c_str()); - } - - info.GetReturnValue().SetUndefined(); -} - -void NodeMap::SetPaintProperty(const Nan::FunctionCallbackInfo& info) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - auto nodeMap = Nan::ObjectWrap::Unwrap(info.Holder()); - if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); - - if (info.Length() < 3) { - return Nan::ThrowTypeError("Three arguments required"); - } - - if (!info[0]->IsString()) { - return Nan::ThrowTypeError("First argument must be a string"); - } - - mbgl::style::Layer* layer = nodeMap->map->getStyle().getLayer(*Nan::Utf8String(info[0])); - if (!layer) { - return Nan::ThrowTypeError("layer not found"); - } - - if (!info[1]->IsString()) { - return Nan::ThrowTypeError("Second argument must be a string"); - } - - mbgl::optional error = layer->setPaintProperty(*Nan::Utf8String(info[1]), Convertible(info[2])); + mbgl::optional error = layer->setProperty(*Nan::Utf8String(info[1]), Convertible(info[2])); if (error) { return Nan::ThrowTypeError(error->message.c_str()); } diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 381e10381b..aa440d2323 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -50,8 +50,7 @@ public: static void AddImage(const Nan::FunctionCallbackInfo&); static void RemoveImage(const Nan::FunctionCallbackInfo&); static void SetLayerZoomRange(const Nan::FunctionCallbackInfo&); - static void SetLayoutProperty(const Nan::FunctionCallbackInfo&); - static void SetPaintProperty(const Nan::FunctionCallbackInfo&); + static void SetLayerProperty(const Nan::FunctionCallbackInfo&); static void SetFilter(const Nan::FunctionCallbackInfo&); static void SetCenter(const Nan::FunctionCallbackInfo&); static void SetZoom(const Nan::FunctionCallbackInfo&); diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index b5681d218d..1fdfb6ef3a 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1011,7 +1011,7 @@ void QMapboxGL::removeAnnotation(QMapbox::AnnotationID id) */ bool QMapboxGL::setLayoutProperty(const QString& layer, const QString& propertyName, const QVariant& value) { - return d_ptr->setProperty(&mbgl::style::Layer::setLayoutProperty, layer, propertyName, value); + return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); } /*! @@ -1071,7 +1071,7 @@ bool QMapboxGL::setLayoutProperty(const QString& layer, const QString& propertyN bool QMapboxGL::setPaintProperty(const QString& layer, const QString& propertyName, const QVariant& value) { - return d_ptr->setProperty(&mbgl::style::Layer::setPaintProperty, layer, propertyName, value); + return d_ptr->setProperty(&mbgl::style::Layer::setProperty, layer, propertyName, value); } /*! -- cgit v1.2.1