How to set titleText 'onPrintStart'?

941
7
Jump to solution
03-04-2013 09:00 AM
AlexGilvarry
New Contributor II
I'm trying to make it so that the user can set their own custom map title when they "print" the current view in the webmap application. However, I'm having trouble getting this to work.

    var template = [{                 label : "Portrait",                 format : "PDF",                 layout : "A4 Portrait",                 exportOptions : {                   width : 200,                   height : 200,                   dpi : 300                 },                 layoutOptions : {                   titleText : mapTitle,                   authorText : " ",                   copyrightText : "Coldwell Banker Commercial",                   scalebarUnit : "Miles",                 },               }, {                 label : "Landscape",                 format : "PDF",                 layout : "A4 Landscape",                 exportOptions : {                   width : 200,                   height : 200,                   dpi : 300                 },                 layoutOptions : {                   titleText : mapTitle,                   authorText : " ",                   copyrightText : "Coldwell Banker Commercial",                   scalebarUnit : "Miles",                 }               }];                           // print dijit               app.printer = new esri.dijit.Print({                 map : app.map,                 templates : template,                 url : "http://2501s-jjohnson:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"               }, dojo.byId("btn"));               app.printer.startup();                   dojo.connect(app.printer, 'onPrintStart', function() {                 mapTitle = prompt("What would you like to title this map?");               });


I'm trying to set the titleText using the mapTitle variable, which the user sets when they click the print button using the dojo.connect 'onPrintStart' event, but this isn't working. i'm pretty sure the titleText is already set in stone by the time the user is prompted to name the map, but i'm not exactly sure what I should be doing so that the template gets the user input from the mapTitle variable. Any guidance would be greatly appreciated!
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Please try this:

      dojo.connect(print, "onPrintStart", function(){         this.templates[0].layoutOptions.titleText = "Hello Map";       });

The array index number is the one in your templates which has the titleText. In your case, just put 0 there since you only have one template.
Hope this helps.

View solution in original post

0 Kudos
7 Replies
JianHuang
Occasional Contributor III
What did you see as the title ?
0 Kudos
AlexGilvarry
New Contributor II
What did you see as the title ?


Nothing. I assume it's reading the variable before I set it to whatever title i need with the prompt and treating the empty variable as an empty string.
0 Kudos
JianHuang
Occasional Contributor III
Please try this:

      dojo.connect(print, "onPrintStart", function(){         this.templates[0].layoutOptions.titleText = "Hello Map";       });

The array index number is the one in your templates which has the titleText. In your case, just put 0 there since you only have one template.
Hope this helps.
0 Kudos
AlexGilvarry
New Contributor II
Please try this:

      dojo.connect(print, "onPrintStart", function(){
        this.templates[0].layoutOptions.titleText = "Hello Map";
      });

The array index number is the one in your templates which has the titleText. In your case, just put 0 there since you only have one template.
Hope this helps.


Great! Thanks! This works perfectly.
0 Kudos
LuciHawkins
Occasional Contributor III
Hi,

I am trying to implement this in my code and I have 10 templates.  What is the correct method for doing that?  I have tried:

dojo.connect(printer, "onPrintStart", function(){
  printTitlep = document.getElementById("printTitle").value;
        this.templates([0,1,2,3,4,5,6,7,8,9]).layoutOptions.titleText = printTitlep;
      });

and I get the error:

TypeError: this.templates is not a function

Thanks,

Luci
0 Kudos
JianHuang
Occasional Contributor III
Luci,

templates is an array, instead of a function. So that it cannot add () along with it. You can use for loop to loop through the array. For example:

var i;
for (i = 0; i < this.templates.length; i++) {
  this.templates.layoutOptions.titleText = printTitlep;
}
0 Kudos
LuciHawkins
Occasional Contributor III
Awesome!  It worked like a charm, Thank you Jian! 

Luci
0 Kudos