Help me understand how to use ConvertWebMapToArcGISProject!

311
1
Jump to solution
01-09-2020 02:17 PM
Arne_Gelfert
Regular Contributor

In a separate post a while back, I was hoping to solicit some guidance on how to use the geoprocessing widget.  After some distractions, I'm now returning to this effort.

I have built a few functioning Python tool(boxe)s with ArcGIS Pro now. I understand how to interact with the map layout in Pro to programmatically create PDF of my map and modify the map for conversion to PDF. I am not completely sure how that related to what ESRI calls a "staged layout template." But that has to be similar to what I'm doing. First, I want to replace my aprx reference to a project file with one to a web map.

Memorable ESRI Quote #1

For advanced printing scenarios, you ...  can use the ConvertWebMapToMapDocument (for ArcMap) or ConvertWebMapToArcGISProject (for ArcGIS Pro) functions in the Python arcpy module.

So I am trying to leverage

arcpy.mp.ConvertWebMapToArcGISProject(<webmap_as_json>, <some_wonderful_pdf>)

There is no simple way of generating some sample JSON describing your web map that you could use to test your script. So after publishing a script as a geoprocessing service that takes <webmap_as_json> as an argument, how do I pass the json ?

I can hook Web AppBuilder's Geoprocessing widget into my geoprocessing services but it's needing that JSON to feed on.

So I'm inclined to think I'm headed down the wrong path.

Questions:

  1. Which widget, if any, can call geoprocessing services and pass along the JSON?
  2. Is a "staged layout template" just a PAGX file sitting in a folder registered with my hosting server?
0 Kudos
1 Solution

Accepted Solutions
Arne_Gelfert
Regular Contributor

Doing a post-mortem on this before I forget....So I dropped my efforts to use the OTB GP widget, instead, I created a GP tool in ArcGIS Pro (using Python) and 

ConvertWebMapToArcGISProject

which allows you to create an in-memory APRX and then massage it to your heart's delight - iterate over maps or layers, choose a pre-configured template, and export that to PDF.

To consume that, I created a custom widget and in it, I did something like this:

 printFromJSON : function (){

var currentMap = this.map;

var printTask = new PrintTask();
var params = new PrintParameters();
params.map = currentMap;

var webMapAsJSON = printTask._getPrintDefinition(currentMap, params);
var webMapAsJSONasString = JSON.stringify(webMapAsJSON);
var file;
var gpParams = {"Web_Map_as_JSON" : webMapAsJSONasString,
"PDFOutputFile" : file};
gp.submitJob(gpParams, this.completeCallback, this.statusCallback);
},

//Note the "var file" in there‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍. It has to match any output parameters you've configured in your GP tool.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
1 Reply
Arne_Gelfert
Regular Contributor

Doing a post-mortem on this before I forget....So I dropped my efforts to use the OTB GP widget, instead, I created a GP tool in ArcGIS Pro (using Python) and 

ConvertWebMapToArcGISProject

which allows you to create an in-memory APRX and then massage it to your heart's delight - iterate over maps or layers, choose a pre-configured template, and export that to PDF.

To consume that, I created a custom widget and in it, I did something like this:

 printFromJSON : function (){

var currentMap = this.map;

var printTask = new PrintTask();
var params = new PrintParameters();
params.map = currentMap;

var webMapAsJSON = printTask._getPrintDefinition(currentMap, params);
var webMapAsJSONasString = JSON.stringify(webMapAsJSON);
var file;
var gpParams = {"Web_Map_as_JSON" : webMapAsJSONasString,
"PDFOutputFile" : file};
gp.submitJob(gpParams, this.completeCallback, this.statusCallback);
},

//Note the "var file" in there‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍. It has to match any output parameters you've configured in your GP tool.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos