-
Notifications
You must be signed in to change notification settings - Fork 1.3k
symbolSortKey does not equally sort icon and text #15964
Comments
Thanks for the report @johnnewman. This probably has the same root cause as mapbox/mapbox-gl-js#8896. |
@ansis @chloekraw I am still able to reproduce this issue using the sample project with the Mapbox iOS SDK v5.5.1. For the two features in the sample, the only way I can get the red feature's text to draw above the blue feature is by setting the My goal is for both the icon and text to be prioritized based upon the
ConfigurationMapbox SDK versions: 5.5.1 |
@johnnewman thanks for the comment.
I'm not sure if you misspoke here, but A few follow-up questions:
|
@chloekraw Thank you for your quick response. Getting the red feature's text to draw over the blue feature with
layer.text = NSExpression(forKeyPath: "text")
layer.iconImageName = NSExpression(forKeyPath: "icon")
layer.textAnchor = NSExpression(forConstantValue: NSValue(mglTextAnchor: .left))
layer.textJustification = NSExpression(forConstantValue: NSValue(mglTextJustification: .left))
layer.textColor = NSExpression(forConstantValue: UIColor.black)
layer.textAllowsOverlap = NSExpression(forConstantValue: NSNumber(value: false))
layer.iconAllowsOverlap = NSExpression(forConstantValue: NSNumber(value: true))
layer.textOptional = NSExpression(forConstantValue: NSNumber(value: true))
layer.textFontSize = NSExpression(forConstantValue: NSNumber(value: 13))
layer.textOffset = NSExpression(forConstantValue: NSValue(cgVector: CGVector.init(dx: 1, dy: 0)))
layer.symbolSortKey = symbolSortKeyExpression()
/// Our goal is to get the red pin (sort 100) to appear above the blue pin (sort 0).
/// Since the red is on top, we also want the red pin's text to draw at the same z-level.
private func symbolSortKeyExpression() -> NSExpression {
// Red icon on top; blue text appears
return NSExpression(forKeyPath: "sort")
// Blue icon on top; red text appears
// return NSExpression(forFunction: "multiply:by:", arguments: [NSExpression(forKeyPath: "sort"), NSExpression(forConstantValue: -1)])
}
|
@johnnewman I see. Unfortunately, This is because when symbols are not allowed to overlap, symbols placed first cause subsequent symbols to be hidden due to collision detection. In contrast, symbols placed first when overlap is enabled are underneath symbols placed later. This is a reflection of how the renderer behaves and we understand it's suboptimal; however, it cannot be easily changed. We would like to investigate rewriting our shaders, placement logic, etc. in a way that may enable a future refactor of |
Thank you for the insight @chloekraw. Even though this refactor isn't prioritized at the moment, would it be possible to reopen this ticket so that we have something to track? |
@johnnewman sure, I've opened a ticket here to track: mapbox/mapbox-gl-js#9368 |
When using MGLSymbolStyleLayer's
symbolSortKey
expression withtextAllowsOverlap
as false, text collisions cause the lower-sort features to take priority. Features with a lower sort will draw their text and cause features of a higher sort to hide theirs.Steps to reproduce
icon
andtext
properties.textOptional
to true,iconAllowsOverlap
to true, andtextAllowsOverlap
to false.Expected behavior
When the features collide:
Actual behavior
The icons are at the correct z-level, but the lower-sort feature's text has caused the higher-sort feature's text to hide.
The attached zip contains a sample Xcode project that demonstrates this issue. You'll just need to run a pod install and supply an API token in the app delegate. The output of the project is captured in the screenshot below. The red feature has a higher sort value, but its text is hidden.
TextLayeringProject.zip
If I reverse the
sort
values by multiplying them all by -1, then the red icon appears with its text, but both the text and the icon are drawn below the now higher blue icon:Configuration
Mapbox SDK versions: 5.4.0
iOS/macOS versions: 13.2.2
Device/simulator models: 11
Xcode version: 11.2.1
The text was updated successfully, but these errors were encountered: