PrintTemplate: change map title dynamically?

4536
12
Jump to solution
10-23-2015 01:46 PM
DavidChrest
Occasional Contributor II

Is there a straightforward way for a user to change the map title text when printing a map instead of having it hard coded in the layoutOptions of the PrintTemplate?

I tried the following but did not work.

HTML:

<div id="print_button"></div> Title:
  <input type="text" id="mapTitle" size="5" value="title" style="height: 18px; width:200px; border: 1px solid #759DC0;" />

JS:

var MT = dom.byId("mapTitle").value


  // create a print template for each choice
  templates = array.map(templateNames, function (ch) {
  var plate = new PrintTemplate();
  plate.layout = plate.label = ch;
  plate.format = "PDF";
  plate.showAttribution = false;
  plate.exportOptions = {
  dpi: 150
  };
  plate.layoutOptions = {

  "titleText": MT,
  "scalebarUnit": "Miles"
  };
  return plate;
  });


  // create the print dijit
  printer = new Print({
  "map": map,
  "templates": templates,
  url: printUrl
  }, dom.byId("print_button"));
  printer.startup();
  }

Any help is very much appreciated.

0 Kudos
1 Solution

Accepted Solutions
ChrisSergent
Regular Contributor III

You can edit the map title in my print task: csergent45/gisTemplate · GitHub

View solution in original post

12 Replies
TracySchloss
Frequent Contributor

I'm not using the Print digit, I'm using PrintTask and PrintParameters instead.  It's been a while, but I think I started down that path specifically for increased flexibility like allowing the user to specify a title before printing.   I think the print templates are already created before any print is ever submitted.  Initially, the input field is still blank, and it doesn't allow you to modify the print templates with a new title value when you the print job is submitted.  

There used to be some decent examples using PrintTask and PrintParameters, but so many things have been dropped out of the documentation lately I can say what you might find.

Here is a map I published that has printing based on PrintTask/PrintParameters.  Maybe it will help:

Missouri Legislative Districts

DavidChrest
Occasional Contributor II

Yes, I came across your earlier post. Not sure why examples are being dropped. All the past examples can be found at SDK Downloads | ArcGIS for Developers . Under ArcGIS JS API, select version dropdown on the right, then select "Documentation."

Would be really nice to be able to easily set things up for a user to input a map title. Otherwise, may be better off just having no title at all to prevent a bunch of maps made all with the same title.

0 Kudos
ChrisSergent
Regular Contributor III

You can edit the map title in my print task: csergent45/gisTemplate · GitHub

DavidChrest
Occasional Contributor II

Thanks so much Chris. Looks like you solved this popular problem. Much appreciated. Since, I am about out of time, I need to move on but I'll try your code in my next app, which I need to start soon.

0 Kudos
ClintonBallandis1
Occasional Contributor

Chris thanks for posting this code. The print task is still very useful.

0 Kudos
TracySchloss
Frequent Contributor

Yes, I know you can download them, but in practice, going back into the folder where I have it is a pain.  I dowloaded SDK 3.11, which isn't too far back, but still contains the dropped examples, which I need to go back to periodically.

I'm surprised that the Print widget doesn't have the functionality built in to allow the user to change a title.  I agree a whole bunch of print outs all titled the same, but with different content, isn't that useful.  It doesn't look like there is an event in Print that deals with the act of printing.  It's all just for the creation/destruction of the widget itself.

0 Kudos
ChrisSergent
Regular Contributor III

The link I provided above has the print task modified where you can change the title. Kelly Hutchins​ feel free to add my code; which I had a lot of help with if you want to add it to any samples. All code I post on here is up for grabs by users or Esri.

0 Kudos
DavidChrest
Occasional Contributor II

Chris,

Yes, I see your code but at his point in my project I can't afford the time to completely rework my printing functionality. Your code looks good but looks like a heck of a lot just to be able to enter a map title.

Sure would be nice if I can just pop in a textarea/input, etc:

HTML:

<textarea id="MapTitle" style="width: 200px; height: 18px; border: 1px solid #759DC0;"> </textarea>

Then in JS, simply have:

var MT = document.getElementById("MapTitle").value;

Then in the PrintTemplate layoutOptions:

"titleText": MT

But that "titleText" element simply will not read a variable based on user input, which is easily done when, for example, setting buffer distances.

If MT = "Same Title for Every Single Map," then it appears in the map, but otherwise, nothing appears. Sure would be nice if there were some kind of quick fix for this.

0 Kudos
TracySchloss
Frequent Contributor

I know it's a more code, but I've found that the functions I use for printing are pretty universal.  I haven't had to rework them from one project to the next, I just copy/paste the same few set of functions and make sure I have the divs, input for title etc. 

The other benefit is that you can put breakpoints in the code and see exactly what's happening and when.  With the Print widget, there's not a place for those, or you would see what's happening in the sequence of template creation, print submittal etc.  It helped me to understand what we going on under the hood.

The only thing I can think of to try it to not create any print template or widget until after the user specifies a title.  Then you wouldn't be creating any templates/widgets using input from a field that was initially blank.  You'd have to destroy them or something after each print job, to continue to have the ability to change titles.  That sounds even clunkier than building your own set of printTask functions.

0 Kudos