mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.35k stars 1.33k forks source link

[Android] - Offline region download [HTTP] Request with response = 422: Unknown #16486

Closed nstele closed 3 years ago

nstele commented 4 years ago

I've recently changed the Tile URL that I use and looks like this:

"tiles": [ "https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/512/{z}/{x}/{y}?access_token=TOKEN_VALUE"]

When I try to attemp to download a region I got this:

D/Mbgl-HttpRequest: [HTTP] Request with response = 422: Unknown

Before this change I was able to download the same region without any problem. Also I've changed the tile set size to 256 and get the same result.

Platform: Android and iOS Mapbox SDK version: 8.2.0 for Android and latest version for iOS

Steps to trigger behavior

  1. Change the tile set URL for Mapbox satellite and Mapbox Open Street to latest versions
  2. Try to download an offline region
  3. Get HTTP response 422

Expected behavior

Download the offline region (previouly working with old tile set)

Actual behavior

The download fails and return HTTP 422

nstele commented 4 years ago

@tobrun this is urgent since the tiles set will be deprecated on 6/1

tobrun commented 4 years ago

@nstele it seems you have a custom style definition? If you want to download an offline region with one of our predefined styles you can use Style.MAPBOX_STREETS instead (you aren't required to setup any tilesize etc.).

nstele commented 4 years ago

@shivani-patel23 @chloekraw @tobrun I'm using a custom style, the only change I've made since I use this custom style is the way to define the sources for this layer:

Before:

"mb_satellite_streets": {
      "type": "raster",
      "url": "mapbox://mapbox.streets-satellite",
      "tileSize": 256
    },

Now:

"sources": {
    "mb_satellite_streets": {
      "type": "raster",
      "tiles": [
        "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=MY_TOKEN"
      ],
      "tileSize": 512
    },

When I work with the map I can display the layers without problems, but when I try to download this style I get D/Mbgl-HttpRequest: [HTTP] Request with response = 422: Unknown

More info:

https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/512/15/7389/13327?access_token=API_KEY&offline=true

This is the URL that the SDK is trying to use the tiles and the API returns:

{
message: "Invalid query param offline"
}

Other test I've made and I can't display the layers in the map and neither download:

My json style:

 "layers": [
    {
      "id": "mb_satellite_streets",
      "type": "raster",
      "source": "mb_satellite_streets",
      "layout": {
        "visibility": "visible"
      }
    },

    "sources": {
    "mb_satellite_streets": {
      "type": "raster",
      "url": "mapbox://styles/mapbox/satellite-v11",
      "tileSize": 512
    },
**D/Mbgl-HttpRequest: [HTTP] Cancel request https://api.mapbox.com/v4/styles.json?access_token=API_TOKEN&secure&sku=SKU**

E/Mbgl: {OnlineFileSourc}[General]: The resource https://api.mapbox.com/v4/styles.json not found E/Mbgl: {android.staging}[Style]: Failed to load source mb_satellite_streets: HTTP status code 404

shabnomnom commented 4 years ago

@nstele just want to summarize you are seeing 422 error because the SDK is appending the offline=true to the end of your URL and that was not happening with the classic style?

I also noticed on your last test the correct URL is : mapbox://styles/mapbox/satellite-streets-v11 rather than mapbox://styles/mapbox/satellite-v11. Are you still getting an error with the correct URL?

nstele commented 4 years ago

@shabnomnom

  1. Raster classic style we are currently using in production:

    "sources": {
     "mb_satellite_streets": {
     "type": "raster",
     **"url": "mapbox://mapbox.streets-satellite",**
     "tileSize": 256
    }
    }

    Results: works ok, I can display the maps with all styles and also download maps. Those are the styles that you are going to deprecated.

  2. First approach was change the url for

    "sources": {
    "mb_satellite_streets": {
      "type": "raster",
      **"url": "mapbox://styles/mapbox/satellite-v11",**
      "tileSize": 512
    },   

Results: I can't display Satellites Style in map, (map shows a black background) despite other layers can be displayed without any problems. These are the error that I can see in the console:

Load style from JSON:

D/Mbgl-HttpRequest: [HTTP] Request with response = 404: Not Found
D/Mbgl-HttpRequest: [HTTP] Cancel request https://api.mapbox.com/v4/styles.json?access_token=MY_TOKEN&secure&sku=SKU
E/Mbgl: {OnlineFileSourc}[General]: The resource `https://api.mapbox.com/v4/styles.json` not found
E/Mbgl: {android.staging}[Style]: Failed to load source mb_satellite_streets: HTTP status code 404

When try to download:

D/Mbgl-HttpRequest: [HTTP] Request with response = 404: Not Found
D/Mbgl-HttpRequest: [HTTP] Cancel request https://api.mapbox.com/v4/styles.json?access_token=MY_API_TOKEN&offline=true
E/Mbgl: {OnlineFileSourc}[General]: The resource `https://api.mapbox.com/v4/styles.json` not found
E/Mbgl: {android.staging}[Style]: Failed to load source mb_satellite_streets: HTTP status code 404
  1. Last approach was use this URL and format for sources:
"sources": {
    "mb_satellite_streets": {
      "type": "raster",
      "tiles": [
        "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=MY_TOKEN"
      ],
      "tileSize": 512
    },

Results: I can display the style for satellite without problems but when I try to download the map I get 422

Let me know if you needs more info about it

nstele commented 4 years ago

@shabnomnom @shivani-patel23 @chloekraw any news about this?

shabnomnom commented 4 years ago

@nstele I see that you are mentioning that you want to download a custom style, but in your first approach, you are referring to the mapbox satellite layer like so: mapbox://styles/mapbox/satellite-v11.

  1. Is this layer only a place holder for your custom layer?

  2. if you just want to load Mapbox satellite layer, you can use the following URL: URL:mapbox://styles/mapbox/satellite-v9 or continue using mapbox.satellites with the /v4/ endpoint since that raster tileset is not deprecating.

  3. In order to confirm if this issue is only happening with our raster layer, would you also check if you are getting the same error when loading vector style such as: mapbox.com/styles/v1/mapbox/streets-v11/tiles/1/1/0? ?

nstele commented 4 years ago

@shabnomnom the custom style is composed by other layers, but as base layer we use satellites, open street, etc raster layers.

So if you combine our layers with Satellites or Open Streets new sources, we get the result described above.

  1. Mapbox Satellite Style is used as Base Layer of our custom style.

  2. I've tried with mapbox://styles/mapbox/satellite-v9, mapbox://styles/mapbox/satellite-v10 and mapbox://styles/mapbox/satellite-v11 and we have the same problem, the style is not loaded in our map, the rest of the layers added in our custom style are been displayed ok. About using mapbox.satellites with the /v4/ endpoint since that raster tileset , is not possible since we use the style that includes the streets and routes also and V4 endpoint doesn't have that.

  3. About vector satellite style is not working it display black layer.

@shabnomnom for us would be really good if you could fix the problem that the API returns 422 when we try to download the tiles from this URL: "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=MY_TOKEN"

shabnomnom commented 3 years ago

@nstele the Static Tile API team was able to resolve the 422 error caused by offline=true parameter, so you should be unblocked here.

However, a better implimentation is using Vector Tiles API and Raster Tiles API instead of the Static TIle API. If you have not done this already, use the Vector Tiles API for your vector layers and the Raster Tiles API for your raster layers. Especially because the requests from Vector Tiles API and Raster Tiles API are included in the cost of their MAUs/SDK usage. Please reach out to the Mapbox support if you have any implimentation/pricing specific questions.