So I tried to add Print function on my arcgis map. It's doesn't work at all. So I tried to start new project and figure it out. It worked fine.
Back to my main project, I realized the errors is came from parser itself. When I comment the parser.parse();
the print function is work but a part of my function didn't work out.
I've tried to add this:
<script> var dojoConfig = { parseOnLoad: false, async: true, tlmSiblingOfDojo: false }; </script>
It doesn't work out.
Here is the print function:
parser.parse(); esriConfig.defaults.io.corsEnabledServers.push("1xx.1xx.xx.xx2:6443"); map = new Map("mapDiv", { // basemap: "satellite", basemap: "topo", center: [118,-1], zoom: 5, sliderStyle: "small" }); printUrl = "https://1xx.1xx.7x.2xx:6443/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map..."; var printInfo = esriRequest({ "url": printUrl, "content": { "f": "json" } }); printInfo.then(dojo.hitch(printUrl,dojo.hitch(map,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": "Author.", "copyrightText": "<copyright info here>", "legendLayers": [], "titleText": "A title", "scalebarUnit": "Kilometers" }; return plate; }); // create the print dijit var printer = new Print({ "map": map, "templates": templates, "url": printUrl }, dojo.byId("print_map")); printer.startup(); } function handleError(err) { console.log("Something broke: ", err); }
How can I make the print function work out without removing parser.parse();
? If I didn't use parser, all my function can't be loaded, and if I use parser, the json can't be sent to server service.