Issue with fetching a custom tileset from CARTO and displaying it on a MapBox map iOS Swift

172 views Asked by At

I'm attempting to fetch a custom tileset from CARTO using the documentation I found that the way to fetch from the API doc is:

curl --location --request GET 'https://gcp-us-east1.api.carto.com/v3/maps/carto_dw/tileset?name=carto-demo-data.demo_tilesets.nasadem_glo_quadgrid15' --header 'Authorization: Bearer <your access token>'

I made that request on Swift as follows:

{
    let urlString = "\(environment.apiBaseURL)/v3/maps/\(environment.connection)/tileset"
    return Future<CartoTileJsonResponse, Error> { [weak self] promise in
        self?.session
            .request(urlString,
                     method: .get,
                     parameters: ["name": tileSetName]
            )
            .validate()
            .responseData(completionHandler: { response in
                if let error = response.error {
                    promise(.failure(error))
                    return
                }
                
                guard let data = response.value else {
                    promise(.failure(response.error ?? NSError(domain: "unknow error", code: 999, userInfo: nil)))
                    return
                }
                
                do {
                    let cartoTileJsonResponse = try JSONDecoder().decode(CartoTileJsonResponse.self, from: data)
                    promise(.success(cartoTileJsonResponse))
                } catch(let error) {
                    debugPrint(error)
                    promise(.failure(error))
                }
            })
    }
}

As the name of the function says this return a new URL which I also make a GET request which finally returns a tilejson as shown:

    {
   "name": "NiallsFarm_Tileset_1_NDVI",
   "tilejson": "3.1.0",
   "center": [
      -2.637422918924969,
      55.96538584577466,
      15
   ],
   "description": "",
   "maxzoom": 15,
   "tilestats": {
      "layers": [
         {
            "layer": "default",
            "attributeCount": 2,
            "count": 22146,
            "geometry": "Polygon",
            "attributes": [
               {
                  "type": "String",
                  "attribute": "fieldName",
                  "categories": [
                     {
                        "category": "South Tempriggs",
                        "frequency": 7587
                     },
                     {
                        "category": "Kirklands",
                        "frequency": 6603
                     },
                     {
                        "category": "East Lothian",
                        "frequency": 4677
                     },
                     {
                        "category": "Crumstanes",
                        "frequency": 3279
                     }
                  ]
               },
               {
                  "quantiles": {
                     "3": [
                        0.5691,
                        0.658
                     ],
                     "4": [
                        0.5328,
                        0.6307,
                        0.6627
                     ],
                     "5": [
                        0.5112,
                        0.5942,
                        0.6515,
                        0.6658
                     ],
                     "6": [
                        0.5004,
                        0.5699,
                        0.6307,
                        0.6578,
                        0.6675
                     ],
                     "7": [
                        0.4899,
                        0.5509,
                        0.6055,
                        0.6464,
                        0.6604,
                        0.6689
                     ],
                     "8": [
                        0.4824,
                        0.5344,
                        0.5841,
                        0.6303,
                        0.6545,
                        0.6627,
                        0.6697
                     ],
                     "9": [
                        0.4768,
                        0.5212,
                        0.5705,
                        0.6123,
                        0.6436,
                        0.6576,
                        0.6646,
                        0.6705
                     ],
                     "10": [
                        0.4708,
                        0.5112,
                        0.5574,
                        0.5937,
                        0.6303,
                        0.6516,
                        0.6596,
                        0.6657,
                        0.6712
                     ],
                     "11": [
                        0.4674,
                        0.504,
                        0.5447,
                        0.5801,
                        0.6151,
                        0.6413,
                        0.6555,
                        0.6613,
                        0.6666,
                        0.6718
                     ],
                     "13": [
                        0.4594,
                        0.4931,
                        0.5235,
                        0.5607,
                        0.5872,
                        0.617,
                        0.6401,
                        0.6534,
                        0.6591,
                        0.6641,
                        0.6682,
                        0.6726
                     ],
                     "14": [
                        0.4542,
                        0.4899,
                        0.5164,
                        0.5502,
                        0.5779,
                        0.6048,
                        0.6303,
                        0.6468,
                        0.6559,
                        0.6606,
                        0.665,
                        0.6688,
                        0.6731
                     ],
                     "15": [
                        0.4514,
                        0.4866,
                        0.5112,
                        0.541,
                        0.5705,
                        0.5937,
                        0.6192,
                        0.6387,
                        0.6516,
                        0.6576,
                        0.6617,
                        0.6657,
                        0.6693,
                        0.6732
                     ],
                     "16": [
                        0.4496,
                        0.4824,
                        0.5052,
                        0.5344,
                        0.5626,
                        0.5841,
                        0.6089,
                        0.6303,
                        0.6448,
                        0.6545,
                        0.6588,
                        0.6627,
                        0.6663,
                        0.6697,
                        0.6736
                     ],
                     "17": [
                        0.4451,
                        0.4792,
                        0.5026,
                        0.5263,
                        0.5538,
                        0.5767,
                        0.5977,
                        0.6207,
                        0.6381,
                        0.6504,
                        0.6562,
                        0.66,
                        0.6637,
                        0.6669,
                        0.6702,
                        0.6738
                     ],
                     "18": [
                        0.4417,
                        0.476,
                        0.499,
                        0.521,
                        0.547,
                        0.571,
                        0.5885,
                        0.612,
                        0.6304,
                        0.6434,
                        0.6531,
                        0.6578,
                        0.6609,
                        0.6646,
                        0.6675,
                        0.6706,
                        0.674
                     ],
                     "19": [
                        0.4394,
                        0.4729,
                        0.4952,
                        0.5154,
                        0.5407,
                        0.5643,
                        0.5821,
                        0.6018,
                        0.6226,
                        0.6372,
                        0.6483,
                        0.6551,
                        0.6587,
                        0.662,
                        0.6653,
                        0.668,
                        0.6709,
                        0.6742
                     ],
                     "20": [
                        0.4366,
                        0.4708,
                        0.4921,
                        0.5112,
                        0.5341,
                        0.5575,
                        0.576,
                        0.5941,
                        0.6135,
                        0.6304,
                        0.6423,
                        0.6521,
                        0.6564,
                        0.6596,
                        0.6627,
                        0.6658,
                        0.6684,
                        0.6712,
                        0.6744
                     ],
                     "12We ": [
                        0.4622,
                        0.4983,
                        0.5344,
                        0.5705,
                        0.6005,
                        0.6303,
                        0.649,
                        0.6576,
                        0.6627,
                        0.6675,
                        0.6722
                     ]
                  },
                  "attribute": "NDVI",
                  "min": 0.2076,
                  "avg": 0.5944896234082888,
                  "type": "Number",
                  "max": 0.6885,
                  "sum": "13165.56719999999999590190036258263717172608"
               }
            ]
         }
      ],
      "layerCount": 1
   },
   "tiles": [
      "https://gcp-us-east1.api.carto.com/v3/maps/omegacrop-production/tileset/{z}/{x}/{y}?name={NAME}&partition=12_15_16142_16145_10208_10211_3999_1&formatTiles=mvt&cache=1653383237150&access_token={ACCES_TOKEN}"
   ],
   "minzoom": 12,
   "attribution": "",
   "bounds": [
      -2.6481308960412906,
      55.9604080548856,
      -2.62664091461468,
      55.97227003506276
   ],
   "vector_layers": [
      {
         "field": {
            "fieldName": "String",
            "NDVI": "Number"
         },
         "id": "default",
         "minzoom": 12,
         "geometry_type": "Polygon",
         "maxzoom": 15
      }
   ]
}

Which I'm not being able to display on Mapbox Map using either Raster or Vector Layers. Also when trying to do a GET request from the tiles url the tilejson return I'm receiving the following error:

{
"error": "invalid zoom value, must be an integer number greater than or equal to 0",
"status": 400,
"message": "invalid zoom value, must be an integer number greater than or equal to 0",
"z": null,
"x": null,
"y": null
}

If anyone have experienced this or may know what I may be doing wrong it would be highly appreciated.

0

There are 0 answers