Select to view content in your preferred language

Alternatives to Geoprocessing Widget, anyone? Ways to generate sample JSON for testing GP Service, anyone else?

1533
6
Jump to solution
12-17-2019 12:05 PM
Arne_Gelfert
Frequent Contributor

I'm in the process of converting some existing custom Geocortex tools to ESRI WAB and JSAPI web tools.

For one of these, what I'm looking to recreate is the ability to:

  1. Query for and select a feature
  2. Generate a set of PDF maps centered on that feature with some pretty strict layout spec's.
  3. Finally prompt the user to download/save the PDFs as ZIP.

ESRI suggested that I look into using the Geoprocessing Widget to call a geoprocessing service that generates the maps. GP Widget looks promising.

QUESTION 1 - Is there another more appropriate out of the box offering? I've previously set up a custom print template on my hosting server, which worked fine. But what I need is a little more, I guess you'd say - complex. More like a fancy ultra print widget with the ability to pass in some parameters that are used as text in a print template.

Of course, I immediately started reading about arcpy.ConvertWebMapToArcGISProject(). The thought of working out my functionality in Python has a much great appeal than trying to whip up some jimu-jambalaya in WAB (sorry still not feeling the love).

QUESTION 2 - What is the easiest way for me to generate some sample JSON based off an actual web map of mine that I can use for testing with my geoprocessing code?

I could, of course, follow the guidelines here. But is there a simpler (lazier) way? Something similar to generating JSON output for a map service using the "?f=pjson." karate chop.

https://server.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade_Dark/MapServer/0/?f=pjson

Hey, thanks for chiming in. 

0 Kudos
1 Solution

Accepted Solutions
Arne_Gelfert
Frequent Contributor

Just doing a post-mortem on this one: You can your JSON from esri/tasks/PrintTask, as explained here: Get the WebMap from Javascript API esri/map.

View solution in original post

0 Kudos
6 Replies
Arne_Gelfert
Frequent Contributor

I am going to boldly answer Part 2 of my own question from last month (last year).

If you have a web map stored as an item in Portal, you can get a JSON representation of it using the following URL:

https://<yourwebadaptor>.<yourdomain>/portal/sharing/rest/content/items/<youritemsnearlyendlessandgibberishishID?f=pjson
0 Kudos
Arne_Gelfert
Frequent Contributor

Hold that thought, buster! 

That's some pretty JSON but not at all like the kind I was looking for... which was: 

{ "mapOptions": {}, 
  "operationalLayers": [], 
  "baseMap": [], "
   exportOptions": {}, 
  "layoutOptions": {} }

What's going on here?!

0 Kudos
Arne_Gelfert
Frequent Contributor

Just doing a post-mortem on this one: You can your JSON from esri/tasks/PrintTask, as explained here: Get the WebMap from Javascript API esri/map.

0 Kudos
by Anonymous User
Not applicable

So, it seems you figured it out! I'm trying to do the same things. I already have the first part of the workflow: I have a script that selects what I need. Next is to print out the map along with a summary of several attributes and a legend. My thought is to create a custom print service, but not sure how to incorporate this in my existing script (or, if I should). I really want to limit the number of clicks the user needs to do; ideally, they should be able to click the map, the GP tool should start running, then prompt the user to save a PDF map.

The "ConvertWebMapToArcGISProject" is a little confusing to me, though. I don't need to be able to open the map in ArcMap/Pro. Any thoughts/suggestions?

0 Kudos
Arne_Gelfert
Frequent Contributor

Agree with you, some of the ESRI examples look real straight forward until you try to solve a real world problem. For me it came down creating a GP Service in Python that does what I need with a map saved in APRX project. You can work in Pro or Python until you have that right. Once that's done, you call that services using...Geoprocessor.

Once you have an instance of a geoprocessing service to call and a printTask in Javascript, you can do something like:

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);

Let me know if that helps.

0 Kudos
by Anonymous User
Not applicable

Thanks for your input. We're in the early stages, so I'll let you know when we get this implemented!

0 Kudos