summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/style/layer.hpp5
-rw-r--r--include/mbgl/style/layers/circle_layer.hpp5
-rw-r--r--include/mbgl/style/layers/fill_layer.hpp5
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs17
-rw-r--r--include/mbgl/style/layers/line_layer.hpp5
-rw-r--r--include/mbgl/style/layers/raster_layer.hpp4
-rw-r--r--include/mbgl/style/layers/symbol_layer.hpp5
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp4
-rw-r--r--src/mbgl/annotation/fill_annotation_impl.cpp5
-rw-r--r--src/mbgl/annotation/line_annotation_impl.cpp4
-rw-r--r--src/mbgl/annotation/style_sourced_annotation_impl.cpp9
-rw-r--r--src/mbgl/style/layer.cpp8
-rw-r--r--src/mbgl/style/layer_impl.cpp10
-rw-r--r--src/mbgl/style/layer_impl.hpp6
-rw-r--r--src/mbgl/style/layers/circle_layer.cpp12
-rw-r--r--src/mbgl/style/layers/fill_layer.cpp12
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs26
-rw-r--r--src/mbgl/style/layers/line_layer.cpp12
-rw-r--r--src/mbgl/style/layers/raster_layer.cpp8
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp12
-rw-r--r--src/mbgl/style/parser.cpp39
-rw-r--r--test/style/source.cpp4
-rw-r--r--test/style/style_layer.cpp18
-rw-r--r--test/text/quads.cpp123
24 files changed, 176 insertions, 182 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp
index 1f4a6fdf35..1eff9eb3dc 100644
--- a/include/mbgl/style/layer.hpp
+++ b/include/mbgl/style/layer.hpp
@@ -55,11 +55,6 @@ public:
float getMaxZoom() const;
void setMaxZoom(float) const;
- // Create a new layer with the specified `id` and `ref`. All other properties
- // are copied from this layer.
- std::unique_ptr<Layer> copy(const std::string& id,
- const std::string& ref) const;
-
// Private implementation
class Impl;
const std::unique_ptr<Impl> baseImpl;
diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp
index 10d281b6ac..9c2b458d4b 100644
--- a/include/mbgl/style/layers/circle_layer.hpp
+++ b/include/mbgl/style/layers/circle_layer.hpp
@@ -13,14 +13,13 @@ namespace style {
class CircleLayer : public Layer {
public:
- CircleLayer(const std::string& layerID);
+ CircleLayer(const std::string& layerID, const std::string& sourceID);
~CircleLayer() final;
// Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;
+ void setSourceLayer(const std::string& sourceLayer);
void setFilter(const Filter&);
const Filter& getFilter() const;
diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp
index a14bf4a390..90538dd3ea 100644
--- a/include/mbgl/style/layers/fill_layer.hpp
+++ b/include/mbgl/style/layers/fill_layer.hpp
@@ -13,14 +13,13 @@ namespace style {
class FillLayer : public Layer {
public:
- FillLayer(const std::string& layerID);
+ FillLayer(const std::string& layerID, const std::string& sourceID);
~FillLayer() final;
// Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;
+ void setSourceLayer(const std::string& sourceLayer);
void setFilter(const Filter&);
const Filter& getFilter() const;
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
index fdf7620892..60365be906 100644
--- a/include/mbgl/style/layers/layer.hpp.ejs
+++ b/include/mbgl/style/layers/layer.hpp.ejs
@@ -22,24 +22,23 @@ namespace style {
class <%- camelize(type) %>Layer : public Layer {
public:
+<% if (type === 'background') { -%>
<%- camelize(type) %>Layer(const std::string& layerID);
+<% } else { -%>
+ <%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID);
+<% } -%>
~<%- camelize(type) %>Layer() final;
-<% if (type === 'raster') { -%>
+<% if (type !== 'background') { -%>
// Source
-
- void setSource(const std::string& sourceID);
- const std::string& getSourceID() const;
-
-<% } else if (type !== 'background') { -%>
- // Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
+<% if (type !== 'raster') { -%>
const std::string& getSourceLayer() const;
+ void setSourceLayer(const std::string& sourceLayer);
void setFilter(const Filter&);
const Filter& getFilter() const;
+<% } -%>
<% } -%>
<% if (layoutProperties.length) { -%>
diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp
index fb9e37811a..4ffeee114a 100644
--- a/include/mbgl/style/layers/line_layer.hpp
+++ b/include/mbgl/style/layers/line_layer.hpp
@@ -15,14 +15,13 @@ namespace style {
class LineLayer : public Layer {
public:
- LineLayer(const std::string& layerID);
+ LineLayer(const std::string& layerID, const std::string& sourceID);
~LineLayer() final;
// Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;
+ void setSourceLayer(const std::string& sourceLayer);
void setFilter(const Filter&);
const Filter& getFilter() const;
diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp
index 6d0c7dd91c..372434e46d 100644
--- a/include/mbgl/style/layers/raster_layer.hpp
+++ b/include/mbgl/style/layers/raster_layer.hpp
@@ -13,12 +13,10 @@ namespace style {
class RasterLayer : public Layer {
public:
- RasterLayer(const std::string& layerID);
+ RasterLayer(const std::string& layerID, const std::string& sourceID);
~RasterLayer() final;
// Source
-
- void setSource(const std::string& sourceID);
const std::string& getSourceID() const;
// Paint properties
diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp
index 7d98a5ef6b..b21c8deaf7 100644
--- a/include/mbgl/style/layers/symbol_layer.hpp
+++ b/include/mbgl/style/layers/symbol_layer.hpp
@@ -15,14 +15,13 @@ namespace style {
class SymbolLayer : public Layer {
public:
- SymbolLayer(const std::string& layerID);
+ SymbolLayer(const std::string& layerID, const std::string& sourceID);
~SymbolLayer() final;
// Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;
+ void setSourceLayer(const std::string& sourceLayer);
void setFilter(const Filter&);
const Filter& getFilter() const;
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index dd2467e34f..7e1984a3c8 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -157,9 +157,9 @@ void AnnotationManager::updateStyle(Style& style) {
source->baseImpl->enabled = true;
style.addSource(std::move(source));
- std::unique_ptr<SymbolLayer> layer = std::make_unique<SymbolLayer>(PointLayerID);
+ std::unique_ptr<SymbolLayer> layer = std::make_unique<SymbolLayer>(PointLayerID, SourceID);
- layer->setSource(SourceID, PointLayerID);
+ layer->setSourceLayer(PointLayerID);
layer->setIconImage({"{sprite}"});
layer->setIconAllowOverlap(true);
diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp
index cbd76ede97..8146c68a53 100644
--- a/src/mbgl/annotation/fill_annotation_impl.cpp
+++ b/src/mbgl/annotation/fill_annotation_impl.cpp
@@ -16,9 +16,8 @@ void FillAnnotationImpl::updateStyle(Style& style) const {
if (style.getLayer(layerID))
return;
- std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(layerID);
- layer->setSource(AnnotationManager::SourceID, layerID);
-
+ std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(layerID, AnnotationManager::SourceID);
+ layer->setSourceLayer(layerID);
layer->setFillOpacity(annotation.opacity);
layer->setFillColor(annotation.color);
layer->setFillOutlineColor(annotation.outlineColor);
diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp
index e689c3240d..bc7b8df50e 100644
--- a/src/mbgl/annotation/line_annotation_impl.cpp
+++ b/src/mbgl/annotation/line_annotation_impl.cpp
@@ -16,8 +16,8 @@ void LineAnnotationImpl::updateStyle(Style& style) const {
if (style.getLayer(layerID))
return;
- std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(layerID);
- layer->setSource(AnnotationManager::SourceID, layerID);
+ std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(layerID, AnnotationManager::SourceID);
+ layer->setSourceLayer(layerID);
layer->setLineJoin(LineJoinType::Round);
layer->setLineOpacity(annotation.opacity);
layer->setLineWidth(annotation.width);
diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.cpp b/src/mbgl/annotation/style_sourced_annotation_impl.cpp
index d828014606..d3212da12d 100644
--- a/src/mbgl/annotation/style_sourced_annotation_impl.cpp
+++ b/src/mbgl/annotation/style_sourced_annotation_impl.cpp
@@ -2,6 +2,7 @@
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/layer.hpp>
+#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -23,13 +24,13 @@ void StyleSourcedAnnotationImpl::updateStyle(Style& style) const {
return;
if (sourceLayer->is<LineLayer>()) {
- std::unique_ptr<Layer> layer = sourceLayer->copy(layerID, "");
- layer->as<LineLayer>()->setSource(AnnotationManager::SourceID, layerID);
+ std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, "", AnnotationManager::SourceID);
+ layer->as<LineLayer>()->setSourceLayer(layerID);
layer->as<LineLayer>()->setVisibility(VisibilityType::Visible);
style.addLayer(std::move(layer), sourceLayer->getID());
} else if (sourceLayer->is<FillLayer>()) {
- std::unique_ptr<Layer> layer = sourceLayer->copy(layerID, "");
- layer->as<FillLayer>()->setSource(AnnotationManager::SourceID, layerID);
+ std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, "", AnnotationManager::SourceID);
+ layer->as<FillLayer>()->setSourceLayer(layerID);
layer->as<FillLayer>()->setVisibility(VisibilityType::Visible);
style.addLayer(std::move(layer), sourceLayer->getID());
}
diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp
index 342699a2c9..6eff64ae09 100644
--- a/src/mbgl/style/layer.cpp
+++ b/src/mbgl/style/layer.cpp
@@ -38,13 +38,5 @@ void Layer::setMaxZoom(float maxZoom) const {
baseImpl->maxZoom = maxZoom;
}
-std::unique_ptr<Layer> Layer::copy(const std::string& id,
- const std::string& ref) const {
- std::unique_ptr<Layer> result = baseImpl->clone();
- result->baseImpl->id = id;
- result->baseImpl->ref = ref;
- return result;
-}
-
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp
index 74cc80d253..b345297027 100644
--- a/src/mbgl/style/layer_impl.cpp
+++ b/src/mbgl/style/layer_impl.cpp
@@ -3,6 +3,16 @@
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;
}
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp
index 34fc6b2735..33ad2e32ac 100644
--- a/src/mbgl/style/layer_impl.hpp
+++ b/src/mbgl/style/layer_impl.hpp
@@ -37,6 +37,12 @@ class Layer::Impl {
public:
virtual ~Impl() = default;
+ // Create a new layer with the specified `id`, `ref`, 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;
diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp
index bdfbf629e6..8066d7fd3c 100644
--- a/src/mbgl/style/layers/circle_layer.cpp
+++ b/src/mbgl/style/layers/circle_layer.cpp
@@ -6,10 +6,11 @@
namespace mbgl {
namespace style {
-CircleLayer::CircleLayer(const std::string& layerID)
+CircleLayer::CircleLayer(const std::string& layerID, const std::string& sourceID)
: Layer(Type::Circle, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
+ impl->source = sourceID;
}
CircleLayer::CircleLayer(const Impl& other)
@@ -25,15 +26,14 @@ std::unique_ptr<Layer> CircleLayer::Impl::clone() const {
// Source
-void CircleLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
- impl->sourceLayer = sourceLayer;
-}
-
const std::string& CircleLayer::getSourceID() const {
return impl->source;
}
+void CircleLayer::setSourceLayer(const std::string& sourceLayer) {
+ impl->sourceLayer = sourceLayer;
+}
+
const std::string& CircleLayer::getSourceLayer() const {
return impl->sourceLayer;
}
diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp
index 1deaabb5ef..7d7d1a9e27 100644
--- a/src/mbgl/style/layers/fill_layer.cpp
+++ b/src/mbgl/style/layers/fill_layer.cpp
@@ -6,10 +6,11 @@
namespace mbgl {
namespace style {
-FillLayer::FillLayer(const std::string& layerID)
+FillLayer::FillLayer(const std::string& layerID, const std::string& sourceID)
: Layer(Type::Fill, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
+ impl->source = sourceID;
}
FillLayer::FillLayer(const Impl& other)
@@ -25,15 +26,14 @@ std::unique_ptr<Layer> FillLayer::Impl::clone() const {
// Source
-void FillLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
- impl->sourceLayer = sourceLayer;
-}
-
const std::string& FillLayer::getSourceID() const {
return impl->source;
}
+void FillLayer::setSourceLayer(const std::string& sourceLayer) {
+ impl->sourceLayer = sourceLayer;
+}
+
const std::string& FillLayer::getSourceLayer() const {
return impl->sourceLayer;
}
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index 633d673804..4f78d6b55e 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -11,11 +11,20 @@
namespace mbgl {
namespace style {
+<% if (type === 'background') { -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID)
: Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
}
+<% } else { -%>
+<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID)
+ : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>())
+ , impl(static_cast<Impl*>(baseImpl.get())) {
+ impl->id = layerID;
+ impl->source = sourceID;
+}
+<% } -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other)
: Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>(other))
@@ -28,28 +37,18 @@ std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const {
return std::make_unique<<%- camelize(type) %>Layer>(*this);
}
-<% if (type === 'raster') { -%>
+<% if (type !== 'background') { -%>
// Source
-void <%- camelize(type) %>Layer::setSource(const std::string& sourceID) {
- impl->source = sourceID;
-}
-
const std::string& <%- camelize(type) %>Layer::getSourceID() const {
return impl->source;
}
-<% } else if (type !== 'background') { -%>
-// Source
-void <%- camelize(type) %>Layer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
+<% if (type !== 'raster') { -%>
+void <%- camelize(type) %>Layer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
}
-const std::string& <%- camelize(type) %>Layer::getSourceID() const {
- return impl->source;
-}
-
const std::string& <%- camelize(type) %>Layer::getSourceLayer() const {
return impl->sourceLayer;
}
@@ -64,6 +63,7 @@ const Filter& <%- camelize(type) %>Layer::getFilter() const {
return impl->filter;
}
<% } -%>
+<% } -%>
// Layout properties
diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp
index abe326a672..e720d1fcfb 100644
--- a/src/mbgl/style/layers/line_layer.cpp
+++ b/src/mbgl/style/layers/line_layer.cpp
@@ -6,10 +6,11 @@
namespace mbgl {
namespace style {
-LineLayer::LineLayer(const std::string& layerID)
+LineLayer::LineLayer(const std::string& layerID, const std::string& sourceID)
: Layer(Type::Line, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
+ impl->source = sourceID;
}
LineLayer::LineLayer(const Impl& other)
@@ -25,15 +26,14 @@ std::unique_ptr<Layer> LineLayer::Impl::clone() const {
// Source
-void LineLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
- impl->sourceLayer = sourceLayer;
-}
-
const std::string& LineLayer::getSourceID() const {
return impl->source;
}
+void LineLayer::setSourceLayer(const std::string& sourceLayer) {
+ impl->sourceLayer = sourceLayer;
+}
+
const std::string& LineLayer::getSourceLayer() const {
return impl->sourceLayer;
}
diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp
index fb7f08fbe9..cdba19ac4e 100644
--- a/src/mbgl/style/layers/raster_layer.cpp
+++ b/src/mbgl/style/layers/raster_layer.cpp
@@ -6,10 +6,11 @@
namespace mbgl {
namespace style {
-RasterLayer::RasterLayer(const std::string& layerID)
+RasterLayer::RasterLayer(const std::string& layerID, const std::string& sourceID)
: Layer(Type::Raster, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
+ impl->source = sourceID;
}
RasterLayer::RasterLayer(const Impl& other)
@@ -25,14 +26,11 @@ std::unique_ptr<Layer> RasterLayer::Impl::clone() const {
// Source
-void RasterLayer::setSource(const std::string& sourceID) {
- impl->source = sourceID;
-}
-
const std::string& RasterLayer::getSourceID() const {
return impl->source;
}
+
// Layout properties
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index 38a898deca..905caa0310 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -6,10 +6,11 @@
namespace mbgl {
namespace style {
-SymbolLayer::SymbolLayer(const std::string& layerID)
+SymbolLayer::SymbolLayer(const std::string& layerID, const std::string& sourceID)
: Layer(Type::Symbol, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
+ impl->source = sourceID;
}
SymbolLayer::SymbolLayer(const Impl& other)
@@ -25,15 +26,14 @@ std::unique_ptr<Layer> SymbolLayer::Impl::clone() const {
// Source
-void SymbolLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
- impl->sourceLayer = sourceLayer;
-}
-
const std::string& SymbolLayer::getSourceID() const {
return impl->source;
}
+void SymbolLayer::setSourceLayer(const std::string& sourceLayer) {
+ impl->sourceLayer = sourceLayer;
+}
+
const std::string& SymbolLayer::getSourceLayer() const {
return impl->sourceLayer;
}
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index bbe2fd7862..a0f4dd24c9 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -219,7 +219,7 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
return;
}
- layer = reference->copy(id, ref);
+ layer = reference->baseImpl->copy(id, ref, reference->baseImpl->source);
layer->baseImpl->parsePaints(value);
} else {
// Otherwise, parse the source/source-layer/filter/render keys to form the bucket.
@@ -235,17 +235,31 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
}
std::string type { typeVal.GetString(), typeVal.GetStringLength() };
+ std::string source;
+
+ if (value.HasMember("source")) {
+ const JSValue& value_source = value["source"];
+ if (value_source.IsString()) {
+ source = { value_source.GetString(), value_source.GetStringLength() };
+ auto source_it = sourcesMap.find(source);
+ if (source_it == sourcesMap.end()) {
+ Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", source.c_str(), id.c_str());
+ }
+ } else {
+ Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", id.c_str());
+ }
+ }
if (type == "fill") {
- layer = std::make_unique<FillLayer>(id);
+ layer = std::make_unique<FillLayer>(id, source);
} else if (type == "line") {
- layer = std::make_unique<LineLayer>(id);
+ layer = std::make_unique<LineLayer>(id, source);
} else if (type == "circle") {
- layer = std::make_unique<CircleLayer>(id);
+ layer = std::make_unique<CircleLayer>(id, source);
} else if (type == "symbol") {
- layer = std::make_unique<SymbolLayer>(id);
+ layer = std::make_unique<SymbolLayer>(id, source);
} else if (type == "raster") {
- layer = std::make_unique<RasterLayer>(id);
+ layer = std::make_unique<RasterLayer>(id, source);
} else if (type == "background") {
layer = std::make_unique<BackgroundLayer>(id);
} else {
@@ -255,19 +269,6 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
Layer::Impl* impl = layer->baseImpl.get();
- if (value.HasMember("source")) {
- const JSValue& value_source = value["source"];
- if (value_source.IsString()) {
- impl->source = { value_source.GetString(), value_source.GetStringLength() };
- auto source_it = sourcesMap.find(impl->source);
- if (source_it == sourcesMap.end()) {
- Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", impl->source.c_str(), impl->id.c_str());
- }
- } else {
- Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", impl->id.c_str());
- }
- }
-
if (value.HasMember("source-layer")) {
const JSValue& value_source_layer = value["source-layer"];
if (value_source_layer.IsString()) {
diff --git a/test/style/source.cpp b/test/style/source.cpp
index d31474712e..59b2524e17 100644
--- a/test/style/source.cpp
+++ b/test/style/source.cpp
@@ -276,8 +276,8 @@ TEST(Source, VectorTileCorrupt) {
};
// Need to have at least one layer that uses the source.
- auto layer = std::make_unique<LineLayer>("id");
- layer->setSource("source", "water");
+ auto layer = std::make_unique<LineLayer>("id", "source");
+ layer->setSourceLayer("water");
test.style.addLayer(std::move(layer));
Tileset tileset;
diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp
index 3274131966..9c6a6e924a 100644
--- a/test/style/style_layer.cpp
+++ b/test/style/style_layer.cpp
@@ -55,12 +55,12 @@ const auto duration = PropertyValue<float> { 1.0f };
TEST(Layer, Clone) {
testClone<BackgroundLayer>("background");
- testClone<CircleLayer>("circle");
+ testClone<CircleLayer>("circle", "source");
testClone<CustomLayer>("custom", [](void*){}, [](void*, const CustomLayerRenderParameters&){}, [](void*){}, nullptr),
- testClone<FillLayer>("fill");
- testClone<LineLayer>("line");
- testClone<RasterLayer>("raster");
- testClone<SymbolLayer>("symbol");
+ testClone<FillLayer>("fill", "source");
+ testClone<LineLayer>("line", "source");
+ testClone<RasterLayer>("raster", "source");
+ testClone<SymbolLayer>("symbol", "source");
}
TEST(Layer, BackgroundProperties) {
@@ -80,7 +80,7 @@ TEST(Layer, BackgroundProperties) {
}
TEST(Layer, CircleProperties) {
- auto layer = std::make_unique<CircleLayer>("circle");
+ auto layer = std::make_unique<CircleLayer>("circle", "source");
EXPECT_TRUE(layer->is<CircleLayer>());
// Paint properties
@@ -105,7 +105,7 @@ TEST(Layer, CircleProperties) {
}
TEST(Layer, FillProperties) {
- auto layer = std::make_unique<FillLayer>("fill");
+ auto layer = std::make_unique<FillLayer>("fill", "source");
EXPECT_TRUE(layer->is<FillLayer>());
// Paint properties
@@ -133,7 +133,7 @@ TEST(Layer, FillProperties) {
}
TEST(Layer, LineProperties) {
- auto layer = std::make_unique<LineLayer>("line");
+ auto layer = std::make_unique<LineLayer>("line", "source");
EXPECT_TRUE(layer->is<LineLayer>());
// Layout properties
@@ -184,7 +184,7 @@ TEST(Layer, LineProperties) {
}
TEST(Layer, RasterProperties) {
- auto layer = std::make_unique<RasterLayer>("raster");
+ auto layer = std::make_unique<RasterLayer>("raster", "source");
EXPECT_TRUE(layer->is<RasterLayer>());
// Paint properties
diff --git a/test/text/quads.cpp b/test/text/quads.cpp
index 6fdd769fc3..2dd6a68cad 100644
--- a/test/text/quads.cpp
+++ b/test/text/quads.cpp
@@ -4,14 +4,13 @@
#include <mbgl/text/quads.hpp>
#include <mbgl/text/shaping.hpp>
#include <mbgl/text/glyph.hpp>
-#include <mbgl/style/layers/symbol_layer.hpp>
-#include <mbgl/style/layers/symbol_layer_impl.hpp>
+#include <mbgl/style/layers/symbol_layer_properties.hpp>
using namespace mbgl;
using namespace mbgl::style;
TEST(getIconQuads, normal) {
- auto layer = std::make_unique<SymbolLayer>("symbol");
+ SymbolLayoutProperties layout;
Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0);
SpriteAtlasElement image = {
Rect<uint16_t>( 0, 0, 15, 11 ),
@@ -22,7 +21,7 @@ TEST(getIconQuads, normal) {
GeometryCoordinates line;
Shaping shapedText;
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads.size(), 1u);
ASSERT_EQ(quads[0].anchorPoint.x, 2);
@@ -58,8 +57,8 @@ TEST(getIconQuads, style) {
// none
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads.size(), 1u);
ASSERT_EQ(quads[0].anchorPoint.x, 0);
@@ -79,10 +78,10 @@ TEST(getIconQuads, style) {
// width
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(24.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -60);
ASSERT_EQ(quads[0].tl.y, 0);
@@ -96,10 +95,10 @@ TEST(getIconQuads, style) {
// width x textSize
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -113,14 +112,14 @@ TEST(getIconQuads, style) {
// width x textSize + padding
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
- layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
- layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ layout.iconTextFitPadding.value[0] = 5.0f;
+ layout.iconTextFitPadding.value[1] = 10.0f;
+ layout.iconTextFitPadding.value[2] = 5.0f;
+ layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -40);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -134,10 +133,10 @@ TEST(getIconQuads, style) {
// height
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(24.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -151,10 +150,10 @@ TEST(getIconQuads, style) {
// height x textSize
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -20);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -168,14 +167,14 @@ TEST(getIconQuads, style) {
// height x textSize + padding
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
- layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
- layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ layout.iconTextFitPadding.value[0] = 5.0f;
+ layout.iconTextFitPadding.value[1] = 10.0f;
+ layout.iconTextFitPadding.value[2] = 5.0f;
+ layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -189,10 +188,10 @@ TEST(getIconQuads, style) {
// both
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(24.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -60);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -206,10 +205,10 @@ TEST(getIconQuads, style) {
// both x textSize
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -223,14 +222,14 @@ TEST(getIconQuads, style) {
// both x textSize + padding
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
- layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ layout.iconTextFitPadding.value[0] = 5.0f;
+ layout.iconTextFitPadding.value[1] = 10.0f;
+ layout.iconTextFitPadding.value[2] = 5.0f;
+ layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -40);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -244,14 +243,14 @@ TEST(getIconQuads, style) {
// both x textSize + padding t/r/b/l
{
- auto layer = std::make_unique<SymbolLayer>("symbol");
- layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
- layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- layer->impl->layout.iconTextFitPadding.value[0] = 0.0f;
- layer->impl->layout.iconTextFitPadding.value[1] = 5.0f;
- layer->impl->layout.iconTextFitPadding.value[2] = 10.0f;
- layer->impl->layout.iconTextFitPadding.value[3] = 15.0f;
- SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+ SymbolLayoutProperties layout;
+ layout.textSize = LayoutProperty<float>(12.0f);
+ layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ layout.iconTextFitPadding.value[0] = 0.0f;
+ layout.iconTextFitPadding.value[1] = 5.0f;
+ layout.iconTextFitPadding.value[2] = 10.0f;
+ layout.iconTextFitPadding.value[3] = 15.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
ASSERT_EQ(quads[0].tl.x, -45);
ASSERT_EQ(quads[0].tl.y, -5);