FeatureLayer labels not included in print output from print widget

1812
8
Jump to solution
09-20-2021 06:06 AM
DaveAdams
New Contributor III

I have an application written in 4.20 of the Javascript API using the ES Modules (Angular). The print widget is working fine using an instance of ArcGIS Server 10.9 except that the labels of the points in a featurelayer are not being printed in the output. Each of the 3 points should have a number label. Everything else looks correct in the output pdf against the map view. I have tried changing fonts etc but the labels are not appearing. I wondered if there is anything else obvious in the webmap json which might be preventing them in the output. The featurelayers in the webmap are created on-the-fly from graphics rather than hosted.

I have attached the webmap json as a text file.

Any help would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
DaveAdams
New Contributor III

Finally found the answer to my own question. I found the fix under Print - TemplateOptions. Here I can force the attributes into the webmap json by setting forceFeatureAttributes: true https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Print-TemplateOptions.htm... . It is false by default to reduce the request size but I needed the attribute for labeling. Hopefully that will help anyone else with missing labels in a printout containing a dynamic (rather than hosted) feature layer

View solution in original post

8 Replies
DaveAdams
New Contributor III

I can see the issue is that only one of the attributes of the feature layer have been passed into the json so the labeling attribute is missing so I am trying to figure out what controls the attributes passed through into the webmap json

0 Kudos
DaveAdams
New Contributor III

Update: the only attribute included in the featureSet seems to be the one used in the unique value renderer. I cannot find a way to include other specified attributes in the layer featureSet in the json when the feature layer has been created dynamically from graphics. If not, there is no way to print labels for these feature layers unless the label attribute happens to be the same field as has been included in the webmap json.

0 Kudos
Noah-Sager
Esri Regular Contributor

Hi @DaveAdams, this is an interesting issue. Could you share some code or a test-app that reproduces this behavior? I would like to see how you create the labels for the featureLayer so that they can display but not print. 

Is the behavior any different if you use the ArcGIS Online utility print service?

"https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%..."

 

0 Kudos
DaveAdams
New Contributor III

Hi @Noah-Sager - I have investigated more today and have learnt more about the issue. I have tried multiple print servers (e.g. https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%...) but the problem is all about the content of the webmap json. The problem feature layer labels are defined here and applied to the layer:

const devicesLabelClass = new LabelClass({
      labelExpressionInfo: { expression: '$feature.sequence_no' },
      labelPlacement: 'above-right',
      symbol: {
        type: 'text',  // autocasts as new TextSymbol()
        color: 'black',
        haloSize: 1.5,
        haloColor: 'white',
        font: {  // autocast as new Font()
          size: 10,
          weight: 'bold',
          family: 'Arial',
          style: 'italic'
        }
      },
      maxScale: 0,
      minScale: 25000
    });
 

The problem layer is a dynamic layer loaded from graphics I built from json data. The problem occurs when I have applied a unique-value renderer in the layer which means that the resulting featureSet for the points only includes the geometry and the single attribute which is being used for rendering. The attribute used in the map for labeling i.e. 'sequence_no' is missing and hence the labeling does not work in the print export.

"attributes": {
"device_id_in_source_system": "111"
}

As a contrast there is another dynamic layer (polygons but with the same attributes) in my sample file which has a simple renderer applied and that featureSet includes all the attributes in the feature layer. 

"attributes": {
"OBJECTID": 36,
"crime_ref": "BC-B",
"from_date_time": 1606811400000,
"to_date_time": 1606842000000,
"general_text": "Break-in at Honeysuckle Cottage", etc

If I manually add the attribute into the json for the points then the print service correctly prints the labels.

Really I think the creation of webmap json should detect if there are any labels active on a layer and ensure that attribute is included rather than just the one used for rendering.

Hopefully that explains a little more. I am currently trying a workaround (with some success) by intercepting the file using esriConfig.request.interceptors.push : BeforeInterceptorCallback to try and transfer some attributes i.e. the label attribute from the other layer in the file which luckily matches in schema. Without the other layer I would have nothing to help create some label values.

Cheers

 
0 Kudos
DaveAdams
New Contributor III

Finally found the answer to my own question. I found the fix under Print - TemplateOptions. Here I can force the attributes into the webmap json by setting forceFeatureAttributes: true https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Print-TemplateOptions.htm... . It is false by default to reduce the request size but I needed the attribute for labeling. Hopefully that will help anyone else with missing labels in a printout containing a dynamic (rather than hosted) feature layer

EA_Developer1
New Contributor

any idea how can I make this work through REST service directly? I have tried adding forceFeatureAttribute:true across web map json and also as a separate post request terminal but to no effect.

0 Kudos
Noah-Sager
Esri Regular Contributor

Good work @DaveAdams, thank you for sharing your solution here.

0 Kudos
ShefaliMantri1
New Contributor

Labels still not visible after setting forceFeatureAttribute:true for AGOL secured feature layer.

Feature layer is not created by json data

0 Kudos