diff options
author | Ansis Brammanis <ansis.brammanis@gmail.com> | 2018-01-08 12:57:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 12:57:03 -0500 |
commit | feab36a9fbc5162150de8c3e26df8585b1430318 (patch) | |
tree | 3cb44b5fc7b1679ce5cfa502413db1540c4cccdb /src/mbgl/text | |
parent | f86c1b7d0f440b7cf0da72a3c0940715f97d709e (diff) | |
download | qtlocation-mapboxgl-feab36a9fbc5162150de8c3e26df8585b1430318.tar.gz |
[core] port minor collision changes from -js (#10764)
Diffstat (limited to 'src/mbgl/text')
-rw-r--r-- | src/mbgl/text/cross_tile_symbol_index.cpp | 66 | ||||
-rw-r--r-- | src/mbgl/text/cross_tile_symbol_index.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/text/placement.cpp | 7 |
3 files changed, 35 insertions, 42 deletions
diff --git a/src/mbgl/text/cross_tile_symbol_index.cpp b/src/mbgl/text/cross_tile_symbol_index.cpp index 177615857f..6efded8e4a 100644 --- a/src/mbgl/text/cross_tile_symbol_index.cpp +++ b/src/mbgl/text/cross_tile_symbol_index.cpp @@ -57,50 +57,35 @@ void TileLayerIndex::findMatches(std::vector<SymbolInstance>& symbolInstances, c CrossTileSymbolLayerIndex::CrossTileSymbolLayerIndex() { } -void CrossTileSymbolLayerIndex::addBucket(const OverscaledTileID& coord, SymbolBucket& bucket, uint32_t& maxCrossTileID) { - if (bucket.bucketInstanceId) return; - bucket.bucketInstanceId = ++maxBucketInstanceId; - - uint8_t minZoom = 25; - uint8_t maxZoom = 0; - for (auto& it : indexes) { - auto z = it.first; - minZoom = std::min(minZoom, z); - maxZoom = std::max(maxZoom, z); +bool CrossTileSymbolLayerIndex::addBucket(const OverscaledTileID& tileID, SymbolBucket& bucket, uint32_t& maxCrossTileID) { + auto thisZoomIndexes = indexes[tileID.overscaledZ]; + auto previousIndex = thisZoomIndexes.find(tileID); + if (previousIndex != thisZoomIndexes.end() && previousIndex->second.bucketInstanceId == bucket.bucketInstanceId) { + return false; } + for (auto& symbolInstance: bucket.symbolInstances) { + symbolInstance.crossTileID = 0; + } - // make all higher-res child tiles block duplicate labels in this tile - for (auto z = maxZoom; z > coord.overscaledZ; z--) { - auto zoomIndexes = indexes.find(z); - if (zoomIndexes != indexes.end()) { - for (auto& childIndex : zoomIndexes->second) { - if (!childIndex.second.coord.isChildOf(coord)) { - continue; + for (auto& it : indexes) { + auto zoom = it.first; + auto zoomIndexes = it.second; + if (zoom > tileID.overscaledZ) { + for (auto& childIndex : zoomIndexes) { + if (childIndex.second.coord.isChildOf(tileID)) { + childIndex.second.findMatches(bucket.symbolInstances, tileID); } - childIndex.second.findMatches(bucket.symbolInstances, coord); } - } - if (z == 0) { - break; - } - } - - // make this tile block duplicate labels in lower-res parent tiles - for (auto z = coord.overscaledZ; z >= minZoom; z--) { - auto parentCoord = coord.scaledTo(z); - auto zoomIndexes = indexes.find(z); - if (zoomIndexes != indexes.end()) { - auto parentIndex = zoomIndexes->second.find(parentCoord); - if (parentIndex != zoomIndexes->second.end()) { - parentIndex->second.findMatches(bucket.symbolInstances, coord); + } else { + auto parentTileID = tileID.scaledTo(zoom); + auto parentIndex = zoomIndexes.find(parentTileID); + if (parentIndex != zoomIndexes.end()) { + parentIndex->second.findMatches(bucket.symbolInstances, tileID); } } - if (z == 0) { - break; - } } - + for (auto& symbolInstance : bucket.symbolInstances) { if (!symbolInstance.crossTileID) { // symbol did not match any known symbol, assign a new id @@ -108,7 +93,8 @@ void CrossTileSymbolLayerIndex::addBucket(const OverscaledTileID& coord, SymbolB } } - indexes[coord.overscaledZ].emplace(coord, TileLayerIndex(coord, bucket.symbolInstances, bucket.bucketInstanceId)); + indexes[tileID.overscaledZ].emplace(tileID, TileLayerIndex(tileID, bucket.symbolInstances, bucket.bucketInstanceId)); + return true; } bool CrossTileSymbolLayerIndex::removeStaleBuckets(const std::unordered_set<uint32_t>& currentIDs) { @@ -145,9 +131,11 @@ bool CrossTileSymbolIndex::addLayer(RenderSymbolLayer& symbolLayer) { SymbolBucket& symbolBucket = *reinterpret_cast<SymbolBucket*>(bucket); if (!symbolBucket.bucketInstanceId) { - symbolBucketsChanged = true; + symbolBucket.bucketInstanceId = ++maxBucketInstanceId; } - layerIndex.addBucket(renderTile.tile.id, symbolBucket, maxCrossTileID); + + const bool bucketAdded = layerIndex.addBucket(renderTile.tile.id, symbolBucket, maxCrossTileID); + symbolBucketsChanged = symbolBucketsChanged || bucketAdded; currentBucketIDs.insert(symbolBucket.bucketInstanceId); } diff --git a/src/mbgl/text/cross_tile_symbol_index.hpp b/src/mbgl/text/cross_tile_symbol_index.hpp index c67cd37e00..995e0061b9 100644 --- a/src/mbgl/text/cross_tile_symbol_index.hpp +++ b/src/mbgl/text/cross_tile_symbol_index.hpp @@ -42,11 +42,10 @@ public: class CrossTileSymbolLayerIndex { public: CrossTileSymbolLayerIndex(); - void addBucket(const OverscaledTileID&, SymbolBucket&, uint32_t& maxCrossTileID); + bool addBucket(const OverscaledTileID&, SymbolBucket&, uint32_t& maxCrossTileID); bool removeStaleBuckets(const std::unordered_set<uint32_t>& currentIDs); private: std::map<uint8_t,std::map<OverscaledTileID,TileLayerIndex>> indexes; - uint32_t maxBucketInstanceId = 0; }; class CrossTileSymbolIndex { @@ -59,6 +58,7 @@ public: private: std::map<std::string, CrossTileSymbolLayerIndex> layerIndexes; uint32_t maxCrossTileID = 0; + uint32_t maxBucketInstanceId = 0; }; } // namespace mbgl diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index b27d8f5baf..84e53f74eb 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -228,10 +228,15 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, std::set<uint32_t>& if (bucket.hasCollisionBoxData()) bucket.collisionBox.dynamicVertices.clear(); if (bucket.hasCollisionCircleData()) bucket.collisionCircle.dynamicVertices.clear(); + JointOpacityState defaultOpacityState( + bucket.layout.get<style::TextAllowOverlap>(), + bucket.layout.get<style::IconAllowOverlap>(), + true); + for (SymbolInstance& symbolInstance : bucket.symbolInstances) { auto opacityState = seenCrossTileIDs.count(symbolInstance.crossTileID) == 0 ? getOpacity(symbolInstance.crossTileID) : - JointOpacityState(false, false, false); + defaultOpacityState; seenCrossTileIDs.insert(symbolInstance.crossTileID); |