Great! I got your attention…
There are good and bad news. The bad news is that – inherently printing service does not support popups. Popups are client side UI controls to display attributes for selected features. Sometimes attributes are not even shown in popups controls, instead they are shown on a tabular grid or some other way that a web designer prefers. Often when we ask about ‘printing popups’, we mean print the map and ‘attributes of the feature(s) that are selected or queried on the map’.
Good news is that there are solutions. The post is about sharing two alternatives to tackle the issue.
Option #1: Using CustomTextElements and Web Application Builder Print Widget
This approach is simple and helpful in cases like when you want to print map with few information such as address, owner name, parcel-id for the selected parcel. And you need to define a layout for a specific layer or a specific task – it not meant to be applicable generically for all purposes.
Here is what needs to be done to achieve that:
a) Add CustomTextElements in the layout
CustomTextElements are text elements on the layout with names. To add a CustomTextElement in ArcMap layout…
- Choose Text from Insert menu.
- Open the Properties page of the text element.
- Switch to Size and Position tab.
- Enter a name in Element Name.
- Click OK button.
- Repeat to add more text element as needed.
- Finish rest of the layout design.
b) Publish (or republish) a custom printing service with Get Layout Templates Info task
Get Layout Templates Info task is an arcpy script that gets installed as part of 10.4. For previous versions, you can download the script from GitHub.
Step by step instructions are provided in ArcGIS Server help to publish a custom printing service with Get Layout Templates Info task.
c) Use Print Widget in the Web Application Builder
Once you setup a print widget to use your custom printing service published in the previous section, the widget retrieves available CustomTextElements for each layout template by calling into Get Layout Templates Info task.
When you choose a layout with CustomTextElements on the Print widget, they appear in the Advanced drop-down allowing users to enter new values for those CustomTextElements. Fill them up and click Print, the widget will include CustomTextElements name-value pairs in the request to the printing service and the service updates those text elements with those values passed in and returns the output.
While this approach is very simple and no programming required, it has few challenges:
- It is very much tied to a particular layer or task.
- It requires manually data entries
- This will not work when there are more than one features are selected.
That leads to the 2nd option.
Option#2: Use custom ArcPy based Printing Service
Please Note: Due to an accidental side effect of an optimization that went in to ArcGIS API for JavaScript 3.21, this approach is not going to work for mapImage (aka dynamic map service) layer in ver 3.21, 3.22 and 3.23, and all client applications use one of these JS API versions – such as Web Application Builder’s (WAB) Print Widget that comes as part of ArcGIS Enterprise 10.6.
JS API v. 3.24 introduced a new option that allows a client application to control whether requests going to a print service includes attributes or not. WAB Print Widget is enhanced with this option in ArcGIS Online June 2018 release.
This is more flexible approach but requires python programming. The basic idea is that:
- On your web application,
- Query or Identify results need to be stored in client side graphics layer for a mapImage layer (aka dynamic map service layer),
- for feature layer, perform selection using SelectFeatures() function or widgets like WAB’s Select widget
- Print task or widget is executed:
- and forceFeatureAttributes is set to true, it includes attributes with all graphics, that are stored in graphic layers, in the request that goes to the printing service.
- for selection on a feature layer, it includes object ids for selected features.
- Printing service that is powered by an arcpy script needs to:
- Read all features from all or any specific operational layer (graphic layer is a type of operational layer with featureCollection and no URLs).
- for feature layer with selection objectids, attributes need to be retrieved from the source map or feature service submitting a query request.
- Add one text element for each attributes (or concatenate all attributes and add that in a single text box element) on the layout.
- If they don’t fit on a single page, use a separate layout template (aka mxd) where the map element is moved outside of the page and add text elements on that layout.
- Once done, export them all into separate pdf files.
- Call ConvertWebMapToMapDocument arcpy function to get a MapDocument object off the WebMap JSON.
- Export the map document in to a pdf.
- Finally combine them all in a single pdf file and sends the url of the output back to the client.
- Read all features from all or any specific operational layer (graphic layer is a type of operational layer with featureCollection and no URLs).
Note: for more information about creating an arcpy based printing, visit Server help.
A sample script tool with instructions and template mxds can be downloaded from http://www.arcgis.com/home/item.html?id=75bdfb3701c04ed8878e2ee561f291c4.
Here is what a sample output would look like:
Happy popup printing!!
Article Discussion: