Select to view content in your preferred language

Printing selected features using a custom report template

207
3
Jump to solution
2 weeks ago
BrittaneyHarkness
Occasional Contributor

Hi,

I am trying to print using a custom report template built using ArcGIS Pro. The goal of the report template is to display a map of a selected parcel and attributes describing the property.

The datasource is a large parcel dataset that is consumed in a custom javascript application that uses the print component. I followed directions to create the report template and publish a new print service with the template as a report option. In my app I am able to update the reportOptions "sourceId" to point to my parcel layer and then pass the updates to the print component as a printTemplate. 

 

My Question: Is there anyway to pass a definition query or a filter as a report option to only display a selected feature in my source layer instead of everything in view? Or do I have to apply the definition query directly my source layer? 

 

thanks,

Britt

 

@Noah-Sager  I watched your presentation from this year's Dev summit. Appreciate all the great info. It really helped to get me started. Any chance this question is in your wheelhouse? 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

The short answer is yes, you can do what you're talking about.  The key to it is implementing a RequestInterceptor that captures the print service request before it's sent, and modifies the request to include the definitionExpression that you want for your request, but not necessarily for the layer presently in your map.  That way you don't have to assign it directly to the layer.

Note, interceptors are added to the "interceptors" property of esriConfig.request.

View solution in original post

3 Replies
JoelBennett
MVP Regular Contributor

The short answer is yes, you can do what you're talking about.  The key to it is implementing a RequestInterceptor that captures the print service request before it's sent, and modifies the request to include the definitionExpression that you want for your request, but not necessarily for the layer presently in your map.  That way you don't have to assign it directly to the layer.

Note, interceptors are added to the "interceptors" property of esriConfig.request.

BrittaneyHarkness
Occasional Contributor

Joel, thank you for the direction and helpful links. I'll give it a try.

 

-Britt

0 Kudos
BrittaneyHarkness
Occasional Contributor

Joel, I added this to my print component in my app and it did the trick. Thanks again!

 

esriConfig.request.interceptors.push({

            urls: config.print_service_url,
         
            before: (params) => {
                const query = params.requestOptions?.query;
                console.log("request query: ", query)
                if (query) {
                   
                    const webMapParam = query.Web_Map_as_JSON
           
                    if (webMapParam) {
                    const webMap = JSON.parse(webMapParam);
           
                    // Modify the operational layers by adding a
                    //definiton query to the parcel layer
                    const operationalLayers = webMap.operationalLayers
                    webMap.operationalLayers = operationalLayers.map((layer) => {

                        if(layer.id === sourceId){
                            console.log("applying defintion expression to: ", layer.id, expression)
                            layer.layerDefinition.definitionExpression = expression
                        }

                        return layer
                    })
 
                    params.requestOptions.query.Web_Map_as_JSON = JSON.stringify(webMap);
                    }
              }
            },
         
            after: (response) => {
              console.log("Modified print response", response);
              return response;
            }
        });