maplibre / maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
https://maplibre.org
BSD 2-Clause "Simplified" License
1.02k stars 298 forks source link

Adding @2x to raster-dem source #2717

Closed michalgwo closed 1 month ago

michalgwo commented 1 month ago

Describe the bug When I try to use raster-dem type source, maplibre automatically adds @2x to link, which causes 404 error when the source doesn't support higher resolution source. For example MapTiler's outdoor style (https://api.maptiler.com/maps/outdoor-v2/style.json?key=xxx - to see the style you need API key, which you can get for free on https://www.maptiler.com/) has terrain-rgb source

"terrain-rgb":{
    "url":"https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=xxx",
    "type":"raster-dem"
    }
}

When I use this style in my app, it doesn't show any layer from this source and logs:

[HTTP] This request was cancelled (https://api.maptiler.com/tiles/terrain-rgb-v2/12/2302/1399@2x.webp?key=xxx). This is expected for tiles that were being prefetched but are no longer needed for the map to render.
[HTTP] Request with response = 404: No additional information

The 404 error happens because maptiler added @2x to link before .webp what makes requests to non-existent url.

To Reproduce Steps to reproduce the behavior:

  1. Create Android app with MapTiler's outdoor style (https://api.maptiler.com/maps/outdoor-v2/style.json?key=xxx - to use the style you need API key, which you can get for free on https://www.maptiler.com/)
  2. See that the app doesn't show hillshade
  3. Look at the log that the url is changed

Expected behavior Don't add @2x by default and/or make an option to toggle it.

Platform information (please complete the following information):

louwers commented 1 month ago

Unable to reproduce with version 11.1.0 (although there shouldn't be any difference) and Raster DEM data gets loaded with MapTiler outdoor as expected.

The @2x should only get added when the style has support for it (when the URL includes {ratio}).

https://github.com/maplibre/maplibre-native/blob/main/src/mbgl/storage/resource.cpp#L113

michalgwo commented 1 month ago

I investigated this issue further, and it works on 11.1.0 (regardless of configuration, I will explain below). I forgot to mention that I was using the 10.2.0 version of MapLibre. For those who want to stick with the older version, I also figured out that the problem occurs only when I get the instance of Mapbox with all 3 parameters:

Mapbox.getInstance(this, "xxx", WellKnownTileServer.MapTiler)

But, when I skip apiKey and tileServer, everything works perfectly:

Mapbox.getInstance(this)
louwers commented 1 month ago

Thanks for sharing your solution.