Handle requests with complex overlay data
Overlaying additional data onto your map images using GeoJSON can significantly increase the size of your requests. This is especially true if the GeoJSON objects contain many custom markers, boundaries, lines, and so on. Including a large GeoJSON in your request can quickly exceed the URL length limit of 8,192 characters.
Importance of compressing GeoJSON data
There are several ways to ensure your request doesn't exceed the allowed length, such as reducing data complexity by removing features or limiting the display area on the image. One particularly effective method is using the flexible polyline feature supported by the HERE Map Image API v3. This feature helps to reduce the size of your request without affecting image quality or the extent of data shown.
Flexible polyline encoding is highly useful for efficiently representing complex line geometries, such as routes or paths or handling large numbers of point geometries, with a compact string format. By encoding a series of coordinates into a single, compressed string, flexible polyline encoding allows for the inclusion of intricate multiPoint and line geometries without exceeding URL length limitations, which can be particularly useful in case of applications that require the transmission of detailed geographic data.
The following figure demonstrates a comparison between uncompressed (using the geojson parameter) and compressed (using the overlay parameter) data. This showcases the potential benefits of using flexible polyline to compress the size of custom data for overlaying on the map image, without exceeding the request length limit:
Prerequisites
- You have basic knowledge of the Python language
- You installed the
flexpolylinelibrary - You have a HERE Platform account
Tutorial objectives
This tutorial demonstrates how to compress GeoJSON data that would otherwise exceed the URL length limit. By combining Python string manipulation with flexible polyline encoding, you can ensure that your request completes without errors.
The flexible polyline feature is implemented in multiple programming languages. For more information, see the feature documentation.
Source GeoJSON data
The GeoJSON object that's the subject of this tutorial provides geographical data for three large river systems across South and North America, obtained from the Natural Earth public-domain dataset, comprising of hundreds of coordinate pairs for accurate representation, in the form of a MultiLine geometry:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[[-124.83563,56.756924],[-124.20045,56.243492],[-123.888738,56.088825],[-123.54354,56.044719],[-122.730075,56.09854],[-122.221708,56.021232],[-121.973635,56.019785],[-121.357136,56.189749],[-120.244594,56.151973],[-119.509445,56.251451],[-119.188714,56.244371],[-118.670348,56.016219],[-118.346233,55.981312],[-117.779136,56.054098],[-117.50613,56.155358],[-117.20036,56.412319],[-117.176899,56.545024],[-117.258212,56.854876],[-117.132276,57.281026],[-117.107523,57.654156],[-117.037011,57.929229],[-116.854154,58.069582],[-116.676232,58.127408],[-116.542106,58.288949],[-116.323153,58.370959],[-115.98847,58.418708],[-114.972512,58.409717],[-114.613231,58.475863],[-114.488959,58.512165],[-114.21144,58.590481],[-113.923622,58.66496],[-113.768451,58.689751],[-113.583488,58.723574],[-113.29753,58.807845],[-113.149186,58.855323],[-112.647615,59.097608],[-112.322673,59.1259],[-112.06504,59.083577],[-111.92647,58.973455],[-111.410765,59.005055],[-111.443838,59.536625],[-111.569024,59.847949],[-112.383135,60.221544],[-112.493206,60.314613],[-112.483697,60.450522],[-112.57134,60.540594],[-113.160116,60.853237],[-113.28246,61.173812],[-113.459658,61.24267],[-113.58198,61.244208],[-113.70401,61.245874],[-113.8389,61.256003],[-114.136035,61.278108],[-114.433242,61.300186],[-114.56835,61.310211],[-116.334341,61.089398],[-116.698634,61.121386],[-117.668109,61.307834],[-118.154979,61.421471],[-119.070634,61.301323],[-119.76837,61.334138],[-120.317819,61.463355],[-120.575039,61.569679],[-120.813396,61.780958],[-121.589163,61.973685],[-123.024217,62.242299],[-123.254668,62.348908],[-123.296113,62.509932],[-123.228933,62.86668],[-123.320504,63.05734],[-123.954419,63.741019],[-124.336489,64.00276],[-124.489347,64.22316],[-124.761682,64.423872],[-125.025155,64.692021],[-125.300228,64.805967],[-126.181621,65.049105],[-126.929328,65.29139],[-128.030191,65.608347],[-128.671418,65.722759],[-128.908561,65.860554],[-128.983363,66.029665],[-128.842079,66.322515],[-129.025608,66.455479],[-129.770524,66.731612],[-130.043711,66.880879],[-130.345037,67.213779],[-130.532829,67.30584],[-130.759404,67.353667],[-131.208679,67.454694],[-132.652829,67.293309],[-133.015776,67.29274],[-133.37255,67.359351],[-133.829732,67.520582],[-134.190072,67.741524],[-134.399568,68.052642],[-134.40719,68.182092],[-134.159686,68.449672],[-134.244228,68.706194],[-134.835898,68.963775],[-135.313414,69.374991]],
[[-110.7437,44.726728],[-110.929399,44.678927],[-111.099673,44.756519],[-111.204415,44.812472],[-111.309195,44.86845],[-111.425512,44.905567],[-111.541791,44.942658],[-111.635945,45.077507],[-111.654058,45.309715],[-111.448515,46.024581],[-111.452804,46.222657],[-111.48432,46.291645],[-111.515797,46.361434],[-111.562849,46.43975],[-111.65045,46.584172],[-111.698034,46.662139],[-111.783624,46.738116],[-111.86867,46.81368],[-111.921974,46.941295],[-111.855906,47.108184],[-111.644498,47.292256],[-111.170625,47.588026],[-110.511544,47.91382],[-110.226651,47.964256],[-109.819079,47.806927],[-108.938022,47.764139],[-108.821287,47.738766],[-108.564679,47.682943],[-108.308606,47.627106],[-108.193468,47.601694],[-108.108087,47.586876],[-107.946519,47.559449],[-107.859225,47.544695],[-106.883961,47.750962],[-106.759957,47.820802],[-106.529676,47.950549],[-106.405722,48.020532],[-106.233571,48.031784],[-105.822967,48.058462],[-105.332867,48.090243],[-104.922237,48.116857],[-104.750035,48.128019],[-103.772317,48.027301],[-103.240437,48.092414],[-102.894024,48.058669],[-102.140091,47.650218],[-101.793626,47.553273],[-101.691594,47.540974],[-101.502064,47.518159],[-101.399877,47.505989],[-101.355397,47.427002],[-101.311072,47.34786],[-101.005276,47.171126],[-100.946129,47.052542],[-100.836291,46.832271],[-100.777176,46.713531],[-100.691452,46.604778],[-100.605688,46.49618],[-100.570419,46.140543],[-100.355393,45.350333],[-100.370509,45.084923],[-100.459366,44.910205],[-100.639872,44.747708],[-100.629382,44.640118],[-100.55719,44.533716],[-100.475477,44.484133],[-100.393918,44.434962],[-100.271242,44.372873],[-100.043197,44.256976],[-99.920381,44.194512],[-99.625516,44.166452],[-99.557832,44.12086],[-99.432181,44.03624],[-99.364653,43.990752],[-99.376962,43.914788],[-99.399576,43.77353],[-99.41173,43.697462],[-99.377314,43.594678],[-99.250183,43.510652],[-98.973511,43.323532],[-98.70437,43.130804],[-98.599842,43.029932],[-98.612037,43.003751],[-98.59408,43.000011],[-98.336111,42.873637],[-97.968175,42.794546],[-97.881823,42.839711],[-97.644086,42.836352],[-97.287389,42.846171],[-97.028284,42.717651],[-96.75414,42.633832],[-96.708794,42.551098],[-96.623037,42.502651],[-96.455399,42.48888],[-96.410363,42.389273],[-96.346594,42.224606],[-96.34892,42.14195],[-96.167251,41.953305],[-96.104568,41.787682],[-96.096894,41.556689],[-96.024857,41.524546],[-95.958633,41.404915],[-95.855952,41.11656],[-95.834248,40.944039],[-95.861869,40.764721],[-95.796369,40.58419],[-95.776422,40.501352],[-95.608138,40.343223],[-95.452359,40.215065],[-95.322936,40.001331],[-95.085172,39.86798],[-94.955,39.869996],[-94.926552,39.725379],[-95.06706,39.53968],[-94.991302,39.444414],[-94.868002,39.234608],[-94.604788,39.139704],[-93.181697,39.317962],[-92.992535,39.275536],[-92.844792,39.033483],[-92.531582,38.876878],[-92.292914,38.658881],[-92.047244,38.614465],[-91.451751,38.670482],[-90.885377,38.635058],[-90.432717,38.794945],[-90.355471,38.800274],[-90.214197,38.805455],[-90.144596,38.794299],[-90.182849,38.680288],[-90.212498,38.584829],[-90.30549,38.439075],[-90.369724,38.263401],[-90.22795,38.113385],[-90.030184,37.972179],[-89.917012,37.968535],[-89.654961,37.748601],[-89.553882,37.719016],[-89.479287,37.477377],[-89.516236,37.326818],[-89.388311,37.081458],[-89.280178,37.107089],[-89.102954,36.952215],[-89.134373,36.851989],[-89.115098,36.694556],[-89.273822,36.611719],[-89.498201,36.506402],[-89.524039,36.409432],[-89.585353,36.266882],[-89.663023,36.02328],[-89.684265,36.02328],[-89.687311,36.02328],[-89.67142,35.981719],[-89.673746,35.940158],[-89.775109,35.799417],[-89.950266,35.701981],[-89.988972,35.536462],[-90.147283,35.405255],[-90.13519,35.113878],[-90.249395,35.020653],[-90.268076,34.941485],[-90.446386,34.866994],[-90.450107,34.722041],[-90.584336,34.454254],[-90.69973,34.397539],[-90.87654,34.261733],[-90.981909,34.054873],[-91.200629,33.70616],[-91.223419,33.469069],[-91.108309,33.206656],[-91.15611,33.009923],[-91.084641,32.952873],[-91.175644,32.80854],[-91.031027,32.60261],[-91.071826,32.478896],[-90.943074,32.306685],[-91.081618,32.204675],[-91.128205,32.015462],[-91.321449,31.859606],[-91.411417,31.649955],[-91.502161,31.408626],[-91.62466,31.296953],[-91.583758,31.047356],[-91.52893,30.808352],[-91.340362,30.646864],[-91.121849,30.269987],[-90.991366,30.133768],[-90.783394,30.052895],[-90.045894,29.895721],[-89.952695,29.801334],[-89.887686,29.6477],[-89.403866,29.157213]],
[[-71.668747,-15.336376],[-71.50116,-14.792327],[-71.557539,-14.28688],[-71.659212,-14.077952],[-71.857133,-13.901683],[-72.136806,-13.739213],[-72.750748,-13.486825],[-73.221107,-13.421868],[-73.5623,-13.017551],[-73.858665,-12.496136],[-73.980673,-12.198377],[-74.144228,-11.452789],[-74.145159,-11.277658],[-73.802596,-11.188774],[-73.735726,-11.029766],[-73.788281,-10.802079],[-73.995375,-10.394352],[-74.050591,-10.181704],[-74.006614,-9.860328],[-74.166889,-9.681476],[-74.4755,-9.029216],[-74.468188,-8.738846],[-74.337343,-8.511677],[-74.483071,-8.390134],[-74.660321,-8.069016],[-74.908394,-7.836369],[-75.021772,-7.461508],[-75.215688,-7.178063],[-75.208195,-7.085459],[-75.136028,-7.012337],[-75.160781,-6.52663],[-75.103472,-6.238482],[-74.938444,-6.066038],[-74.747086,-5.970126],[-74.306182,-5.639862],[-74.064337,-5.137877],[-73.974265,-5.044911],[-73.806575,-4.972358],[-73.488635,-4.444845],[-73.358282,-4.173388],[-73.215784,-4.037221],[-73.139122,-3.683702],[-73.035046,-3.55477],[-72.87211,-3.494773],[-72.475855,-3.481028],[-72.13262,-3.420101],[-71.865556,-3.435966],[-71.542734,-3.731296],[-71.265825,-3.859661],[-70.900473,-3.960068],[-70.628991,-3.888186],[-70.365493,-3.911182],[-70.113389,-4.06833],[-69.869296,-4.320356],[-69.664037,-4.271729],[-69.503246,-4.139179],[-69.262873,-3.622156],[-68.952943,-3.443304],[-68.06876,-3.296904],[-67.96011,-3.217013],[-67.932385,-3.108027],[-67.658216,-2.865406],[-67.378905,-2.707328],[-66.846586,-2.659217],[-66.541463,-2.486256],[-65.997878,-2.49654],[-65.760968,-2.602993],[-65.620459,-2.609246],[-65.439101,-2.684642],[-64.575614,-3.39819],[-64.011126,-3.743544],[-63.177275,-4.035154],[-62.736501,-3.855888],[-62.410552,-3.789432],[-61.810821,-3.855165],[-61.493554,-3.769589],[-60.596063,-3.350855],[-59.924502,-3.205954],[-59.82996,-3.141927],[-59.657929,-3.12322],[-58.689048,-3.342328],[-58.535595,-3.226263],[-58.315918,-3.211845],[-57.766494,-2.658494],[-57.475892,-2.495506],[-56.702244,-2.47928],[-56.119541,-2.132996],[-55.822143,-2.014502],[-55.514849,-1.949493],[-55.151021,-2.137595],[-54.806391,-2.175629],[-54.525116,-2.440316],[-54.185964,-2.311176],[-53.791982,-1.978535],[-53.496445,-1.828105],[-52.4362,-1.430765],[-51.788177,-1.085101],[-51.000241,-0.483174],[-50.554816,0.056276]]
]
},
"properties": {}
}
]
}Request an image with uncompressed GeoJSON
The GeoJSON object from the previous example contains almost 12,000 characters, even if minified, well beyond the character limit. To test the character limit, include the GeoJSON data from the example in the following request:
https://image.maps.hereapi.com/mia/v3/base/mc/overlay;padding=10/1200x900/png8
?apiKey={YOUR_API_KEY}
&geojson={"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiLineString","coordinates":[[[56.756924,-124.83563],[56.243492,-124.20045],[56.088825,-123.888738],...Note
In the previous request, the GeoJSON object was cut off for brevity.
Response: The API returns the following error message:
414 Request-URI Too LargeThe message indicates that the request exceeded the character limit, as expected.
Compress GeoJSON data
To address the 414 Request-URI Too Large error, compress GeoJSON data to ensure it fits within the URL length limits for API requests by combining basic Python scripting with flexible polyline encoding to significantly reduce the size of the GeoJSON data without compromising the quality or extent of the information displayed.
-
Create a
.pyextension file and open it using an editor of your choice. -
In the file, import the
flexpolylineandjsonlibraries by adding the following statements:import flexpolyline as fp import json -
Declare the
apikeyvariable to hold your API key:apikey = 'YOUR_HERE_APIKEY' -
Declare the
geojsonvariable to hold the GeoJSON object with eitherLineString,MultiLineString, orMultiPointgeometries to compress:geojson = '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiLineString","coordinates":[[[-124.83563,56.756924],[-124.20045,56.243492]...' -
Extract the
coordinatesvalues from the object that you want to compress:coordinates = data["features"][0]["geometry"]["coordinates"]Note
Based on the source GeoJSON for this tutorial, the
coordinatesvariable extracts theMultiLineStringcoordinates as an array of arrays from the first feature. Ensure you adjust the coordinate extraction to match the structure of your own GeoJSON objects to avoid unexpected results or aKeyError. -
Because you can't compress a
MultiLineStringdirectly, apply thefp.encode()method to eachLineStringmember of thecoordinatesarray:# Converts the input data into the expected format # Transforms arrays of [[latitude, longitude],...] values into multiple flexible polylines encoded_coordinates = [fp.encode([[lat, lon] for lon, lat in line]) for line in coordinates]Note
The geographic coordinates in the source GeoJSON file are in the
[longitude, latitude]format and need to be swapped to the[latitude, longitude]format, required by themultiLineparameter of the HERE Map Image API v3.For more information, see line and multiLine geometries.
-
Join the encoded
LineStringgeometries with the";"character to create the value for themultiLineparameter in the HERE Maps API v3 request:# Get the 'Fp1;Fp2;Fp3;...' string multiLine_param = ";".join(encoded_coordinates) -
Construct the static URL with the encoded coordinates and your API key:
staticUrlRequest = f'https://image.maps.hereapi.com/mia/v3/base/mc/overlay;padding=10/1200x900/png?apiKey={apiKey}&overlay=multiLine:{multiLine_param}'Note
The original request used the
geojsonparameter that the API requires for handling additional overlays in the form of traditional GeoJSON data. The new request uses a different parameter calledoverlay, designed for making the additional overlay data as compact as possible. -
Optional: Customize the compressed
LineStringgeometries by performing any of the following actions:-
Add style properties to the
multiLineparameter, as shown in the following example:multiLine:fp1;fp2;fp3;color=%230000FF;width=4;outline-color=%23AFEEEE;outline-width=2 -
Add markers with text bubbles as part of an
overlayparameter, for example:overlay=point:-3.182206,-59.968344;label=Amazon|36.981127,-89.117962;label=Mississippi|63.852735,-124.027241;label=Mackenzie|icon=bubble;color=%23AFEEEE;outline-color=%230000FF
-
-
Print the URL to check the result:
print(staticUrlRequest) -
Make the API query by accessing the resulting URL. The API request is successful, returning the requested image, as shown in the following figure:

The following section contains the final request, for reference:
https://image.maps.hereapi.com/mia/v3/base/mc/overlay;padding=10/1200x900/png?apiKey={YOUR_HERE_APIKEY}
&overlay=multiLine:BF4qt6K1-95X9okD8h8D1mem88BzzIwtjCswKk8-EljPqpjDhJuuwBqmhBkt4DjsHup5G4tT2yvEnsBy0-B9xsB4nlDl6G4p_B-mOq4uD84Tqq1BgmyBi37Bs9Z0yE0w8Bl8PunzCizYi8oC46Em31B24Nmtb82jBupLg4iB0xfomaygQw4qBuqJ4rhCl4B4tmGs9MwlmC8iH2oYwpPwm2BwxO8m4B-6E6peszGgkkB2uQo73B4oJk_cqqvB6-hD6wF-u_BvoImqyBnwViibwlGm3kDo6nD3uG658BruY--oCng_E2lS9vVuxau7B-yR3jRii9B7_yDyz-Bz8XsuNvziB0Jv8XsK16Xq_BhramqEjh6BgqEvh6B0-BtsahkrBt94K-nG5knCotkBnr9FomW9i_C9uX56yFktG7ooE0nZhqrDw4UznyBwopB3xuBw0lBvw3E8u0Bjp4Iq6UpgtBsuf_iI21lC8jN0nlBp8RgxlE_57D8jzB9zqCwhrBr7dumnBhm1B-r0B3uzBmoWl31ByvvB1ksFqqvBlhyEg99Brg3GirW1n9Dm9ajquB-ghBvzOsm5Bgzbg_Zh7jB691B1vxE-kdtr1B0ghCp76Bs_R11kB-qJhosBs3T_33Czwf9h6IxDt8mCqgN51lC2vfrp5C8krBjsmCw48Br9oBipZzvBso0B8qwBojyBrwQ-pyB9xzDiqwCto9C;BFi2_wIj09jV3qJzokB-kPlohB29K1uU89K7uUgoH92W6nH32W6qatsSqrtBnxD8zrE0koBg2mB3akvN_kGm0N3kGwpPhmJ0mcvjRqnPrpJ86O92Qo4OxzQ09YjtKgzgB88Mw-jBqppBy45B4x8Cm0_Bo3gEo7Jy03Bp3eqzvCtrI0isFx-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q2Mx5_C8v-C;BFrsz9C15t1NqoqDu3gBi3iDrgL65oBt7T2tiB_0mBu3f_z2BupxBj93D-1M377Cg_uCt0iC66lDn85Bgl6Bx6X-zxEn-fymiB5FyrRg9iC4hf-hNivsBtoKq0vCruoBixpBh5Ky4-B8yI69iB3pf0s_D5o8B624B2tB6rsB6xZ23X5uc-2-B5ziBiutBtuwB8mpCzkWyr3B_7lB4iS6uBgpOijO27-C16E-o4BmmL41hBungBu3S-rlBmwgC2j2CshiDwnvBilSgzRulOi4gBghnDij-Byg1B4uZiza06bwhlCk_O6lZuqUg3Ls6f81CystC68LohjCljDkl0B515B2h_BniZ0i2BxzTwrnCohO4g1B1vE8uzBl2e0nxBlnxBy1vB-vJ8ioBu8Z-sfs_kDs-uB89iBix8Bgzck2sFqzPinVkpVqtFssvBwx1Bg8e4x2B2sJ--nDg5hBiz7BngCslqDp5U2ouBjnBmubl3OwtjB1rrE60oFtujCgouDx-4By7iFsgjB8i2Cs_Mm1_B56Mqk1D62Q--9Bi5xCqpvF2pcoljEkwM8uS-0DmzhBt5qBwn9Fu1Wi_dk6Cg9qBuisD-prD06fo44BulDqj3Eo0jC85xD0kX4i6Bq2Myg8B13kB-hnC1tH-pjCp2zB-92BknZ4niCg_gCs-sCosdk35BsztCwivGswjCky-Diy1D085EyrpD8_2C;color=%230000FF;width=4;outline-color=%23AFEEEE;outline-width=2
&overlay=point:-3.182206,-59.968344;label=Amazon|36.981127,-89.117962;label=Mississippi|63.852735,-124.027241;label=Mackenzie|icon=bubble;color=%23AFEEEE;outline-color=%230000FFConclusion
This tutorial showcased the potential of the flexible polyline feature for overlaying additional data onto your map images without exceeding the URL length limit. The tutorial demonstrated how to compress a GeoJSON containing nearly 12,000 characters to fit within the 8,192 character limit for the entire request, while also adding style customizations for the overlay features.
If you are facing issues related to request size, even after implementing flexible polylines, consider switching to client-side rendering by using the following services:
Next steps
For more information on custom overlays in the HERE Map Image API, see:
Updated 23 days ago