Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] fix collisions with icon-text-fit and variable placement #15828

Merged
merged 5 commits into from
Oct 23, 2019

Conversation

ansis
Copy link
Contributor

@ansis ansis commented Oct 17, 2019

port https://github.com/mapbox/mapbox-gl-js/pull/8803/files

When deciding the placement position it was only checking whether there were text collisions. If there was an icon collision then it would hide the icon (and by default, the text with it) instead of trying a different position.

If icon-text-fit is used it now checks whether the icon fits before accepting a placement position.

const auto placeFeatureForVariableAnchors = [&] (const CollisionFeature& collisionFeature, style::TextWritingModeType orientation) {
const bool doVariableIconPlacement = hasIconTextFit && !iconAllowOverlap && symbolInstance.placedIconIndex;

const auto placeFeatureForVariableAnchors = [&] (const CollisionFeature& collisionFeature, style::TextWritingModeType orientation, const CollisionFeature& iconCollisionFeature) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/collisionFeature/textCollisionFeature ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, changed!

@@ -329,6 +331,15 @@ void Placement::placeBucket(
allowOverlap,
pitchWithMap,
params.showCollisionBoxes, avoidEdges, collisionGroup.second, textBoxes);

if (doVariableIconPlacement) {
auto placedIconFeature = collisionIndex.placeFeature(iconCollisionFeature, shift,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need to call placedFeature = collisionIndex.placeFeature(.. above? wouldn't just one placeFeature() call suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case there is negative icon padding (or an icon offset?) the text box might be larger than the icon box. Placing both is the clearest way to handle the possible differences

@ansis ansis force-pushed the icon-text-fit-variable-placement branch from 70c3e0e to a85187a Compare October 22, 2019 18:48
@ansis ansis force-pushed the icon-text-fit-variable-placement branch from a85187a to 0fe6136 Compare October 22, 2019 21:31
@ansis ansis merged commit 99feb9b into master Oct 23, 2019
@ansis ansis deleted the icon-text-fit-variable-placement branch October 23, 2019 00:30
springmeyer pushed a commit that referenced this pull request Oct 24, 2019
springmeyer pushed a commit that referenced this pull request Oct 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants