[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.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user