From 88032a785519b4e80dff47a6de732657121cf4fe Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 14 Feb 2018 15:17:48 -0500 Subject: [core] don't hide icons if text is an empty string --- mapbox-gl-js | 2 +- src/mbgl/layout/symbol_instance.cpp | 8 ++++++-- src/mbgl/layout/symbol_instance.hpp | 4 ++++ src/mbgl/layout/symbol_layout.cpp | 9 +++++---- src/mbgl/text/placement.cpp | 12 ++++++------ test/text/cross_tile_symbol_index.test.cpp | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mapbox-gl-js b/mapbox-gl-js index f13c86ea35..eb90e09f71 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit f13c86ea356c384fdab31855b9152f5bf5ef97b8 +Subproject commit eb90e09f7148d56c636412912e5de6214934b329 diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp index 6e152349ca..c7f6269d4b 100644 --- a/src/mbgl/layout/symbol_instance.cpp +++ b/src/mbgl/layout/symbol_instance.cpp @@ -12,6 +12,8 @@ SymbolInstance::SymbolInstance(Anchor& anchor_, const SymbolLayoutProperties::Evaluated& layout, const float layoutTextSize, const uint32_t index_, + const bool hasText_, + const bool hasIcon_, const float textBoxScale, const float textPadding, const SymbolPlacementType textPlacement, @@ -27,8 +29,10 @@ SymbolInstance::SymbolInstance(Anchor& anchor_, anchor(anchor_), line(line_), index(index_), - hasText(shapedTextOrientations.first || shapedTextOrientations.second), - hasIcon(shapedIcon), + hasText(hasText_), + hasIcon(hasIcon_), + hasTextData(shapedTextOrientations.first || shapedTextOrientations.second), + hasIconData(shapedIcon), // Create the collision features that will be used to check whether this symbol instance can be placed textCollisionFeature(line_, anchor, shapedTextOrientations.first, textBoxScale, textPadding, textPlacement, indexedFeature, overscaling), diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp index 827a5dbbdb..e896cde392 100644 --- a/src/mbgl/layout/symbol_instance.hpp +++ b/src/mbgl/layout/symbol_instance.hpp @@ -20,6 +20,8 @@ public: const style::SymbolLayoutProperties::Evaluated&, const float layoutTextSize, const uint32_t index, + const bool hasText, + const bool hasIcon, const float textBoxScale, const float textPadding, style::SymbolPlacementType textPlacement, @@ -38,6 +40,8 @@ public: uint32_t index; bool hasText; bool hasIcon; + bool hasTextData; + bool hasIconData; SymbolQuads horizontalGlyphQuads; SymbolQuads verticalGlyphQuads; optional iconQuad; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index a41a98fcaf..26332df4a0 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -323,6 +323,7 @@ void SymbolLayout::addFeature(const std::size_t index, symbolInstances.emplace_back(anchor, line, shapedTextOrientations, shapedIcon, layout.evaluate(zoom, feature), layoutTextSize, symbolInstances.size(), + bool(feature.text), bool(feature.icon), textBoxScale, textPadding, textPlacement, textOffset, iconBoxScale, iconPadding, iconOffset, glyphPositionMap, indexedFeature, index, feature.text.value_or(std::u16string()), overscaling); @@ -428,14 +429,14 @@ std::unique_ptr SymbolLayout::place(const bool showCollisionBoxes) for (SymbolInstance &symbolInstance : bucket->symbolInstances) { - const bool hasText = symbolInstance.hasText; - const bool hasIcon = symbolInstance.hasIcon; + const bool hasTextData = symbolInstance.hasTextData; + const bool hasIconData = symbolInstance.hasIconData; const auto& feature = features.at(symbolInstance.featureIndex); // Insert final placement into collision tree and add glyphs/icons to buffers - if (hasText) { + if (hasTextData) { const Range sizeData = bucket->textSizeBinder->getVertexSizeData(feature); bucket->text.placedSymbols.emplace_back(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max, symbolInstance.textOffset, symbolInstance.writingModes, symbolInstance.line, CalculateTileDistances(symbolInstance.line, symbolInstance.anchor)); @@ -474,7 +475,7 @@ std::unique_ptr SymbolLayout::place(const bool showCollisionBoxes) } } - if (hasIcon) { + if (hasIconData) { if (symbolInstance.iconQuad) { const Range sizeData = bucket->iconSizeBinder->getVertexSizeData(feature); bucket->icon.placedSymbols.emplace_back(symbolInstance.anchor.point, symbolInstance.anchor.segment, sizeData.min, sizeData.max, diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 400fe79ac5..f8fed7f01a 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -108,8 +108,8 @@ void Placement::placeLayerBucket( continue; } - bool placeText = false; - bool placeIcon = false; + bool placeText = symbolInstance.hasText; + bool placeIcon = symbolInstance.hasIcon; bool offscreen = true; if (symbolInstance.placedTextIndex) { @@ -149,11 +149,11 @@ void Placement::placeLayerBucket( placeIcon = placeText && placeIcon; } - if (placeText) { + if (placeText && symbolInstance.hasTextData) { collisionIndex.insertFeature(symbolInstance.textCollisionFeature, bucket.layout.get()); } - if (placeIcon) { + if (placeIcon && symbolInstance.hasIconData) { collisionIndex.insertFeature(symbolInstance.iconCollisionFeature, bucket.layout.get()); } @@ -249,7 +249,7 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, std::set& seenCrossTileIDs.insert(symbolInstance.crossTileID); - if (symbolInstance.hasText) { + if (symbolInstance.hasTextData) { auto opacityVertex = SymbolOpacityAttributes::vertex(opacityState.text.placed, opacityState.text.opacity); for (size_t i = 0; i < symbolInstance.horizontalGlyphQuads.size() * 4; i++) { bucket.text.opacityVertices.emplace_back(opacityVertex); @@ -264,7 +264,7 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, std::set& bucket.text.placedSymbols[*symbolInstance.placedVerticalTextIndex].hidden = opacityState.isHidden(); } } - if (symbolInstance.hasIcon) { + if (symbolInstance.hasIconData) { auto opacityVertex = SymbolOpacityAttributes::vertex(opacityState.icon.placed, opacityState.icon.opacity); if (symbolInstance.iconQuad) { bucket.icon.opacityVertices.emplace_back(opacityVertex); diff --git a/test/text/cross_tile_symbol_index.test.cpp b/test/text/cross_tile_symbol_index.test.cpp index 794c2b59a1..dd2494bb53 100644 --- a/test/text/cross_tile_symbol_index.test.cpp +++ b/test/text/cross_tile_symbol_index.test.cpp @@ -11,7 +11,7 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) { style::SymbolLayoutProperties::Evaluated layout_; IndexedSubfeature subfeature(0, "", "", 0); Anchor anchor(x, y, 0, 0); - return {anchor, line, shaping, {}, layout_, 0, 0, 0, 0, style::SymbolPlacementType::Point, {{0, 0}}, 0, 0, {{0, 0}}, gpm, subfeature, 0, key, 0 }; + return {anchor, line, shaping, {}, layout_, 0, 0, true, false, 0, 0, style::SymbolPlacementType::Point, {{0, 0}}, 0, 0, {{0, 0}}, gpm, subfeature, 0, key, 0 }; } -- cgit v1.2.1