AGOL Webmap as JSON?

1570
2
Jump to solution
12-16-2016 01:55 PM
CalebMackey1
Regular Contributor II

Just curious if there is an "out of the box" way to get the web map as JSON from the current AGOL webmap from within a custom widget?  Unfortunately, due to client specifications I cannot conform to the Export Web Map Task parameters for the GP Service I'll be using.

I know with the JavaScript API, I can use the PrintTask to do the work for me to get the map in the current state by doing this:

var printTask = new PrintTask()
var Web_Map_as_JSON = printTask._getPrintDefinition(this.map))

However, when I try that from a custom widget passing in the AGOL web map, I get the following error:

Another thing I found that will give me the web map is to use the ArcGIS Utils:

utils.getItem(this.map.itemId)

That does give me the web map as JSON, but obviously it is not the current state (i.e. doesn't show which layers are on/off in the current map).  Is there an "easy" way or do I have to manually build it?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Caleb,

   The problem with using private functions is that they are undocumented. The method takes a map as the first param and a PrintParameters as the second and because you were not providing the PrintParameters.

              var printTask = new PrintTask("your url");
              var template = new PrintTemplate();
              template.preserveScale = false;

              var params = new PrintParameters();
              params.map = this.map;
              params.template = template;
              var Web_Map_as_JSON = JSON.stringify(printTask._getPrintDefinition(this.map, params));
              console.info(Web_Map_as_JSON);

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Caleb,

   The problem with using private functions is that they are undocumented. The method takes a map as the first param and a PrintParameters as the second and because you were not providing the PrintParameters.

              var printTask = new PrintTask("your url");
              var template = new PrintTemplate();
              template.preserveScale = false;

              var params = new PrintParameters();
              params.map = this.map;
              params.template = template;
              var Web_Map_as_JSON = JSON.stringify(printTask._getPrintDefinition(this.map, params));
              console.info(Web_Map_as_JSON);

View solution in original post

CalebMackey1
Regular Contributor II

Thanks, Robert!  That did the trick.  

0 Kudos