Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Merge style::Layer::set{Layout,Paint}Property #15997

Merged
merged 3 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ class Layer {
void setMaxZoom(float);

// Dynamic properties
virtual optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0;
virtual optional<conversion::Error> setPaintProperty(const std::string& name,
const conversion::Convertible& value) = 0;
virtual optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) = 0;
optional<conversion::Error> setVisibility(const conversion::Convertible& value);

virtual StyleProperty getProperty(const std::string&) const = 0;
Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class BackgroundLayer : public Layer {
~BackgroundLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class CircleLayer : public Layer {
~CircleLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/custom_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class CustomLayer : public Layer {
~CustomLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string&) const final;
// Private implementation

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class FillExtrusionLayer : public Layer {
~FillExtrusionLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/fill_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class FillLayer : public Layer {
~FillLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/heatmap_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class HeatmapLayer : public Layer {
~HeatmapLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/hillshade_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class HillshadeLayer : public Layer {
~HillshadeLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/layer.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public:
~<%- camelize(type) %>Layer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class LineLayer : public Layer {
~LineLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/raster_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class RasterLayer : public Layer {
~RasterLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class SymbolLayer : public Layer {
~SymbolLayer() final;

// Dynamic properties
optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final;
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;

StyleProperty getProperty(const std::string& name) const final;

Expand Down
28 changes: 11 additions & 17 deletions platform/android/src/style/layers/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mbgl::style::conversion::Error> error = layer.setLayoutProperty(jni::Make<std::string>(env, jname), Value(env, jvalue));
if (error) {
mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make<std::string>(env, jname) + " " + error->message);
return;
}
}

void Layer::setPaintProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) {
// Convert and set property
optional<mbgl::style::conversion::Error> error = layer.setPaintProperty(jni::Make<std::string>(env, jname), Value(env, jvalue));
optional<mbgl::style::conversion::Error> error =
layer.setProperty(jni::Make<std::string>(env, jname), Value(env, jvalue));
if (error) {
mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make<std::string>(env, jname) + " " + error->message);
return;
Expand Down Expand Up @@ -176,10 +168,14 @@ namespace android {
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)

// Register the peer
jni::RegisterNativePeer<Layer>(env, javaClass, "nativePtr",
jni::RegisterNativePeer<Layer>(
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"),
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions platform/android/src/style/layers/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class Layer {

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

Expand Down
40 changes: 4 additions & 36 deletions platform/node/src/node_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -850,7 +850,7 @@ void NodeMap::SetLayerZoomRange(const Nan::FunctionCallbackInfo<v8::Value>& info
layer->setMaxZoom(info[2]->NumberValue());
}

void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>& info) {
void NodeMap::SetLayerProperty(const Nan::FunctionCallbackInfo<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;

Expand All @@ -874,39 +874,7 @@ void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>& info
return Nan::ThrowTypeError("Second argument must be a string");
}

mbgl::optional<Error> 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<v8::Value>& info) {
using namespace mbgl::style;
using namespace mbgl::style::conversion;

auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(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> error = layer->setPaintProperty(*Nan::Utf8String(info[1]), Convertible(info[2]));
mbgl::optional<Error> error = layer->setProperty(*Nan::Utf8String(info[1]), Convertible(info[2]));
if (error) {
return Nan::ThrowTypeError(error->message.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions platform/node/src/node_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class NodeMap : public Nan::ObjectWrap {
static void AddImage(const Nan::FunctionCallbackInfo<v8::Value>&);
static void RemoveImage(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetLayerZoomRange(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetLayoutProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetPaintProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetLayerProperty(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetFilter(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetCenter(const Nan::FunctionCallbackInfo<v8::Value>&);
static void SetZoom(const Nan::FunctionCallbackInfo<v8::Value>&);
Expand Down
4 changes: 2 additions & 2 deletions platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*!
Expand Down Expand Up @@ -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);
}

/*!
Expand Down
24 changes: 4 additions & 20 deletions render-test/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,9 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata, R
assert(operationArray.Size() >= 2u);
assert(operationArray[1].IsString());
map.getStyle().removeSource(operationArray[1].GetString());
} else if (operationArray[0].GetString() == setPaintPropertyOp) {
// setPaintProperty
} else if (operationArray[0].GetString() == setLayoutPropertyOp ||
operationArray[0].GetString() == setPaintPropertyOp) {
// set{Paint|Layout}Property
assert(operationArray.Size() >= 4u);
assert(operationArray[1].IsString());
assert(operationArray[2].IsString());
Expand All @@ -808,24 +809,7 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata, R
return false;
} else {
const mbgl::JSValue* propertyValue = &operationArray[3];
layer->setPaintProperty(propertyName, propertyValue);
}
} else if (operationArray[0].GetString() == setLayoutPropertyOp) {
// setLayoutProperty
assert(operationArray.Size() >= 4u);
assert(operationArray[1].IsString());
assert(operationArray[2].IsString());

const std::string layerName { operationArray[1].GetString(), operationArray[1].GetStringLength() };
const std::string propertyName { operationArray[2].GetString(), operationArray[2].GetStringLength() };

auto layer = map.getStyle().getLayer(layerName);
if (!layer) {
metadata.errorMessage = std::string("Layer not found: ") + layerName;
return false;
} else {
const mbgl::JSValue* propertyValue = &operationArray[3];
layer->setLayoutProperty(propertyName, propertyValue);
layer->setProperty(propertyName, propertyValue);
}
} else if (operationArray[0].GetString() == fileSizeProbeOp) {
// probeFileSize
Expand Down
9 changes: 3 additions & 6 deletions src/mbgl/style/conversion/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ optional<Error> setPaintProperties(Layer& layer, const Convertible& value) {
if (!isObject(*paintValue)) {
return { { "paint must be an object" } };
}
return eachMember(*paintValue, [&] (const std::string& k, const Convertible& v) {
return layer.setPaintProperty(k, v);
});
return eachMember(*paintValue, [&](const std::string& k, const Convertible& v) { return layer.setProperty(k, v); });
}

optional<std::unique_ptr<Layer>> Converter<std::unique_ptr<Layer>>::operator()(const Convertible& value, Error& error) const {
Expand Down Expand Up @@ -83,9 +81,8 @@ optional<std::unique_ptr<Layer>> Converter<std::unique_ptr<Layer>>::operator()(c
error.message = "layout must be an object";
return nullopt;
}
optional<Error> error_ = eachMember(*layoutValue, [&] (const std::string& k, const Convertible& v) {
return layer->setLayoutProperty(k, v);
});
optional<Error> error_ = eachMember(
*layoutValue, [&](const std::string& k, const Convertible& v) { return layer->setProperty(k, v); });
if (error_) {
error = *error_;
return nullopt;
Expand Down
Loading