Error with Print Digit "Cannot read property 'getScale' of undefined "

471
1
03-28-2018 11:07 PM
MuhammadFayaz
Occasional Contributor

I am trying to use the Print digit for using ArcGIS templates for printing. But i am getting an error and cannot fix it. 

Here is my code.

app.printUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%...";

 // get print templates from the export web map task
 var printInfo = esriRequest({
 "url": app.printUrl,
 "content": { "f": "json" }
 });
 printInfo.then(handlePrintInfo, handleError);
function handlePrintInfo(resp) {
 var layoutTemplate, templateNames, mapOnlyIndex, templates;
layoutTemplate = arrayUtils.filter(resp.parameters, function (param, idx) {
 return param.name === "Layout_Template";
 });
if (layoutTemplate.length === 0) {
 console.log("print service parameters name for templates must be \"Layout_Template\"");
 return;
 }
 templateNames = layoutTemplate[0].choiceList;
// remove the MAP_ONLY template then add it to the end of the list of templates
 mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");
 if (mapOnlyIndex > -1) {
 var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
 templateNames.push(mapOnly);
 }
// create a print template for each choice
 templates = arrayUtils.map(templateNames, function (ch) {
 var plate = new PrintTemplate();
 plate.layout = plate.label = ch;
 plate.format = "PDF";
 plate.layoutOptions = {
 "authorText": "Made by: Esri's JS API Team",
 "copyrightText": "<copyright info here>",
 "legendLayers": [],
 "titleText": "Pool Permits",
 "scalebarUnit": "Miles"
 };
 return plate;
 });
// create the print dijit
 app.printer = new Print({
 "map": app.map,
 "templates": templates,
 url: app.printUrl
 }, dom.byId("print_button"));
 app.printer.startup();
 }
function handleError(err) {
 console.log("Something broke: ", err);
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Anyone can please help?

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Muhammad,

   The code you have posted is a copy of the Sample

Print templates with esri.request | ArcGIS API for JavaScript 3.23 

So there is nothing wrong in that portion of the code. It must be something in the rest of your code that is causing the problem.

0 Kudos