summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-22 12:31:49 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-24 09:39:15 -0700
commitc4e4cc5081965d03132eea754c27ece3c95961cb (patch)
tree3aa4f722ead3273b1faaed5f30449bb8654cf23d /src
parent089c4e413fbe80711ebd874520d3b8fdcb997112 (diff)
downloadqtlocation-mapboxgl-c4e4cc5081965d03132eea754c27ece3c95961cb.tar.gz
[core] Adjust layer source properties to better reflect reality
* Layer source ID is immutable; must be provided to the constructor * Layer source layer is mutable * Layers with GeoJSON sources do not have a source layer While here, make Layer::copy impl-private.
Diffstat (limited to 'src')
-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
14 files changed, 87 insertions, 80 deletions
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()) {