Hung Truong
Hung Truong

Reputation: 91

Trying to use Mapbox Static Images with a complicated (long) GeoJSON object results in an error

We're trying to use the Mapbox Static Image endpoint to draw a GeoJSON object on a map as a thumbnail image. We seem to be running into a URL size character limit, as our URL is 29219 characters long! Just wondering if there's something we can do to actually get an image back, either by sending the GeoJSON in the POST body or some other wizardry.

Upvotes: 2

Views: 1159

Answers (2)

Moemanchu
Moemanchu

Reputation: 161

One solution that worked for me was reducing the precision in my data points and simplifying the geometry. For example, connecting to my Postgres data source, I use the following Postgis functions to help shorten the URL.

1.) ST_ASGEOJSON(geom, 5), which shortened the lat long pairs to 123.45678 instead of 123.456789101112

2.) ST_SIMPLIFY(geom, DISTANCE), which removes a number of points using whiz-bang magic.

It's not perfect, but it allowed me to use this API with complex MULTIPOLYGON geometries and SQL Reporting Services 2008.

Upvotes: 0

nrutas
nrutas

Reputation: 5051

URLs have no limit, only software. IE stops at 2,048.

why are you putting all of the data in the URL? one thing you could do is send a reference which the other end queries via code (from a db or other method) instead of just encoding it raw into a URL.

Upvotes: 0

Related Questions