The first question is, is the advice you have provided so far the correct way to implement the end product?
Well the code I inserted does not seem to run. I placed it at the end just before } dojo.addOnLoad(Init);
} dojo.addOnLoad(Init);
var app = {}; app.printUrl = "http://gisprod2/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task";
<div id="print_button"></div> <div id="info"> <a href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/printtemplate.htm">Print templates</a> are generated from the Export Web Map Task's <a href="http://servicesbeta2.esri.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task">Layout_Template parameter</a>. This info is retrieved from the service using <a href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/namespace_esri.htm#request">esri.request</a>. </div> </div>
// get print templates from the export web map task var printInfo = esri.request({ "url": printURL, "content": { "f": "json" } }); printInfo.then(handlePrintInfo, handleError); 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(); plate.layout = plate.label = ch; plate.format = "PDF"; plate.layoutOptions = { "authorText": "Made by: Marion County Information Technology", "copyrightText": "Maps are for display purposes only", "legendLayers": [], "titleText": "Marion County Parks", "scalebarUnit": "Miles" }; return plate; }); // create the print dijit var printer = new esri.dijit.Print({ "map": map, "templates": templates, url: printURL }, dojo.byId("print_button")); printer.startup(); } function handleError(err) { alert(err); console.log("Something broke: ", err); } }
<td align="center" style="width: 40px;" valign="middle"> <button dojotype="dijit.form.ToggleButton" id="imgprint" title="Print Map" onclick="window.print();"> <img style="border:none;" src="images/print.png" alt="Print Map"/> </td>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.