From cacbad952fef30af5227c3a533b88e1cb34505f9 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Tue, 25 Apr 2017 16:14:35 -0700 Subject: [PATCH] Calculate line collision boxes over a wider range to account for label expansion in the distance. --- src/symbol/collision_feature.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/symbol/collision_feature.js b/src/symbol/collision_feature.js index b9be1f03718..48c6ab05aee 100644 --- a/src/symbol/collision_feature.js +++ b/src/symbol/collision_feature.js @@ -1,5 +1,10 @@ 'use strict'; +// We calculate line collision boxes out to 150% of what would normally be our +// max size, to allow collision detection to work on labels that expand as +// they move into the distance +const pitchExpansionFactor = 1.5; + /** * A CollisionFeature represents the area of the tile covered by a single label. * It is used with CollisionTile to check if the label overlaps with any @@ -32,7 +37,7 @@ class CollisionFeature { if (alignLine) { let height = y2 - y1; - const length = x2 - x1; + const length = (x2 - x1) * pitchExpansionFactor; if (height > 0) { // set minimum box height to avoid very many small labels @@ -120,7 +125,7 @@ class CollisionFeature { const boxAnchorPoint = p1.sub(p0)._unit()._mult(segmentBoxDistance)._add(p0)._round(); const distanceToInnerEdge = Math.max(Math.abs(boxDistanceToAnchor - firstBoxOffset) - step / 2, 0); - const maxScale = labelLength / 2 / distanceToInnerEdge; + const maxScale = labelLength / 2 / distanceToInnerEdge / pitchExpansionFactor; collisionBoxArray.emplaceBack(boxAnchorPoint.x, boxAnchorPoint.y, -boxSize / 2, -boxSize / 2, boxSize / 2, boxSize / 2, maxScale,