JSON.stringify esri.map object

4166
4
Jump to solution
10-02-2013 08:24 PM
ChrisJudd1
New Contributor III
Hi, I would like to be able to xhrpost the map object.  However, when I try to JSON.stringify the map, I get the following error: TypeError: Converting circular structure to JSON. 

How can this be done?  I know its possible since the print and gp tasks are able to turn the map into a string before posting it.

Thanks,
Chris
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
The print task parses the map object manually to create a JSON object that matches the ExportWebMap specification to use Print GP Services.
http://resources.arcgis.com/en/help/main/10.1/index.html#//0154000004w8000000

So you can do the same, but you'd need to step through the map object, JSON.stringify() won't do it.

View solution in original post

0 Kudos
4 Replies
ReneRubalcava
Frequent Contributor
The print task parses the map object manually to create a JSON object that matches the ExportWebMap specification to use Print GP Services.
http://resources.arcgis.com/en/help/main/10.1/index.html#//0154000004w8000000

So you can do the same, but you'd need to step through the map object, JSON.stringify() won't do it.
0 Kudos
ChrisJudd1
New Contributor III
Thank you sir, that answered my question!
0 Kudos
ReneRubalcava
Frequent Contributor
Just a quick update on this. You can get the mapOptions and operationalLayers (probably most tedious to process) by using the PrintTask.

PrintTask.prototype._getPrintDefinition(map);


After that you'd need to mixin the layoutOptions with your legendOptions if needed and the extra parameters.
Send an object as
{
  Web_Map_as_JSON: <web map as json>,
  Format: <jpg, pdf, whatever>,
  Layout_Template: <template name>
}


You're good to go.
0 Kudos
Arne_Gelfert
Occasional Contributor III

Thanks, Renee. - For anyone needing more info, there is a somewhat more recent related thread here:

Get the WebMap from Javascript API esri/map

0 Kudos