summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-30 17:01:52 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-31 14:17:33 -0700
commit1a9bccbb850c637583c18e7409e3b87a0dd9ff79 (patch)
treecd158e3a469bfcbb1fbeab8efca43fc8ef698765 /src/mbgl
parent743d95405363e0eea1b80e8c28bde245211f7868 (diff)
downloadqtlocation-mapboxgl-1a9bccbb850c637583c18e7409e3b87a0dd9ff79.tar.gz
[core] Add DDS support for icon-image
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/layout/symbol_layout.cpp33
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp6
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp2
3 files changed, 21 insertions, 20 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 7b77bdaf6f..ad58f06311 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -30,6 +30,14 @@ namespace mbgl {
using namespace style;
+template <class Property>
+static bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) {
+ return layout.get<Property>().match(
+ [&] (const std::string& s) { return !s.empty(); },
+ [&] (const auto&) { return true; }
+ );
+}
+
SymbolLayout::SymbolLayout(const BucketParameters& parameters,
const std::vector<const Layer*>& layers,
const GeometryTileLayer& sourceLayer,
@@ -72,15 +80,9 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
layout.get<IconSize>() = leader.layout.evaluate<IconSize>(PropertyEvaluationParameters(zoom + 1));
layout.get<TextSize>() = leader.layout.evaluate<TextSize>(PropertyEvaluationParameters(zoom + 1));
-
- const bool hasTextField = layout.get<TextField>().match(
- [&] (const std::string& s) { return !s.empty(); },
- [&] (const auto&) { return true; }
- );
-
- const bool hasText = !layout.get<TextFont>().empty() && hasTextField;
- const bool hasIcon = !layout.get<IconImage>().empty();
+ const bool hasText = has<TextField>(layout) && !layout.get<TextFont>().empty();
+ const bool hasIcon = has<IconImage>(layout);
if (!hasText && !hasIcon) {
return;
@@ -147,7 +149,11 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
}
if (hasIcon) {
- ft.icon = util::replaceTokens(layout.get<IconImage>(), getValue);
+ std::string icon = layout.evaluate<IconImage>(zoom, ft);
+ if (layout.get<IconImage>().isConstant()) {
+ icon = util::replaceTokens(icon, getValue);
+ }
+ ft.icon = icon;
}
if (ft.text || ft.icon) {
@@ -165,16 +171,11 @@ bool SymbolLayout::hasSymbolInstances() const {
}
bool SymbolLayout::canPrepare(GlyphAtlas& glyphAtlas) {
- const bool hasTextField = layout.get<TextField>().match(
- [&] (const std::string& s) { return !s.empty(); },
- [&] (const auto&) { return true; }
- );
-
- if (hasTextField && !layout.get<TextFont>().empty() && !glyphAtlas.hasGlyphRanges(layout.get<TextFont>(), ranges)) {
+ if (has<TextField>(layout) && !layout.get<TextFont>().empty() && !glyphAtlas.hasGlyphRanges(layout.get<TextFont>(), ranges)) {
return false;
}
- if (!layout.get<IconImage>().empty() && !spriteAtlas.isLoaded()) {
+ if (has<IconImage>(layout) && !spriteAtlas.isLoaded()) {
return false;
}
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index 3a896d4c93..bd5cf30ad6 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -203,15 +203,15 @@ void SymbolLayer::setIconTextFitPadding(PropertyValue<std::array<float, 4>> valu
impl->layout.unevaluated.get<IconTextFitPadding>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding");
}
-PropertyValue<std::string> SymbolLayer::getDefaultIconImage() {
+DataDrivenPropertyValue<std::string> SymbolLayer::getDefaultIconImage() {
return IconImage::defaultValue();
}
-PropertyValue<std::string> SymbolLayer::getIconImage() const {
+DataDrivenPropertyValue<std::string> SymbolLayer::getIconImage() const {
return impl->layout.unevaluated.get<IconImage>();
}
-void SymbolLayer::setIconImage(PropertyValue<std::string> value) {
+void SymbolLayer::setIconImage(DataDrivenPropertyValue<std::string> value) {
if (value == getIconImage())
return;
impl->layout.unevaluated.get<IconImage>() = value;
diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp
index 4e4c64eec9..4f63ed419a 100644
--- a/src/mbgl/style/layers/symbol_layer_properties.hpp
+++ b/src/mbgl/style/layers/symbol_layer_properties.hpp
@@ -60,7 +60,7 @@ struct IconTextFitPadding : LayoutProperty<std::array<float, 4>> {
static std::array<float, 4> defaultValue() { return {{ 0, 0, 0, 0 }}; }
};
-struct IconImage : LayoutProperty<std::string> {
+struct IconImage : DataDrivenLayoutProperty<std::string> {
static constexpr const char * key = "icon-image";
static std::string defaultValue() { return ""; }
};