Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not hide icons if text is an empty string #6164

Merged
merged 2 commits into from
Feb 14, 2018
Merged

do not hide icons if text is an empty string #6164

merged 2 commits into from
Feb 14, 2018

Conversation

ansis
Copy link
Contributor

@ansis ansis commented Feb 14, 2018

fix #6160

Empty text strings do not have any collision boxes so the collision index check was never done and the text was not counted as "placed". This fixes that by making "placed" the default when the feature has text.

Alternative fix

Another possibility would be to create zero-sized collision boxes for empty strings. If we did this, should these zero-size boxes collide with other boxes if they are contained within them?

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • [N/A] document any changes to public APIs
  • [N/A] post benchmark scores
  • manually test the debug page

Empty text strings do not have any collision boxes so the collision
index check was never done and the text was not counted as "placed".
This fixes that by making "placed" the default when the feature has
text.

fix #6160
@ansis ansis requested a review from ChrisLoer February 14, 2018 17:07
@mb12
Copy link

mb12 commented Feb 14, 2018

@ansis Can you please clarify when should one use 'text-optional' and 'icon-optional' layout properties? Shouldn't this require setting text-optional to true in the corresponding style?

Copy link
Contributor

@ChrisLoer ChrisLoer left a comment

Choose a reason for hiding this comment

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

Yeah this looks right to me.

@mb12 I was confused by the same thing regarding text/icon-optional. The difference is that text-optional means "show this icon even if its corresponding text has been hidden because of a collision". It doesn't have anything to do with whether the corresponding text is defined/empty. So in this case even though the text is empty, text-optional still shouldn't be necessary (because the text isn't colliding with anything either).

@dagjomar
Copy link
Contributor

Would this also fix the inverse case, "do not hide text if icon is an empty string" ?

@ChrisLoer
Copy link
Contributor

@dagjomar Mostly I think yes... from the point of view of the code, there's nothing special about an icon-image that evaluates to an empty string: it will be just the same as any other icon-image that's not available in the sprite sheet. Here's the relevant logic:

let shapedIcon;
if (feature.icon) {
const image = imageMap[feature.icon];
if (image) {
shapedIcon = shapeIcon(
imagePositions[feature.icon],
layout.get('icon-offset').evaluate(feature),
layout.get('icon-anchor').evaluate(feature));
if (bucket.sdfIcons === undefined) {
bucket.sdfIcons = image.sdf;
} else if (bucket.sdfIcons !== image.sdf) {
warnOnce('Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer');
}
if (image.pixelRatio !== bucket.pixelRatio) {
bucket.iconsNeedLinear = true;
} else if (layout.get('icon-rotate').constantOr(1) !== 0) {
bucket.iconsNeedLinear = true;
}
}
}
if (shapedTextOrientations.horizontal || shapedIcon) {
addFeature(bucket, feature, shapedTextOrientations, shapedIcon, glyphPositionMap, sizes);
}

Along with:

let placeIcon = symbolInstance.feature.icon !== undefined;

So what that means is something like: "If the feature has an icon, but that icon's image is not in the image map, we won't create a shapedIcon and we won't add a symbol instance for just that icon. But if the same feature also has text, we'll bring the icon along for the ride, and placeIcon will default to true even though there's no collision feature for the empty icon"

@AzadehY-Dev
Copy link

hi. i have an apposite problem. when i add a text field the symbols disappear. i searched a lot and i used a lot of suggestions. but none of them didn't work for me. please help me. that's my code:
`
private void addSymbolToMap(String name, LatLng point) {
mapStyle.addImage(name, getResources().getDrawable(R.drawable.mapbox_marker_icon_default));
SymbolManager sampleSymbolManager = new SymbolManager(mapView, map, mapStyle);
sampleSymbolManager.setIconAllowOverlap(true);
sampleSymbolManager.setTextAllowOverlap(true);
sampleSymbolManager.setIconRotationAlignment(ICON_ROTATION_ALIGNMENT_VIEWPORT);
SymbolOptions sampleSymbolOptions = new SymbolOptions()
.withLatLng(point)
.withIconImage(name)
.withIconSize(1.5f);
.withTextField("test")
.withTextFont(new String[] { "Arial Unicode MS Regular"});
Symbol sampleSymbol = sampleSymbolManager.create(sampleSymbolOptions);
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol layer items disappear when text-field is an empty string
5 participants