summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/conversion/stringify.hpp256
-rw-r--r--src/mbgl/style/group_by_layout.cpp51
-rw-r--r--src/mbgl/style/group_by_layout.hpp14
-rw-r--r--src/mbgl/style/layer_impl.cpp6
-rw-r--r--src/mbgl/style/layer_impl.hpp13
-rw-r--r--src/mbgl/style/layers/background_layer.cpp5
-rw-r--r--src/mbgl/style/layers/background_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/circle_layer.cpp5
-rw-r--r--src/mbgl/style/layers/circle_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/circle_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer.cpp5
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/fill_layer.cpp5
-rw-r--r--src/mbgl/style/layers/fill_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/fill_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs11
-rw-r--r--src/mbgl/style/layers/layer_properties.hpp.ejs1
-rw-r--r--src/mbgl/style/layers/line_layer.cpp6
-rw-r--r--src/mbgl/style/layers/line_layer_impl.cpp3
-rw-r--r--src/mbgl/style/layers/line_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/line_layer_properties.hpp4
-rw-r--r--src/mbgl/style/layers/raster_layer.cpp5
-rw-r--r--src/mbgl/style/layers/raster_layer_impl.hpp1
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp6
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.cpp6
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.hpp4
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp34
29 files changed, 427 insertions, 29 deletions
diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp
new file mode 100644
index 0000000000..d06b2f2814
--- /dev/null
+++ b/src/mbgl/style/conversion/stringify.hpp
@@ -0,0 +1,256 @@
+#pragma once
+
+#include <mbgl/style/filter.hpp>
+#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/layout_property.hpp>
+#include <mbgl/util/enum.hpp>
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/feature.hpp>
+#include <mbgl/util/ignore.hpp>
+#include <mbgl/util/rapidjson.hpp>
+
+#include <array>
+#include <vector>
+#include <unordered_map>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <class Writer>
+void stringify(Writer& writer, NullValue) {
+ writer.Null();
+}
+
+template <class Writer>
+void stringify(Writer& writer, bool v) {
+ writer.Bool(v);
+}
+
+template <class Writer>
+void stringify(Writer& writer, uint64_t v) {
+ writer.Uint64(v);
+}
+
+template <class Writer>
+void stringify(Writer& writer, int64_t v) {
+ writer.Int64(v);
+}
+
+template <class Writer>
+void stringify(Writer& writer, double v) {
+ writer.Double(v);
+}
+
+template <class Writer>
+void stringify(Writer& writer, const std::string& v) {
+ writer.String(v);
+}
+
+template <class Writer, class T, class Enable = std::enable_if_t<std::is_enum<T>::value>>
+void stringify(Writer& writer, const T& v) {
+ writer.String(Enum<T>::toString(v));
+}
+
+template <class Writer>
+void stringify(Writer& writer, const Color& v) {
+ writer.String(v.stringify());
+}
+
+template <class Writer>
+void stringify(Writer& writer, const std::array<float, 2>& v) {
+ writer.StartArray();
+ writer.Double(v[0]);
+ writer.Double(v[1]);
+ writer.EndArray();
+}
+
+template <class Writer>
+void stringify(Writer& writer, const std::array<float, 4>& v) {
+ writer.StartArray();
+ writer.Double(v[0]);
+ writer.Double(v[1]);
+ writer.Double(v[2]);
+ writer.Double(v[3]);
+ writer.EndArray();
+}
+
+template <class Writer>
+void stringify(Writer&, const Value&);
+
+template <class Writer, class T>
+void stringify(Writer& writer, const std::vector<T>& v) {
+ writer.StartArray();
+ for (const auto& e : v) {
+ stringify(writer, e);
+ }
+ writer.EndArray();
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const std::unordered_map<std::string, T>& m) {
+ writer.StartObject();
+ for (const auto& p : m) {
+ writer.Key(p.first.data(), static_cast<unsigned>(p.first.size()));
+ stringify(writer, p.second);
+ }
+ writer.EndObject();
+}
+
+template <class Writer>
+void stringify(Writer& writer, const Value& v) {
+ Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); });
+}
+
+template <class Writer>
+class StringifyFilter {
+public:
+ Writer& writer;
+
+ void operator()(const NullFilter&) {
+ writer.Null();
+ }
+
+ void operator()(const EqualsFilter& f) {
+ stringifyBinaryFilter(f, "==");
+ }
+
+ void operator()(const NotEqualsFilter& f) {
+ stringifyBinaryFilter(f, "!=");
+ }
+
+ void operator()(const LessThanFilter& f) {
+ stringifyBinaryFilter(f, "<");
+ }
+
+ void operator()(const LessThanEqualsFilter& f) {
+ stringifyBinaryFilter(f, "<=");
+ }
+
+ void operator()(const GreaterThanFilter& f) {
+ stringifyBinaryFilter(f, ">");
+ }
+
+ void operator()(const GreaterThanEqualsFilter& f) {
+ stringifyBinaryFilter(f, ">=");
+ }
+
+ void operator()(const InFilter& f) {
+ stringifySetFilter(f, "in");
+ }
+
+ void operator()(const NotInFilter& f) {
+ stringifySetFilter(f, "!in");
+ }
+
+ void operator()(const AllFilter& f) {
+ stringifyCompoundFilter(f, "all");
+ }
+
+ void operator()(const AnyFilter& f) {
+ stringifyCompoundFilter(f, "any");
+ }
+
+ void operator()(const NoneFilter& f) {
+ stringifyCompoundFilter(f, "none");
+ }
+
+ void operator()(const HasFilter& f) {
+ stringifyUnaryFilter(f, "has");
+ }
+
+ void operator()(const NotHasFilter& f) {
+ stringifyUnaryFilter(f, "!has");
+ }
+
+private:
+ template <class F>
+ void stringifyBinaryFilter(const F& f, const char * op) {
+ writer.StartArray();
+ writer.String(op);
+ writer.String(f.key);
+ stringify(writer, f.value);
+ writer.EndArray();
+ }
+
+ template <class F>
+ void stringifySetFilter(const F& f, const char * op) {
+ writer.StartArray();
+ writer.String(op);
+ writer.String(f.key);
+ for (const auto& value : f.values) {
+ stringify(writer, value);
+ }
+ writer.EndArray();
+ }
+
+ template <class F>
+ void stringifyCompoundFilter(const F& f, const char * op) {
+ writer.StartArray();
+ writer.String(op);
+ for (const auto& filter : f.filters) {
+ Filter::visit(filter, *this);
+ }
+ writer.EndArray();
+ }
+
+ template <class F>
+ void stringifyUnaryFilter(const F& f, const char * op) {
+ writer.StartArray();
+ writer.String(op);
+ writer.String(f.key);
+ writer.EndArray();
+ }
+};
+
+template <class Writer>
+void stringify(Writer& writer, const Filter& f) {
+ Filter::visit(f, StringifyFilter<Writer> { writer });
+}
+
+template <class Writer>
+void stringify(Writer& writer, const Undefined&) {
+ assert(false); // Should be omitted entirely instead.
+ writer.Null();
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const Function<T>& f) {
+ writer.StartObject();
+ writer.Key("base");
+ writer.Double(f.getBase());
+ writer.Key("stops");
+ writer.StartArray();
+ for (const auto& stop : f.getStops()) {
+ writer.StartArray();
+ writer.Double(stop.first);
+ stringify(writer, stop.second);
+ writer.EndArray();
+ }
+ writer.EndArray();
+ writer.EndObject();
+}
+
+template <class Writer, class T>
+void stringify(Writer& writer, const PropertyValue<T>& v) {
+ v.evaluate([&] (const auto& v_) { stringify(writer, v_); });
+}
+
+template <class Property, class Writer, class T>
+void stringify(Writer& writer, const PropertyValue<T>& value) {
+ if (value) {
+ writer.Key(Property::key);
+ stringify(writer, value);
+ }
+}
+
+template <class Writer, class... Ps>
+void stringify(Writer& writer, const LayoutProperties<Ps...>& ps) {
+ writer.StartObject();
+ util::ignore({ (stringify<Ps>(writer, ps.unevaluated.template get<Ps>()), 0)... });
+ writer.EndObject();
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/group_by_layout.cpp b/src/mbgl/style/group_by_layout.cpp
new file mode 100644
index 0000000000..52d33827ef
--- /dev/null
+++ b/src/mbgl/style/group_by_layout.cpp
@@ -0,0 +1,51 @@
+#include <mbgl/style/group_by_layout.hpp>
+#include <mbgl/style/layer.hpp>
+#include <mbgl/style/layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
+#include <mbgl/util/rapidjson.hpp>
+
+#include <rapidjson/writer.h>
+#include <rapidjson/stringbuffer.h>
+
+#include <unordered_map>
+
+namespace mbgl {
+namespace style {
+
+std::string layoutKey(const Layer& layer) {
+ using namespace conversion;
+
+ rapidjson::StringBuffer s;
+ rapidjson::Writer<rapidjson::StringBuffer> writer(s);
+
+ writer.StartArray();
+ writer.Uint(static_cast<uint32_t>(layer.type));
+ writer.String(layer.baseImpl->source);
+ writer.String(layer.baseImpl->sourceLayer);
+ writer.Double(layer.baseImpl->minZoom);
+ writer.Double(layer.baseImpl->maxZoom);
+ writer.Uint(static_cast<uint32_t>(layer.baseImpl->visibility));
+ stringify(writer, layer.baseImpl->filter);
+ layer.baseImpl->stringifyLayout(writer);
+ writer.EndArray();
+
+ return s.GetString();
+}
+
+std::vector<std::vector<std::unique_ptr<Layer>>> groupByLayout(std::vector<std::unique_ptr<Layer>> layers) {
+ std::unordered_map<std::string, std::vector<std::unique_ptr<Layer>>> map;
+ for (auto& layer : layers) {
+ auto& vector = map[layoutKey(*layer)];
+ vector.push_back(std::move(layer));
+ }
+
+ std::vector<std::vector<std::unique_ptr<Layer>>> result;
+ for (auto& pair : map) {
+ result.push_back(std::move(pair.second));
+ }
+
+ return result;
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/group_by_layout.hpp b/src/mbgl/style/group_by_layout.hpp
new file mode 100644
index 0000000000..dd7b5d118a
--- /dev/null
+++ b/src/mbgl/style/group_by_layout.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <vector>
+#include <memory>
+
+namespace mbgl {
+namespace style {
+
+class Layer;
+
+std::vector<std::vector<std::unique_ptr<Layer>>> groupByLayout(std::vector<std::unique_ptr<Layer>>);
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp
index 7a0195c55c..5840318724 100644
--- a/src/mbgl/style/layer_impl.cpp
+++ b/src/mbgl/style/layer_impl.cpp
@@ -4,19 +4,13 @@ namespace mbgl {
namespace style {
std::unique_ptr<Layer> Layer::Impl::copy(const std::string& id_,
- const std::string& ref_,
const std::string& source_) const {
std::unique_ptr<Layer> result = clone();
result->baseImpl->id = id_;
- result->baseImpl->ref = ref_;
result->baseImpl->source = source_;
return result;
}
-const std::string& Layer::Impl::bucketName() const {
- return ref.empty() ? id : ref;
-}
-
bool Layer::Impl::hasRenderPass(RenderPass pass) const {
return bool(passes & pass);
}
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp
index 7e2c55c2e6..0fea70c10b 100644
--- a/src/mbgl/style/layer_impl.hpp
+++ b/src/mbgl/style/layer_impl.hpp
@@ -8,6 +8,9 @@
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
+#include <rapidjson/writer.h>
+#include <rapidjson/stringbuffer.h>
+
#include <memory>
#include <string>
#include <limits>
@@ -37,20 +40,19 @@ class Layer::Impl {
public:
virtual ~Impl() = default;
- // Create a new layer with the specified `id`, `ref`, and `sourceID`. All other properties
+ // Create a new layer with the specified `id` and `sourceID`. All other properties
// are copied from this layer.
std::unique_ptr<Layer> copy(const std::string& id,
- const std::string& ref,
const std::string& sourceID) const;
// Create an identical copy of this layer.
virtual std::unique_ptr<Layer> clone() const = 0;
- // Create a layer, copying all properties except id, ref, and paint properties from this layer.
+ // Create a layer, copying all properties except id and paint properties from this layer.
virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0;
- // If the layer has a ref, the ref. Otherwise, the id.
- const std::string& bucketName() const;
+ // Utility function for automatic layer grouping.
+ virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0;
// Partially evaluate paint properties based on a set of classes.
virtual void cascade(const CascadeParameters&) = 0;
@@ -78,7 +80,6 @@ public:
public:
std::string id;
- std::string ref;
std::string source;
std::string sourceLayer;
Filter filter;
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp
index a54115d1a7..a75038bfa0 100644
--- a/src/mbgl/style/layers/background_layer.cpp
+++ b/src/mbgl/style/layers/background_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -26,11 +27,13 @@ std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const {
std::unique_ptr<Layer> BackgroundLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<BackgroundLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = BackgroundPaintProperties();
return std::move(result);
}
+void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
// Layout properties
diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp
index d3d50e21cd..4629217e6d 100644
--- a/src/mbgl/style/layers/background_layer_impl.hpp
+++ b/src/mbgl/style/layers/background_layer_impl.hpp
@@ -11,6 +11,7 @@ class BackgroundLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp
index e3a506e895..389ab93403 100644
--- a/src/mbgl/style/layers/circle_layer.cpp
+++ b/src/mbgl/style/layers/circle_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,13 @@ std::unique_ptr<Layer> CircleLayer::Impl::clone() const {
std::unique_ptr<Layer> CircleLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<CircleLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = CirclePaintProperties();
return std::move(result);
}
+void CircleLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
// Source
const std::string& CircleLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp
index 614f637b3b..136522e41c 100644
--- a/src/mbgl/style/layers/circle_layer_impl.cpp
+++ b/src/mbgl/style/layers/circle_layer_impl.cpp
@@ -24,11 +24,10 @@ bool CircleLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters)
std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(BucketParameters& parameters, const GeometryTileLayer& layer) const {
auto bucket = std::make_unique<CircleBucket>(parameters.mode);
- auto& name = bucketName();
parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
auto geometries = feature.getGeometries();
bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, name);
+ parameters.featureIndex.insert(geometries, index, layerName, id);
});
return std::move(bucket);
diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp
index f0db58be24..744a56898c 100644
--- a/src/mbgl/style/layers/circle_layer_impl.hpp
+++ b/src/mbgl/style/layers/circle_layer_impl.hpp
@@ -11,6 +11,7 @@ class CircleLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp
index baf55205c4..cecd60a296 100644
--- a/src/mbgl/style/layers/custom_layer_impl.cpp
+++ b/src/mbgl/style/layers/custom_layer_impl.cpp
@@ -34,6 +34,9 @@ std::unique_ptr<Layer> CustomLayer::Impl::cloneRef(const std::string&) const {
return std::make_unique<CustomLayer>(*this);
}
+void CustomLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
void CustomLayer::Impl::initialize() {
assert(initializeFn);
initializeFn(context);
diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp
index 3e365faacf..71fb46d0d9 100644
--- a/src/mbgl/style/layers/custom_layer_impl.hpp
+++ b/src/mbgl/style/layers/custom_layer_impl.hpp
@@ -27,6 +27,7 @@ public:
private:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) final {}
bool evaluate(const PropertyEvaluationParameters&) final;
diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp
index 64efb1dd6a..34f0267d16 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer.cpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,13 @@ std::unique_ptr<Layer> FillExtrusionLayer::Impl::clone() const {
std::unique_ptr<Layer> FillExtrusionLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<FillExtrusionLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = FillExtrusionPaintProperties();
return std::move(result);
}
+void FillExtrusionLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
// Source
const std::string& FillExtrusionLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
index 52b9d327f2..3dd8bb270a 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp
@@ -11,6 +11,7 @@ class FillExtrusionLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp
index 3bea9b56b0..b8fa8cad8b 100644
--- a/src/mbgl/style/layers/fill_layer.cpp
+++ b/src/mbgl/style/layers/fill_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,13 @@ std::unique_ptr<Layer> FillLayer::Impl::clone() const {
std::unique_ptr<Layer> FillLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<FillLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = FillPaintProperties();
return std::move(result);
}
+void FillLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
// Source
const std::string& FillLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp
index 59d6a22432..51636820f0 100644
--- a/src/mbgl/style/layers/fill_layer_impl.cpp
+++ b/src/mbgl/style/layers/fill_layer_impl.cpp
@@ -33,11 +33,10 @@ bool FillLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) {
std::unique_ptr<Bucket> FillLayer::Impl::createBucket(BucketParameters& parameters, const GeometryTileLayer& layer) const {
auto bucket = std::make_unique<FillBucket>();
- auto& name = bucketName();
parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
auto geometries = feature.getGeometries();
bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, name);
+ parameters.featureIndex.insert(geometries, index, layerName, id);
});
return std::move(bucket);
diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp
index bebea4ffab..28e2fa7edc 100644
--- a/src/mbgl/style/layers/fill_layer_impl.hpp
+++ b/src/mbgl/style/layers/fill_layer_impl.hpp
@@ -11,6 +11,7 @@ class FillLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index 5fe78519ec..e730e3a29b 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -7,6 +7,7 @@
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -40,11 +41,19 @@ std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const {
std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<<%- camelize(type) %>Layer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = <%- camelize(type) %>PaintProperties();
return std::move(result);
}
+<% if (layoutProperties.length) { -%>
+void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
+ conversion::stringify(writer, layout);
+}
+<% } else { -%>
+void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+<% } -%>
+
<% if (type !== 'background') { -%>
// Source
diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs
index f490a636f9..d18ad44efd 100644
--- a/src/mbgl/style/layers/layer_properties.hpp.ejs
+++ b/src/mbgl/style/layers/layer_properties.hpp.ejs
@@ -16,6 +16,7 @@ namespace style {
<% for (const property of layoutProperties) { -%>
struct <%- camelize(property.name) %> : LayoutProperty<<%- propertyType(property) %>> {
+ static constexpr const char * key = "<%- property.name %>";
static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; }
};
diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp
index 8c38ef5694..7f6c148cd1 100644
--- a/src/mbgl/style/layers/line_layer.cpp
+++ b/src/mbgl/style/layers/line_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,14 @@ std::unique_ptr<Layer> LineLayer::Impl::clone() const {
std::unique_ptr<Layer> LineLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<LineLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = LinePaintProperties();
return std::move(result);
}
+void LineLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
+ conversion::stringify(writer, layout);
+}
+
// Source
const std::string& LineLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp
index 24b2b097b1..477579a43c 100644
--- a/src/mbgl/style/layers/line_layer_impl.cpp
+++ b/src/mbgl/style/layers/line_layer_impl.cpp
@@ -31,11 +31,10 @@ std::unique_ptr<Bucket> LineLayer::Impl::createBucket(BucketParameters& paramete
bucket->layout = layout.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ));
- auto& name = bucketName();
parameters.eachFilteredFeature(filter, layer, [&] (const auto& feature, std::size_t index, const std::string& layerName) {
auto geometries = feature.getGeometries();
bucket->addGeometry(geometries);
- parameters.featureIndex.insert(geometries, index, layerName, name);
+ parameters.featureIndex.insert(geometries, index, layerName, id);
});
return std::move(bucket);
diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp
index 8c8c7d053b..1955c019af 100644
--- a/src/mbgl/style/layers/line_layer_impl.hpp
+++ b/src/mbgl/style/layers/line_layer_impl.hpp
@@ -11,6 +11,7 @@ class LineLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp
index 07458cd634..2ea7f6b125 100644
--- a/src/mbgl/style/layers/line_layer_properties.hpp
+++ b/src/mbgl/style/layers/line_layer_properties.hpp
@@ -10,18 +10,22 @@ namespace mbgl {
namespace style {
struct LineCap : LayoutProperty<LineCapType> {
+ static constexpr const char * key = "line-cap";
static LineCapType defaultValue() { return LineCapType::Butt; }
};
struct LineJoin : LayoutProperty<LineJoinType> {
+ static constexpr const char * key = "line-join";
static LineJoinType defaultValue() { return LineJoinType::Miter; }
};
struct LineMiterLimit : LayoutProperty<float> {
+ static constexpr const char * key = "line-miter-limit";
static float defaultValue() { return 2; }
};
struct LineRoundLimit : LayoutProperty<float> {
+ static constexpr const char * key = "line-round-limit";
static float defaultValue() { return 1; }
};
diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp
index 21d72a0fdc..0fda27f0dc 100644
--- a/src/mbgl/style/layers/raster_layer.cpp
+++ b/src/mbgl/style/layers/raster_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,13 @@ std::unique_ptr<Layer> RasterLayer::Impl::clone() const {
std::unique_ptr<Layer> RasterLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<RasterLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = RasterPaintProperties();
return std::move(result);
}
+void RasterLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
+}
+
// Source
const std::string& RasterLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp
index b7c926f623..8e69c21ca8 100644
--- a/src/mbgl/style/layers/raster_layer_impl.hpp
+++ b/src/mbgl/style/layers/raster_layer_impl.hpp
@@ -11,6 +11,7 @@ class RasterLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index 61f360ff64..c9014e7ee7 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
+#include <mbgl/style/conversion/stringify.hpp>
namespace mbgl {
namespace style {
@@ -27,11 +28,14 @@ std::unique_ptr<Layer> SymbolLayer::Impl::clone() const {
std::unique_ptr<Layer> SymbolLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<SymbolLayer>(*this);
result->impl->id = id_;
- result->impl->ref = this->id;
result->impl->paint = SymbolPaintProperties();
return std::move(result);
}
+void SymbolLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
+ conversion::stringify(writer, layout);
+}
+
// Source
const std::string& SymbolLayer::getSourceID() const {
diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp
index 64968f51e4..8fb85513cf 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.cpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.cpp
@@ -29,7 +29,9 @@ std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(BucketParameters&, const
return nullptr;
}
-std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(BucketParameters& parameters, const GeometryTileLayer& layer) const {
+std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(BucketParameters& parameters,
+ const GeometryTileLayer& layer,
+ std::vector<std::unique_ptr<Layer>> group) const {
PropertyEvaluationParameters p(parameters.tileID.overscaledZ);
SymbolLayoutProperties::Evaluated evaluated = layout.evaluate(p);
@@ -59,7 +61,7 @@ std::unique_ptr<SymbolLayout> SymbolLayer::Impl::createLayout(BucketParameters&
evaluated.get<IconSize>() = layout.evaluate<IconSize>(PropertyEvaluationParameters(p.z + 1));
evaluated.get<TextSize>() = layout.evaluate<TextSize>(PropertyEvaluationParameters(p.z + 1));
- return std::make_unique<SymbolLayout>(id,
+ return std::make_unique<SymbolLayout>(std::move(group),
layer.getName(),
parameters.tileID.overscaleFactor(),
parameters.tileID.overscaledZ,
diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp
index 4377630491..0d9a7c07e3 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.hpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.hpp
@@ -45,12 +45,14 @@ class SymbolLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
+ void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
void cascade(const CascadeParameters&) override;
bool evaluate(const PropertyEvaluationParameters&) override;
std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
- std::unique_ptr<SymbolLayout> createLayout(BucketParameters&, const GeometryTileLayer&) const;
+ std::unique_ptr<SymbolLayout> createLayout(BucketParameters&, const GeometryTileLayer&,
+ std::vector<std::unique_ptr<Layer>>) const;
SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const;
SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const;
diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp
index 8b72c4347a..f5fd6ce3df 100644
--- a/src/mbgl/style/layers/symbol_layer_properties.hpp
+++ b/src/mbgl/style/layers/symbol_layer_properties.hpp
@@ -10,138 +10,172 @@ namespace mbgl {
namespace style {
struct SymbolPlacement : LayoutProperty<SymbolPlacementType> {
+ static constexpr const char * key = "symbol-placement";
static SymbolPlacementType defaultValue() { return SymbolPlacementType::Point; }
};
struct SymbolSpacing : LayoutProperty<float> {
+ static constexpr const char * key = "symbol-spacing";
static float defaultValue() { return 250; }
};
struct SymbolAvoidEdges : LayoutProperty<bool> {
+ static constexpr const char * key = "symbol-avoid-edges";
static bool defaultValue() { return false; }
};
struct IconAllowOverlap : LayoutProperty<bool> {
+ static constexpr const char * key = "icon-allow-overlap";
static bool defaultValue() { return false; }
};
struct IconIgnorePlacement : LayoutProperty<bool> {
+ static constexpr const char * key = "icon-ignore-placement";
static bool defaultValue() { return false; }
};
struct IconOptional : LayoutProperty<bool> {
+ static constexpr const char * key = "icon-optional";
static bool defaultValue() { return false; }
};
struct IconRotationAlignment : LayoutProperty<AlignmentType> {
+ static constexpr const char * key = "icon-rotation-alignment";
static AlignmentType defaultValue() { return AlignmentType::Auto; }
};
struct IconSize : LayoutProperty<float> {
+ static constexpr const char * key = "icon-size";
static float defaultValue() { return 1; }
};
struct IconTextFit : LayoutProperty<IconTextFitType> {
+ static constexpr const char * key = "icon-text-fit";
static IconTextFitType defaultValue() { return IconTextFitType::None; }
};
struct IconTextFitPadding : LayoutProperty<std::array<float, 4>> {
+ static constexpr const char * key = "icon-text-fit-padding";
static std::array<float, 4> defaultValue() { return {{ 0, 0, 0, 0 }}; }
};
struct IconImage : LayoutProperty<std::string> {
+ static constexpr const char * key = "icon-image";
static std::string defaultValue() { return ""; }
};
struct IconRotate : LayoutProperty<float> {
+ static constexpr const char * key = "icon-rotate";
static float defaultValue() { return 0; }
};
struct IconPadding : LayoutProperty<float> {
+ static constexpr const char * key = "icon-padding";
static float defaultValue() { return 2; }
};
struct IconKeepUpright : LayoutProperty<bool> {
+ static constexpr const char * key = "icon-keep-upright";
static bool defaultValue() { return false; }
};
struct IconOffset : LayoutProperty<std::array<float, 2>> {
+ static constexpr const char * key = "icon-offset";
static std::array<float, 2> defaultValue() { return {{ 0, 0 }}; }
};
struct TextPitchAlignment : LayoutProperty<AlignmentType> {
+ static constexpr const char * key = "text-pitch-alignment";
static AlignmentType defaultValue() { return AlignmentType::Auto; }
};
struct TextRotationAlignment : LayoutProperty<AlignmentType> {
+ static constexpr const char * key = "text-rotation-alignment";
static AlignmentType defaultValue() { return AlignmentType::Auto; }
};
struct TextField : LayoutProperty<std::string> {
+ static constexpr const char * key = "text-field";
static std::string defaultValue() { return ""; }
};
struct TextFont : LayoutProperty<std::vector<std::string>> {
+ static constexpr const char * key = "text-font";
static std::vector<std::string> defaultValue() { return { "Open Sans Regular", "Arial Unicode MS Regular" }; }
};
struct TextSize : LayoutProperty<float> {
+ static constexpr const char * key = "text-size";
static float defaultValue() { return 16; }
};
struct TextMaxWidth : LayoutProperty<float> {
+ static constexpr const char * key = "text-max-width";
static float defaultValue() { return 10; }
};
struct TextLineHeight : LayoutProperty<float> {
+ static constexpr const char * key = "text-line-height";
static float defaultValue() { return 1.2; }
};
struct TextLetterSpacing : LayoutProperty<float> {
+ static constexpr const char * key = "text-letter-spacing";
static float defaultValue() { return 0; }
};
struct TextJustify : LayoutProperty<TextJustifyType> {
+ static constexpr const char * key = "text-justify";
static TextJustifyType defaultValue() { return TextJustifyType::Center; }
};
struct TextAnchor : LayoutProperty<TextAnchorType> {
+ static constexpr const char * key = "text-anchor";
static TextAnchorType defaultValue() { return TextAnchorType::Center; }
};
struct TextMaxAngle : LayoutProperty<float> {
+ static constexpr const char * key = "text-max-angle";
static float defaultValue() { return 45; }
};
struct TextRotate : LayoutProperty<float> {
+ static constexpr const char * key = "text-rotate";
static float defaultValue() { return 0; }
};
struct TextPadding : LayoutProperty<float> {
+ static constexpr const char * key = "text-padding";
static float defaultValue() { return 2; }
};
struct TextKeepUpright : LayoutProperty<bool> {
+ static constexpr const char * key = "text-keep-upright";
static bool defaultValue() { return true; }
};
struct TextTransform : LayoutProperty<TextTransformType> {
+ static constexpr const char * key = "text-transform";
static TextTransformType defaultValue() { return TextTransformType::None; }
};
struct TextOffset : LayoutProperty<std::array<float, 2>> {
+ static constexpr const char * key = "text-offset";
static std::array<float, 2> defaultValue() { return {{ 0, 0 }}; }
};
struct TextAllowOverlap : LayoutProperty<bool> {
+ static constexpr const char * key = "text-allow-overlap";
static bool defaultValue() { return false; }
};
struct TextIgnorePlacement : LayoutProperty<bool> {
+ static constexpr const char * key = "text-ignore-placement";
static bool defaultValue() { return false; }
};
struct TextOptional : LayoutProperty<bool> {
+ static constexpr const char * key = "text-optional";
static bool defaultValue() { return false; }
};