Solved! Go to Solution.
esriRequest.setRequestPreCallback(function (args) { //do stuff return args; }); this.printTask.execute(this.printParameters, lang.hitch(this, this._print), lang.hitch(this, this._error)); //reset esriRequest.setRequestPreCallback();
esriRequest.setRequestPreCallback(function (args) { //do stuff return args; }); this.printTask.execute(this.printParameters, lang.hitch(this, this._print), lang.hitch(this, this._error)); //reset esriRequest.setRequestPreCallback();
esriRequest.setRequestPreCallback(lang.hitch(this, function (args) { //Web_Map_as_JSON to js obj var json = JSON.parse(args.content.Web_Map_as_JSON); //remove map.graphics json.operationalLayers.splice(arrayUtils.indexOf(json.operationalLayers, this.map.graphics.id), 1); //remove non-print layers arrayUtils.forEach(json.operationalLayers, function (ol) { var layer = this.map.getLayer(ol.id); if (layer._print && layer._print === false) { json.operationalLayers.splice(arrayUtils.indexOf(json.operationalLayers, ol), 1); } }, this); //strip graphic layer attributes and and info templates arrayUtils.forEach(json.operationalLayers, function (ol) { if (ol.featureCollection && ol.featureCollection.layers.length) { arrayUtils.forEach(ol.featureCollection.layers, function (layer) { arrayUtils.forEach(layer.featureSet.features, function (feature) { if (feature.attributes) { delete feature.attributes; } if (feature.infoTemplate) { delete feature.infoTemplate; } }); }); } }); //json to Web_Map_as_JSON args.content.Web_Map_as_JSON = JSON.stringify(json); return args; }));
This is excellent! Exactly what I was looking for.
One small change on line 9. If the _print property is false then the if statement will still evaluate to false. I think it should read:
if (layer.hasOwnProperty('_print') && layer._print === false) {
It looks setRequestPreCallback is not available in the API version 4.x (request | API Reference | ArcGIS API for JavaScript 4.3 )
I am trying to convert my old print task using new 4.x API. Is there any alternate way to retrieve and modify args.content.Web_Map_as_JSON before it call print task?
It is implemented in the API just not documented yet. You can refer back to the 3.x documentation for usage