Print Dijit Template Question

763
9
Jump to solution
09-12-2012 07:57 AM
by Anonymous User
Not applicable
Attempting to specify which layers are to be included in the legend using the Print Dijit Template sample. However the following line of code essentially bombs the app.

var legendLayer = new esri.tasks.LegendLayer();

Any ideas?

Thanks!

RGibson
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor
heres a working jsfiddle (just update reference to use your own proxy)

var poolFeatureLayer = new esri.layers.FeatureLayer(permitUrl, {           "mode": esri.layers.FeatureLayer.MODE_SNAPSHOT,               //make sure the layer you wish to add to the legend includes an id to pass to legendLayers           "id": "PoolPermits"         });  // create a print template for each choice         templates = dojo.map(templateNames, function(ch) {           var plate = new esri.tasks.PrintTemplate();    var legendLayer = new esri.tasks.LegendLayer();    //set the layerId property for legendLayer           legendLayer.layerId = "PoolPermits";     //legendLayer.subLayerIds = [];         plate.layout = plate.label = ch;           plate.format = "PDF";           plate.layoutOptions = {              "authorText": "May by:  Esri's JS API Team",             "copyrightText": "<copyright info here>",             "titleText": "Pool Permits",              "scalebarUnit": "Miles",                          //this property needs to be set with an array of legendLayer objects, not layerIds      "legendLayers": [legendLayer],            };           return plate;         });

View solution in original post

0 Kudos
9 Replies
JohnGravois
Frequent Contributor
try setting a layerId (and optionally subLayerIds) for legendLayers before the object is passed in the layoutOptions

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/printtemplate.htm#layoutOptions

var myLegendLayer = new esri.tasks.LegendLayer();
myLegendLayer.layerId = "Boundaries";
myLegendLayer.subLayerIds = [];

app.printer = new esri.dijit.Print({
          map: app.map,
    templates: [{
    label: "Layout",
    format: "JPG",
    layout: "Letter ANSI A Landscape",
    preserveScale: false,
    layoutOptions: {
      titleText: "My Print",
      authorText: "esri",
      copyrightText: "My Company",
      scalebarUnit: "Miles",
                                  legendLayer: myLegendLayer
    }
     }
    ],
          url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
        }, dojo.byId("printButton"));
       
0 Kudos
by Anonymous User
Not applicable
Thanks, John, for the quick reply. However I can't get to that point.

Just this line of code by itself.....var legendLayer = new esri.tasks.LegendLayer();.....bombs the app.

Thanks!

RGibson
0 Kudos
JohnGravois
Frequent Contributor
where are you placing that line?
can you post a sample application?
0 Kudos
by Anonymous User
Not applicable
Let me re-phrase. It doesn't bomb the entire app but rather the "handlePrintInfo" function.

Problem code is in bold italic

Thanks!
RGibson



function handlePrintInfo(resp) {
        var layoutTemplate, templateNames, mapOnlyIndex, templates; 

        layoutTemplate = dojo.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 = dojo.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 = dojo.map(templateNames, function(ch) {         
          var plate = new esri.tasks.PrintTemplate();

          var legendLayer = new esri.tasks.LegendLayer();


          plate.layout = plate.label = ch;
          plate.format = "PDF";
          plate.layoutOptions = {
            "authorText": "City of Fort Smith GIS",
            "copyrightText": "Copyright 2012, Fort Smith GIS",
            "legendLayers": [0,1,2,3],
            "titleText": "Chaffee Crossing",
            "scalebarUnit": "Feet"
          };
          return plate;
        });
0 Kudos
JohnGravois
Frequent Contributor
heres a working jsfiddle (just update reference to use your own proxy)

var poolFeatureLayer = new esri.layers.FeatureLayer(permitUrl, {           "mode": esri.layers.FeatureLayer.MODE_SNAPSHOT,               //make sure the layer you wish to add to the legend includes an id to pass to legendLayers           "id": "PoolPermits"         });  // create a print template for each choice         templates = dojo.map(templateNames, function(ch) {           var plate = new esri.tasks.PrintTemplate();    var legendLayer = new esri.tasks.LegendLayer();    //set the layerId property for legendLayer           legendLayer.layerId = "PoolPermits";     //legendLayer.subLayerIds = [];         plate.layout = plate.label = ch;           plate.format = "PDF";           plate.layoutOptions = {              "authorText": "May by:  Esri's JS API Team",             "copyrightText": "<copyright info here>",             "titleText": "Pool Permits",              "scalebarUnit": "Miles",                          //this property needs to be set with an array of legendLayer objects, not layerIds      "legendLayers": [legendLayer],            };           return plate;         });
0 Kudos
by Anonymous User
Not applicable
Once again, thanks John.

However that line of code mentioned above var legendLayer = new esri.tasks.LegendLayer(); isn't agreeable anywhere in my application for some reason. The error is "called_non_callable".

If I place that line of code, and only that single line of code, into the otherwise working sample, it bombs.

RGibson
0 Kudos
by Anonymous User
Not applicable
Ugh....figured it out, John.

I had forgotten to include. Still trying to use the 2.7.
 
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1"></script>

Thanks for your help..

RGibson
0 Kudos
JohnGravois
Frequent Contributor
if you can post a sample app, i would be happy to take a look.
0 Kudos
JohnGravois
Frequent Contributor
missed your last post.  glad to hear it. 🙂
0 Kudos