summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorryanhamley <ryan.hamley@mapbox.com>2018-08-30 17:18:29 -0700
committerryanhamley <ryan.hamley@mapbox.com>2018-09-07 13:05:19 -0700
commit31cca05fc6a9d08d3b0028149f7ef2f2348b18e9 (patch)
tree0fc6980686269d0deade28823be33bf9446610a7 /src
parent79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41 (diff)
downloadqtlocation-mapboxgl-31cca05fc6a9d08d3b0028149f7ef2f2348b18e9.tar.gz
Port symbol-z-order symbol layout style-spec property to Nativeupstream/sort-by-y
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/layout/symbol_layout.cpp7
-rw-r--r--src/mbgl/style/conversion/constant.cpp1
-rw-r--r--src/mbgl/style/conversion/function.cpp2
-rw-r--r--src/mbgl/style/conversion/property_value.cpp1
-rw-r--r--src/mbgl/style/expression/value.cpp3
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp35
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp6
-rw-r--r--src/mbgl/style/types.cpp5
8 files changed, 57 insertions, 3 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 344a76bbe9..74abd74f01 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -401,10 +401,11 @@ std::vector<float> CalculateTileDistances(const GeometryCoordinates& line, const
}
void SymbolLayout::createBucket(const ImagePositions&, std::unique_ptr<FeatureIndex>&, std::unordered_map<std::string, std::shared_ptr<Bucket>>& buckets, const bool firstLoad, const bool showCollisionBoxes) {
- const bool mayOverlap = layout.get<TextAllowOverlap>() || layout.get<IconAllowOverlap>() ||
- layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>();
+ const bool zOrderByViewport = layout.get<SymbolZOrder>() == SymbolZOrderType::ViewportY;
+ const bool sortFeaturesByY = zOrderByViewport && (layout.get<TextAllowOverlap>() || layout.get<IconAllowOverlap>() ||
+ layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>());
- auto bucket = std::make_shared<SymbolBucket>(layout, layerPaintProperties, textSize, iconSize, zoom, sdfIcons, iconsNeedLinear, mayOverlap, bucketLeaderID, std::move(symbolInstances));
+ auto bucket = std::make_shared<SymbolBucket>(layout, layerPaintProperties, textSize, iconSize, zoom, sdfIcons, iconsNeedLinear, sortFeaturesByY, bucketLeaderID, std::move(symbolInstances));
for (SymbolInstance &symbolInstance : bucket->symbolInstances) {
diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp
index de4ab22269..bdc6371722 100644
--- a/src/mbgl/style/conversion/constant.cpp
+++ b/src/mbgl/style/conversion/constant.cpp
@@ -59,6 +59,7 @@ template optional<LineJoinType> Converter<LineJoinType>::operator()(const Conver
template optional<RasterResamplingType> Converter<RasterResamplingType>::operator()(const Convertible&, Error&) const;
template optional<SymbolAnchorType> Converter<SymbolAnchorType>::operator()(const Convertible&, Error&) const;
template optional<SymbolPlacementType> Converter<SymbolPlacementType>::operator()(const Convertible&, Error&) const;
+template optional<SymbolZOrderType> Converter<SymbolZOrderType>::operator()(const Convertible&, Error&) const;
template optional<TextJustifyType> Converter<TextJustifyType>::operator()(const Convertible&, Error&) const;
template optional<TextTransformType> Converter<TextTransformType>::operator()(const Convertible&, Error&) const;
template optional<TranslateAnchorType> Converter<TranslateAnchorType>::operator()(const Convertible&, Error&) const;
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index 6aadaad3b3..2ce2f4eafd 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -131,6 +131,8 @@ template optional<PropertyExpression<SymbolAnchorType>>
convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<SymbolPlacementType>>
convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<SymbolZOrderType>>
+ convertFunctionToExpression<SymbolZOrderType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<TextJustifyType>>
convertFunctionToExpression<TextJustifyType>(const Convertible&, Error&, bool);
template optional<PropertyExpression<TextTransformType>>
diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp
index 8a93c24767..3b79ecc0db 100644
--- a/src/mbgl/style/conversion/property_value.cpp
+++ b/src/mbgl/style/conversion/property_value.cpp
@@ -74,6 +74,7 @@ template optional<PropertyValue<Position>> Converter<PropertyValue<Position>>::o
template optional<PropertyValue<RasterResamplingType>> Converter<PropertyValue<RasterResamplingType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<SymbolAnchorType>> Converter<PropertyValue<SymbolAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<SymbolPlacementType>> Converter<PropertyValue<SymbolPlacementType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
+template optional<PropertyValue<SymbolZOrderType>> Converter<PropertyValue<SymbolZOrderType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TextJustifyType>> Converter<PropertyValue<TextJustifyType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TextTransformType>> Converter<PropertyValue<TextTransformType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
template optional<PropertyValue<TranslateAnchorType>> Converter<PropertyValue<TranslateAnchorType>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const;
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index ddf1ff0ca4..f089c918cd 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -297,6 +297,9 @@ template struct ValueConverter<LineJoinType>;
template type::Type valueTypeToExpressionType<SymbolPlacementType>();
template struct ValueConverter<SymbolPlacementType>;
+
+template type::Type valueTypeToExpressionType<SymbolZOrderType>();
+template struct ValueConverter<SymbolZOrderType>;
template type::Type valueTypeToExpressionType<SymbolAnchorType>();
template struct ValueConverter<SymbolAnchorType>;
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index 4ea138a7f5..c116d5b7e9 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -149,6 +149,22 @@ void SymbolLayer::setSymbolAvoidEdges(PropertyValue<bool> value) {
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
+PropertyValue<SymbolZOrderType> SymbolLayer::getDefaultSymbolZOrder() {
+ return SymbolZOrder::defaultValue();
+}
+
+PropertyValue<SymbolZOrderType> SymbolLayer::getSymbolZOrder() const {
+ return impl().layout.get<SymbolZOrder>();
+}
+
+void SymbolLayer::setSymbolZOrder(PropertyValue<SymbolZOrderType> value) {
+ if (value == getSymbolZOrder())
+ return;
+ auto impl_ = mutableImpl();
+ impl_->layout.get<SymbolZOrder>() = value;
+ baseImpl = std::move(impl_);
+ observer->onLayerChanged(*this);
+}
PropertyValue<bool> SymbolLayer::getDefaultIconAllowOverlap() {
return IconAllowOverlap::defaultValue();
}
@@ -1440,6 +1456,7 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
SymbolPlacement,
SymbolSpacing,
SymbolAvoidEdges,
+ SymbolZOrder,
IconAllowOverlap,
IconIgnorePlacement,
IconOptional,
@@ -1496,6 +1513,12 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
break;
+ case util::hashFNV1a("symbol-z-order"):
+ if (name == "symbol-z-order") {
+ property = Property::SymbolZOrder;
+ }
+ break;
+
case util::hashFNV1a("icon-allow-overlap"):
if (name == "icon-allow-overlap") {
property = Property::IconAllowOverlap;
@@ -1801,6 +1824,18 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
}
+ if (property == Property::SymbolZOrder) {
+ Error error;
+ optional<PropertyValue<SymbolZOrderType>> typedValue = convert<PropertyValue<SymbolZOrderType>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setSymbolZOrder(*typedValue);
+ return nullopt;
+
+ }
+
if (property == Property::IconRotationAlignment || property == Property::IconPitchAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) {
Error error;
optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false);
diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp
index e70ac28d59..10d059e787 100644
--- a/src/mbgl/style/layers/symbol_layer_properties.hpp
+++ b/src/mbgl/style/layers/symbol_layer_properties.hpp
@@ -27,6 +27,11 @@ struct SymbolAvoidEdges : LayoutProperty<bool> {
static bool defaultValue() { return false; }
};
+struct SymbolZOrder : LayoutProperty<SymbolZOrderType> {
+ static constexpr const char * key = "symbol-z-order";
+ static SymbolZOrderType defaultValue() { return SymbolZOrderType::ViewportY; }
+};
+
struct IconAllowOverlap : LayoutProperty<bool> {
static constexpr const char * key = "icon-allow-overlap";
static bool defaultValue() { return false; }
@@ -252,6 +257,7 @@ class SymbolLayoutProperties : public Properties<
SymbolPlacement,
SymbolSpacing,
SymbolAvoidEdges,
+ SymbolZOrder,
IconAllowOverlap,
IconIgnorePlacement,
IconOptional,
diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp
index 46de0173de..51174cf152 100644
--- a/src/mbgl/style/types.cpp
+++ b/src/mbgl/style/types.cpp
@@ -76,6 +76,11 @@ MBGL_DEFINE_ENUM(SymbolAnchorType, {
{ SymbolAnchorType::BottomLeft, "bottom-left" },
{ SymbolAnchorType::BottomRight, "bottom-right" }
});
+
+MBGL_DEFINE_ENUM(SymbolZOrderType, {
+ { SymbolZOrderType::ViewportY, "viewport-y" },
+ { SymbolZOrderType::Source, "source" }
+});
MBGL_DEFINE_ENUM(TextJustifyType, {
{ TextJustifyType::Center, "center" },