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?
Solved! Go to Solution.
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);
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);
Thanks, Robert! That did the trick.