[GIS] How to customize the ArcGIS print legend text using javascript

arcgis-javascript-apiarcgis-serverlegendprinting

Is there a way to customize ArcGIS print service so that it will not print the layer id and the string that is given in ClassBreakRenderer in the legend.

var layer = new FeatuerLayer(url, {
  id: "featureLayerId",
  opacity: 0.5
});

var renderer = new ClassBreakRenderer(null, "columnName");

var legendLayer = new LegendLayer();
lengendLayer.layerId = "featureLayerId";

Best Answer

Intercept the Print request by using the esri/request setRequestPreCallback method. Parse the WebMap String to convert it to JSON. Change your layer id's and stringify back.

esriRequest.setRequestPreCallback(function(ioArgs) {

         if (ioArgs.content && ioArgs.content.Web_Map_as_JSON){ //Intercept Print Call

              var webMapAsJson = ioArgs.content.Web_Map_as_JSON;
              var webMapObj = JSON.parse(webMapAsJson);

              // This is where you do you magic.
              // Loop through webMapObj.operationalLayers.
              // It has the layer id that you want to change

              ioArgs.content.Web_Map_as_JSON = JSON.stringify(webMapObj);
         }

      return ioArgs;          
 });
Related Question