[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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) { -%>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user