Request Static Image from mapbox with polygon via URL

710 Views Asked by At

I am trying to request a static image of a map from Mapbox that has a polygon overlay.

I keep getting a 422 Unknown response.

Below is the url encoded geojson: https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/geojson(%7B%22type%22%3A%22FeatureCollection%22%2C%22features%22%3A%5B%7B%22id%22%3A%224c97769717bde5d3ece6aa37ad153a26%22%2C%22type%22%3A%22Feature%22%2C%22geometry%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-97.35498290052888%2C47.07901887872825%5D%2C%5B-97.34567101592366%2C47.07901887872825%5D%2C%5B-97.34553174426712%2C47.06840297785641%5D%2C%5B-97.35539079875348%2C47.06965221312885%5D%2C%5B-97.36672817535712%2C47.069627161422176%5D%2C%5B-97.36668040297414%2C47.07906677293954%5D%2C%5B-97.35498290052888%2C47.07901887872825%5D%5D%5D%7D%2C%22properties%22%3A%7B%22title%22%3A%22%22%7D%7D%5D%7D)/auto,13/500x300?access_token=MY_MAPBOX_ACCESS_TOKEN

Below is the geojson structure I have stored in my database field that gets url encoded:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [-98.38294, 47.06659],
                    [-98.38322, 47.05229],
                    [-98.36687, 47.05221],
                    [-98.36675, 47.06654],
                    [-98.38294, 47.06659]
                ]
            ]
        },
        "properties": {
            "title": ""
        }
    }]
}

Any help would be greatly appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

The error you receive back with this request is a descriptive one:

{"message":"The auto parameter cannot be used with additional location parameters, bearing, or pitch."}

The problem with this request is not your overlay data, but rather the fact that you are attempting to include additional position arguments after auto (e.g. /auto,13/) which is not supported.

If you remove ,13 from the request, then the image renders as expected:

map with polygon image