From 49834d3c96424221c59965fa54df9fb69b1c340a Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Fri, 4 Dec 2015 06:11:16 -0400 Subject: [PATCH] use compact separators to keep json overlay small --- mapbox/services/static.py | 3 ++- tests/test_staticmaps.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mapbox/services/static.py b/mapbox/services/static.py index 8e9febe..211f4dc 100644 --- a/mapbox/services/static.py +++ b/mapbox/services/static.py @@ -30,7 +30,8 @@ def image(self, mapid, lon=None, lat=None, z=None, features=None, if features: values['overlay'] = json.dumps({'type': 'FeatureCollection', - 'features': features}) + 'features': features}, + separators=(',', ':')) if len(values['overlay']) > 4087: # limit is 4096 minus the 'geojson()' raise ValueError("geojson is too large for the static maps API, " diff --git a/tests/test_staticmaps.py b/tests/test_staticmaps.py index 548ab2f..ce672d1 100644 --- a/tests/test_staticmaps.py +++ b/tests/test_staticmaps.py @@ -56,7 +56,7 @@ def test_staticmap_lonlatz_only(): def test_staticmap_lonlatz_features(points): overlay = json.dumps({'type': 'FeatureCollection', - 'features': points}) + 'features': points}, separators=(',', ':')) overlay = quote(overlay) url = ('https://api.mapbox.com/v4/mapbox.satellite/geojson({0})/' '-61.7,12.1,12/600x600.png256?access_token=pk.test'.format(overlay)) @@ -69,15 +69,15 @@ def test_staticmap_lonlatz_features(points): content_type='image/png') res = mapbox.Static(access_token='pk.test').image('mapbox.satellite', - -61.7, 12.1, 12, - points) + -61.7, 12.1, 12, + points) assert res.status_code == 200 @responses.activate def test_staticmap_auto_features(points): overlay = json.dumps({'type': 'FeatureCollection', - 'features': points}) + 'features': points}, separators=(',', ':')) overlay = quote(overlay) url = ('https://api.mapbox.com/v4/mapbox.satellite/geojson({0})/' 'auto/600x600.png256?access_token=pk.test'.format(overlay)) @@ -90,7 +90,7 @@ def test_staticmap_auto_features(points): content_type='image/png') res = mapbox.Static(access_token='pk.test').image('mapbox.satellite', - features=points) + features=points) assert res.status_code == 200