Best method for forming JSON for Export Web Map (Printing) task

6914
11
08-24-2012 12:36 PM
DavidSchuster1
New Contributor II
Hi,

Can anyone suggest the best way to generate the JSON ("Web_Map_as_JSON" parameter) for a call to the REST API for the Export Web Map printing task?  I need to be able to programatically generate the JSON based on a number of changing configuration options.

It seems like I have a few options:
- Manually construct the JSON string myself.
- Create my own set of classes to represent each parameter (mapOptions, operationalLayers, etc), and use JSON serialization.
- Does ESRI already provide a class library that supports this?  ArcGIS Runtime for WPF perhaps?

Here's what I'm trying to do:
I want to create a .NET 3.5 class library (no user interface) that can be called repeatedly by the rest of my application whever a static map image is needed.   The caller will pass in some feature identifier, and my library will use the REST APIs to locate the feature and return the map image zoomed into the feature.

Thanks!
Tags (2)
11 Replies
TanuHoque
Esri Regular Contributor
You should use one of ArcGIS Web APIs' (JavaScript, Silverlight or Flex) PrintTask in conjunction with PrintingTools service from your web app.

Is you application a web app or desktop app?
0 Kudos
DavidSchuster1
New Contributor II
It's a web application but it doesn't actually need to display an interactive map.  Basically, I want the user to be able to select a set of records and click print.  A server-side component would then print a separate zoomed in map for each of the selected records, then return the entire result as a multi-page concatenated pdf document.

What approach do you recommend for this?  I've thought about Server Object Extensions or a custom geoprocessing task, but I'd rather not require the GIS department to install anything on their end.
0 Kudos
KevinGooss
Occasional Contributor
I have the same requirement. I need to fire off a report that contains a map but i do not have a map in my application. I went with the second approach you mentioned - i created my own class structure to replicate what needs to be in the web_map_as_json request and then i serialize that with JSON.NET to create my request.
But as i was creating that code there was a little voice in my head saying, 'you shouldn't have to be doing this, surely they did it for you somewhere'
0 Kudos
DavidSchuster1
New Contributor II
I have the same voice in my head 😄  Seems like there should be a simpler/cleaner way to do this.
0 Kudos
KevinGooss
Occasional Contributor
I think all of the esri samples assume you have the api and a web map.
I kind of like rolling the classes myself because i know what json they will generate.
and i think esri did a good job, in this case, of publishing and documenting the format for the request.
However, mapping the specification to classes in .NET is not as straightforward as it seems when you consider that different types of layers have different request formats. So you have to create a type/subtype relationship to encapsulate the inheritance between properties that all layers have and those of specific layers.
In the end it looks like a tutorial on OOP principles
0 Kudos
DavidSchuster1
New Contributor II
Regarding your comment about OOP Principles, that's exactly what I was thinking...  All the different types and subtypes of operational layers, etc... hello polymorphism! 

Anyway, thanks for confirming that I'm not crazy.
0 Kudos
TanuHoque
Esri Regular Contributor
Thanks David, Kevin.
The whole idea behind the ExportWebMap is that you have map (composed of mapservice, featuresure, graphics etc.) on your web app and you want that map to be printed by exporting it out to a pdf or any other format first.

Since your web applications does not need to have mapping component, it seems like a custom arcpy.mapping based Geoprocesing service might be a viable solution.

Before I can suggest anything specific, I'd appreciate if you could answer the following questions:
1. do you plan to use map service layer(s) in the map document that you want to be exported out to pdf?, OR
2. is it that you have an existing mxd containing all layers pointing to local datasets (e.g. in a fgdb, shapefile, sde etc) that you want to open, zoom into the extent of a feature and export to a pdf?

Kevin:
3. in your report, how do you know what extent the map needs to be zoomed at? is that like your web app knows the extent always and you are planning that to be sent to the ExportWebMap task?

Please keep in mind that ExportWebMap task in PrintingTools service currently does *not* support returning multi-page pdf - it is always single page. If you need to return multi-page pdf, then you need to go with a custom solution.
A side note: arcpy.mapping.ConvertWebMapToMapDocument, as the name suggests, takes the same webmap_json that ExportWebMap task takes and returns a MapDocument objects that you can then export to any format supported using arcpy functions.
0 Kudos
KevinGooss
Occasional Contributor
For my reports i collect business parameters from the user and then i use the js api to get a feature extent based on those params. So i still have the api dependency, just no map.
I then serialize that extent into my homegrown webmap class which serializes just as the js api would.
I think if i was doing it with python i would still need to get those map params to the gp tool.
I like the esri webmap structure as i think it accurately and succinctly defines all of the components needed to print a great map. I just wish there was an easier way to create that format when you don't have a webmap.
0 Kudos
DavidSchuster1
New Contributor II
Kevin's previous comment describes my situation too. 

A few comments of my own...

Here is the flow of my application:
1) In my app, the user selects multiple records from a data grid (no map) and clicks print
2) For each object selected, my application does the following:
[INDENT]a. Directly call the Query Task (REST API) to locate the object on the map - business parameters tell my app which service/layer/field contains the object's identifier
b. Get the object's extent from the query task results
c. Construct the JSON for the export web map request, providing the extent from the previous step - business parameters tell us which services to display, the order, opacity, etc.  And to answer your first question, I am exporting multiple map services into the PDF.
d. Call the export web map task
e. Concatenate the individual PDFs into one document
[/INDENT]
Eventually, I'd like to remove the UI altogether so that the backend of our application can generate these maps automatically for the user.

As Kevin pointed out, we're looking for something to make step 2c easier - i.e. constructing the JSON for the export web map request.  I'm envisioning an ESRI .NET library containing all the classes that make up the web map specification - classes which could then be serialized to JSON.

Geoprocessing service sounds like a possibility, but here are my concerns...
- We work with multiple clients (of varying GIS experience levels), so I'd prefer not to deploy a geoprocessing tool.
- The map service does not contain all of the data from our system so, as Kevin pointed out, I'd still have to get that data/business parameters to the gp tool

Thanks!
0 Kudos