AnsweredAssumed Answered

Arcgis Javascript api 3.17 printing and legend rendered values not shown

Question asked by thabomoj on Oct 4, 2016

Printing issue using Arcgis Javascript api 3.17.  I have created a custom print template. everything is working fine when creating a smart mapping classbreaks render . eg 

NB printing is working fine with this function , 

function createRenderer(field) {console.log("create renderer: " + field);
//smart mapping functionality begins
smartMapping.createClassedColorRenderer({
"layer": layer,
"field": field,
"basemap": "gray", //map.getBasemap(),
"classificationMethod": "quantile"
}).then(function (response) {
layer.setRenderer(response.renderer);
createLegend(field);
//printMap()
layer.redraw();
});
}

the problem arise  when using a geostats.js api to create class break render the the legend doesn't updated or show values.

Any ideas what might be causing this issue.

code for geostats.js 

function createClassBreaksRenderer(renderLayer, fieldValues, field) {
var renderer = new ClassBreaksRenderer(null, field);

//get class breaks
var classBreaks = getClassBreaks(fieldValues); // this must be jenks

//loop through class breaks until the second last one
for (i = 0; i < classBreaks.length - 1 ; i++) {
//add class breaks to renderer and set the color
renderer.addBreak(classBreaks[i], classBreaks[i + 1], new SimpleFillSymbol().setColor(new Color(rendering.featureMap.color[i])));
}

setRenderer(renderLayer, renderer, field);

//createLegend(field);
}

function getClassBreaks(fieldValues) {
var numClasses = 5; //number of class breaks

//make sure the number of class breaks is less than the number of field values
if (fieldValues.length <= numClasses) {
numClasses = fieldValues.length - 1;
}

//use geostats api
var serie = new geostats(fieldValues);
serie.setPrecision(0);
serie.silent = true;

//get Jenks class breaks
var classBreaks = serie.getClassJenks(numClasses);

return classBreaks;
}

 

//Print Function 

function printMap() {

var StatslegendLayer = new esri.tasks.LegendLayer();// Get the legend Layers
var legendLaye = []
StatslegendLayer.layerId = layer.id;
legendLaye.push(StatslegendLayer);

alert(layer.url);
alert(layer.id);
alert(layer.name);
for (var j = 0, jl = map.layerIds.length; j < jl; j++) {
var currentLayer = map.getLayer(map.layerIds[j]);
alert("id: " + currentLayer.id);
}
var printMap = new esri.tasks.PrintTask("http://ourserver:6080/arcgis/rest/services/ExportWebMap9/GPServer/Export%20Web%20Map");
var params = new esri.tasks.PrintParameters();
var template = new esri.tasks.PrintTemplate();
var txtmetadata = document.getElementById("metadata").innerHTML;
var len = 35;
var curr = len;
var prev = 0;
alert(txtmetadata);
output = [];
var textmetaadat;
if (txtmetadata.length > 35)
{
while (txtmetadata[curr]) {
if ( txtmetadata[curr++] == ' ') {
output.push(txtmetadata.substring(prev, curr).trim());
prev = curr;
curr += len;
}
}
output.push(txtmetadata.substr(prev).trim());
var joinedtxt = output.join('\n')
alert(joinedtxt);
textmetaadat = "Metadata : " + "\n" + joinedtxt;
}
else
{
textmetaadat = "Metadata : " + "\n" + document.getElementById("metadata").innerHTML;
}
template.exportOptions = { dpi: 96 };
template.format = "pdf";
template.layout = "Letter ANSI A Landscape6";

template.preserveScale = true;
template.showAttribution = false;
template.layoutOptions = {
legendLayers: legendLaye, // empty array means no legend
scalebarUnit: "km",
customTextElements: [
{ metadata: textmetaadat }
]
};
params.map = map;
params.template = template;
printMap.execute(params, printResult);
params.map = null
params.template = null
legendLayer.id = " ";

};

Outcomes