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

Webp Tiles Appear with a black boarder

Open paulsUsername opened this issue 1 year ago • 10 comments

Webp tiles with transparent tiles are presented with a black boarder on the iOS app. They look fine in GL JS, but on the iOS SDK they have a large black boarder.

Any solution to this?

paulsUsername avatar Jan 23 '24 20:01 paulsUsername

Hey @paulsUsername Can you provide a sample code to reproduce the issue and name the SDK version

OdNairy avatar Jan 25 '24 13:01 OdNairy

Hey!

Would you expect that the iOS SDK should support transparency from WebP tiles?

The tile format we uploaded to Mapbox studio was WebP. Interestingly, if we upload in PNG format we don't have the issue.

So here is a screenshot from Mapbox studio of the map with transparency:

Screenshot 2024-01-25 at 13 44 50

Below is the style URL:

mapbox://styles/hiiker-mapbox/clrqlal5u00c501pl7wm0b02g (public)

Code to add to map (v11.1.0):

class ViewController: UIViewController {
    
    internal var mapView: MapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let centerCoordinate = CLLocationCoordinate2D(latitude: 53.5, longitude: -7.5)
        let camera = CameraOptions(
            center: centerCoordinate,
            zoom: 5
        )
        let options = MapInitOptions(
            cameraOptions: camera,
            styleURI: StyleURI(
                rawValue: "mapbox://styles/hiiker-mapbox/clrqlal5u00c501pl7wm0b02g"
            )
        )
        
        mapView = MapView(frame: view.bounds, mapInitOptions: options)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        
        view.addSubview(mapView)
    }
}

Screenshot results from the app:

IMG_07EB06C910AC-1

paulsUsername avatar Jan 25 '24 13:01 paulsUsername

WebP isn’t supported on iOS; you’re actually looking at a PNG the server returned instead.

mapbox/mapbox-gl-native#5856

1ec5 avatar Jan 25 '24 15:01 1ec5

@1ec5 One alternative is to use the static tiles API, but would I be correct in saying that you cannot download static tiles (due to lack of mapbox:// URL)?

paulsUsername avatar Jan 25 '24 15:01 paulsUsername

But also just for full clarity for anyone else, given the correct tileset in a style (i.e. not a webp one) the iOS SDK does support transparency:

IMG_2025

paulsUsername avatar Jan 25 '24 16:01 paulsUsername

WebP isn’t supported on iOS; you’re actually looking at a PNG the server returned instead.

iOS platform support WebP images since iOS 14. I was able to manually add WebP with an alpha channel with a transparent background. I've used that sample. IMG_0001

Unfortunately, I've received 404 errors with @paulsUsername sample code.

OdNairy avatar Jan 26 '24 08:01 OdNairy

Is that an image source connected to a server-side upload? Does the Raster Tiles API return WebP these days for iOS or just PNG? At least at one point, it used to return PNG because of missing WebP support on iOS.

1ec5 avatar Jan 26 '24 15:01 1ec5

@1ec5 So if you are using the raster tiles API you can explicitly set the type (i.e. webp, png, png8) but when it is a mapbox scheme style, I don't know how to check (even the tile URLs are just mapbox://).

When using the style on the gl js framework, it does return webps as part of the style.

But the very strange thing is, If I upload my data to mapbox studio as PNGs it works perfectly with transparency. But if I upload a webp tileset (and add it to a style) transparency on the app does not work.

We have created a work around but uploading tilesets that are a mix of png and jpeg (which seems to cause no issues). Where there is transparency we leave the tile as a PNG, where there is no transparency we convert to JPEG.

So you get the benefit of small uploadable tilesets and pretty much all of the benefit of WebP (reduced file size).

That looks to me like @OdNairy added that image locally rather than returning through the server.

paulsUsername avatar Jan 26 '24 15:01 paulsUsername

@paulsUsername yep, I've added a local WebP to check if renderer supports WebP format in general. However, @1ec5 is right, and server converts WebP into PNG (JPEG?). I recommend you stick to the workaround you've found already while we investigate the actual WebP support.

OdNairy avatar Jan 26 '24 19:01 OdNairy

Oh yeah, it’s probably JPEG, now that you mention it. That sounds like a neat workaround by the way.

1ec5 avatar Jan 26 '24 19:01 1ec5