Why does PrintWidget create Web_Map_as_JSON with explicit geometries for FeatureLayer features?

1899
13
Jump to solution
08-22-2017 12:43 PM
JustinRussell
New Contributor

I'll apologize upfront for the cross post - this has also been asked here. If cross posting is frowned upon I'll be happy to take this down.

I'm using a print widget to get exports of a map view. My view has a number of layers, one of them is a feature layer (in this case, showing US ZIP codes). When I look at the ExportWebMap specification it looks like the syntax for feature layers, I should be able to simply provide object IDs for the features that ought to be displayed in the export. However, when I look at the JSON that's sent to the export service's execute task I see that my feature layer was instead treated as a collection of client side graphics - with full geometries listed instead of object IDs.

Aside from being slow this also causes the export operation to crash when my request payload gets too large.

Any insight as to why my FeatureLayer features might be getting serialized as client side graphics?

I'm using version 4.4 of the ArcGIS API for JavaScript.

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

Justin,

   I am not sure if this has been implemented for the 4.x API but here is a thread on how it is done in 3.x:

setRequestPreCallback on PrintTask 

EDIT: If you look at that thread the very last post says it is implemented in 4.x just has not been documented yet.

ThomasSolow
Occasional Contributor III

20 MB, wow.  Just curious, how many features are being sent?  

I think it's possible that you can send objectIds instead, as it says in the documentation, but (for whatever reason) sending whole features is preferred.

I haven't tried it, but you might be able to tap into your export requests before they're sent using the "setRequestPreCallback" (as Robert mentioned) and replace the features with objectIds before the request is sent.  Another option would be to strip out attributes and other extraneous from the request.  You may not need most attributes (depends on your renderer) or you may be able to delete the attribute property entirely.

I'll see if I can get a sample working to try out objectIds.  

0 Kudos
ThomasSolow
Occasional Contributor III

Here's a sample that strips out each feature layer JSON from the request and replaces it with object ids filtered by the view's extent: JS Bin - Collaborative JavaScript Debugging 

This doesn't seem to work from jsbin, but if you copy the html/js to here: ArcGIS API for JavaScript Sandbox and it works for me.

The specifics of this process might vary for you but the specification does appear to be correct, so you can pass in objectIds rather than entire features.  For this example, the content length went from 169,698 to 11,319 and the image seems the same to me.

I don't know why the JS API sends entire features, but there may be a good reason for it (or not).

JustinRussell
New Contributor

Thanks, Thomas. The number of features being sent varies quite a bit but hovers around 100. The feature layer in question is plotting US ZIP Codes - so while there may not be many features, their geometries can be complex (the vast majority of the request payload is geometry rings). The layer is not set to display at high zoom levels.

Thanks for sharing the link below - that's super helpful. I'll experiment setRequestPreCallback as you demonstrated .

0 Kudos