Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(["esri/tasks/PrintTemplate", "esri/tasks/LegendLayer", "esri/tasks/PrintTask", "esri/tasks/PrintParameters"],
- function (PrintTemplate, LegendLayer, PrintTask, Printparameters) {
- $("#print-progress").show(); //Printing is usually async and takes a while, show some progress
- map.getLayer("layer0").setVisibility(false); //Hide any layers you don't want to show up in the map, in this case the base map
- var printTemplate = new PrintTemplate();
- printTemplate.format = $("#print-format").val(); //[pdf | png | png8 | jpg | gif | eps | svg | svgz]
- printTemplate.layout = $("#print-template").val(); //The file name of a layout template in the server’s print template directory, you can generally count on MAP_ONLY, A3 Landscape, A3 Portrait, A4 Landscape, A4 Portrait, Letter ANSI A Landscape, Letter ANSI A Portrait, Tabloid ANSI B Landscape and Tabloid ANSI B Portrait to be there.
- printTemplate.preserveScale = true; //Yep
- printTemplate.showAttribution = false; //Show the imagery sources
- printTemplate.exportOptions = { dpi: Number($("#print-dpi").val()) }; //DPI
- //Here we want to set up our legend.. generally we want to exclude the legend for things like base imagery layers and such (the RGB legend one)
- var legendLayers = [];
- for (var layer in layers) { //Layers here is an object of key value pairs where the key is a name and the value is a reference to an esri Layer
- if (layers[layer] == layers.RentonImagery || layers[layer].visibleLayers == [-1]) //Exclude the layers we don't want in there.. including layers that aren't visible (have visible layers set to -1)
- continue;
- //Do add the ones we want to appear in the legend
- var legendLayer = new LegendLayer();
- legendLayer.layerId = layers[layer].id;
- legendLayers.push(legendLayer);
- }
- printTemplate.layoutOptions = { titleText: "Boeing Renton Environmental Data Management System", legendLayers: legendLayers } //Other options include authorText, copyrightText, scalebarUnit, legendLayers(esri.tasks.LegendLayer[]), customTextElements (object[])
- var printTask = new PrintTask(exportURL, { async: true }); //export url is the url of the print service, something like https://gis1imcloud1.amec.com/arcgis/rest/services/7622/SecurePrint/GPServer/Export%20Web%20Map
- var printParams = new PrintParameters();
- printParams.map = map; //Yep
- printParams.outSpatialReference = map.spatialReference; //Yep
- printParams.template = printTemplate; //Yep
- var success = function (result) {
- //Result will have a url attribute with the location of the exported map
- $("#print-progress").hide();
- $("#print-tool").modal("hide");
- window.open(result.url);
- };
- var fail = function (error) {
- //Error handling
- $("#print-progress").hide();
- $("#print-error").text("Failed to print.");
- $("#print-error").show();
- };
- printTask.execute(printParams).then(success, fail); //Finally make the call
- map.getLayer("layer0").setVisibility(true); //Turn our basemap/other layers back on
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement