mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

Stretchable UIImage support seems to be broken

Open avi-c opened this issue 3 years ago • 13 comments

Environment

  • Maps SDK Version: v10 beta

Observed behavior and steps to reproduce

The Nav SDK started seeing some issues with the route duration annotations being implemented here: https://github.com/mapbox/mapbox-navigation-ios/issues/2996. These issues are also seen in the simpler PR for adding a new example to the Maps SDK sample app: https://github.com/mapbox/mapbox-maps-ios/pull/190.

The issues are around the icon-anchor and text-anchor properties seeming to regress somewhere between when I first put up the sample PR and now. @nishant-karajgikar and I spent a lot of time debugging this. Our shared assumption was that the issue lay either in my use of the runtime styling expressions or in the SDK expression logic itself.

After looking at it for a while and even eliminating the use of data-driven styling, the main issues remained. We came to the conclusion that the issues are likely to be in how the SDK handles generating the GL stretchable images from the UIImage interface provided in the iOS Maps SDK.

https://github.com/mapbox/mapbox-maps-ios/pull/190 contains an animated GIF of how this should look, mainly that the annotations are clearly visually anchored properly with the tip of the annotation staying attached to the map at the same spot. If you build and try the same sample in this branch: ac-AnnotationStylingRedux you will see that the visual behavior is now incorrect and the anchors are not maintained properly.

avi-c avatar May 21 '21 17:05 avi-c

Also, the icon-offset and text-offset properties seem to be broken. it could be that only one or the other is the issue or both could have an issue.

avi-c avatar May 21 '21 18:05 avi-c

I wanted to provide an image depicting the behavior @avi-c mentioned above:

navRouteImage

ZiZasaurus avatar May 24 '21 17:05 ZiZasaurus

On the latest versions of the Maps SDK beta we are actually seeing different issues than that one, but both point to errors in the image stretching. Right now we see incorrect anchoring of the annotations. If you look at the image below you will see that the pin should be anchored on the route line but instead it is anchored further up the base/stem of the annotation. This used to work as expected in earlier betas.

Simulator Screen Shot - iPhone 11 - 2021-05-24 at 10 55 25

avi-c avatar May 24 '21 17:05 avi-c

The image that @ZiZasaurus posted above shows the weird shaped annotations because the image is being stretched at the wrong pixel offset into the original asset, so the stem portion is being stretched when only the middle should be.

avi-c avatar May 24 '21 17:05 avi-c

The primary issue is that when using iconTextFit, the textAnchor takes precedence and overrides the iconAnchor. On top of that, some of the expressions didn't seem to be working as expected. I think mapView.mapboxMap.style.addLayer(shapeLayer) was probably throwing but it was an optional try so it was being swallowed.

cmilack avatar Jul 16 '21 18:07 cmilack

This is also impacting https://github.com/mapbox/mapbox-navigation-ios/pull/3177.

/cc: @knov

zugaldia avatar Jul 20 '21 20:07 zugaldia

I find that the problem is related with the sequence of addLayer and the expression. When the expression is used to style the iconAnchor and iconOffset after we add the layer, they're not working as following: ExpressionAfterAddLayer

But when we do it before adding the layer, it's working as expected. ExpressionStyling

So it seems that right now the SymbolLayer doesn't support the expression styling to a layer already added.

ShanMa1991 avatar Jul 20 '21 20:07 ShanMa1991

As per https://github.com/mapbox/mapbox-maps-ios/pull/548

This turned out to be expected behavior when using both icon-anchor and icon-text-fit.

evil159 avatar Apr 20 '22 20:04 evil159

Reopening as there seems to be more to it

evil159 avatar Apr 20 '22 20:04 evil159

Closing as stale anyway.

evil159 avatar May 02 '22 15:05 evil159

But does it still occur?

avi-c avatar May 02 '22 15:05 avi-c

This turned out to be expected behavior when using both icon-anchor and icon-text-fit.

@cmilack @evil159 I think it’s a bit more nuanced than that. As https://github.com/mapbox/mapbox-maps-ios/issues/381#issuecomment-883699210 shows, the developer basically has a choice between anchoring the symbol on the correct location (resulting in a misshapen icon) or stretching the correct portion of the icon (resulting in a misplaced icon), but not both. I think this is suboptimal for the use case of displaying a 💬-like symbol. If that is no longer one of the intended use cases for icon-text-fit, text-anchor, and stretchable images, then we’d need to go back to the drawing board.

1ec5 avatar May 09 '22 19:05 1ec5

Confirmed that the issue still reproduces: https://github.com/mapbox/mapbox-navigation-ios/pull/2928#issuecomment-1129249034.

1ec5 avatar May 17 '22 19:05 1ec5