Get the WebMap from Javascript API esri/map

3660
5
Jump to solution
08-18-2015 08:56 AM
DaveHighness
Occasional Contributor II

Hi, I need a good method to get the current WebMap object from the Javascript API map. I need to pass the WebMap as JSON to a GP task that will use the arcpy.ExportWebMap_server() tool to create a map image on the server. I was using a hack method I found using the Javascript API PrintTask that was working great until I switched to the latest version of the API (3.14) which I need for other reasons.

var pt = new PrintTask();

var webmap_json = pt._getPrintDefinition(this.map);

The _getPrintDefinition() is an internal method and it appears it no longer works in the latest version of the JS API (3.14). Is there another way to get the WebMap? A method like esri.map.getWebMapJson() would be nice!

Thanks

0 Kudos
1 Solution

Accepted Solutions
DaveHighness
Occasional Contributor II

Ah, I figured it out. I need to pass the _getPrintDefinition() the map and PrintParameters objects. It would be nice if this method were public!

esri/tasks/PrintTask

Method: _getPrintDefinition(esri.Map, esri.tasks.PrintParameters)

View solution in original post

5 Replies
DaveHighness
Occasional Contributor II

Ah, I figured it out. I need to pass the _getPrintDefinition() the map and PrintParameters objects. It would be nice if this method were public!

esri/tasks/PrintTask

Method: _getPrintDefinition(esri.Map, esri.tasks.PrintParameters)

Cook_CountyGIS
New Contributor II

Yes, upgrading from 3.13 to 3.17, I needed to add the PrintParameters:

.....

var params = new esri.tasks.PrintParameters();
params.map = this.map;
params.template = template;
.....
// _getPrintDefinition needed the second parameter: params
var webMapAsJSON = printTask._getPrintDefinition(this.map, params);

.....
Arne_Gelfert
Regular Contributor

Thanks for sharing this.... just what I needed.

0 Kudos
NathanB
New Contributor II

does anyone have a full code sample?  i keep getting null or empty for webMapAsJSON    trying it it with javascript api 4

by Anonymous User
Not applicable

Any luck ?