JordanBaumgardner_GIS

PrintTask Issues - Javascript 4.3 SDK

Discussion created by JordanBaumgardner_GIS on Apr 13, 2017
Latest reply on Oct 30, 2017 by ubatsukh-esristaff

After many hours of looking at this, I think I'm brave enough to call these issues bugs in the Javascript 4.3 SDK

 

I have found workarounds (included below) for the following issues.

Bug #1
-- in PrintTask._setPrintParams(), the resulting Web_Map_as_JSON does not include MapView.rotation

Bug #2
-- in PrintTask._setPrintParams(), the resulting Web_Map_as_JSON does not include a visibleLayers []. For some layers, the GP service does not respect sublayer visibility. I have not determined what the difference is between those that work and those that do not.

Bug #3
-- in PrintTask._setPrintParams(), the resulting Web_Map_as_JSON graphic point layers symbols do not have a style attribute.  Web_Map_as_JSON -> Graphics layer -> Points -> Symbols -> Style missing

 

 

My Workaround

 

wapp.objects.CustomPrintTask = EsriPrintTask.createSubclass({
      execute: function (a, b) {
            internalPrintPrams = this._setPrintParams(a);

            // parse current esri version
            var mapJson = JSON.parse(internalPrintPrams.Web_Map_as_JSON);

            // add rotation
            mapJson.mapOptions.rotation = -1 * a.view.rotation;

            // create visibleLayers node
            $(mapJson.operationalLayers).each(function (opIdx, opLayer) {
                  var visibleLayers = [];
                  $(opLayer.layers).each(function (subIdx, subLayer) {
                        visibleLayers.push(subLayer.id);
                  });
                  opLayer.visibleLayers = jQuery.makeArray(visibleLayers);
            })// for each Operational Layer

            // Remove empty layers
            mapJson.operationalLayers = jQuery.grep(mapJson.operationalLayers, function (layer, idx) {
                  return ((layer.visibleLayers.length > 0)
                        || ((layer.featureCollection) && (layer.featureCollection.layers) && (layer.featureCollection.layers.length > 0)));
            }); // grep Operational Layers

            // Add "style": "esriSMSCircle", to draw features that don't have it
            jQuery.each(mapJson.operationalLayers, function (opIdx, opLayer) {
                  if ((opLayer.featureCollection)&&(opLayer.featureCollection.layers) && (opLayer.featureCollection.layers.length > 0)) {
                        jQuery.each(opLayer.featureCollection.layers, function (featureSetIdx, featureSet) {
                              jQuery.each(featureSet.featureSet.features, function (featureIdx, feature) {
                                    if ((feature.symbol)&&(!feature.symbol.style)) {
                                          feature.symbol.style = "esriSMSCircle";
                                    }
                              }); // for each featureSet
                        });
                  }
            }); // for each opLayer, add style to symbols that don't have it

            internalPrintPrams.Web_Map_as_JSON = JSON.stringify(mapJson);
            return this._geoprocessor["async" === this.mode ? "submitJob" : "execute"](internalPrintPrams, b)
                  .then(this._handleExecuteResponse)
      }
});

Outcomes