PrintTask not showing GraphicLayer

4473
7
03-12-2015 03:06 AM
BrianCachia
New Contributor II

Hi,

I m trying to export a map with a graphic layer but the graphic layer is not being shown in the PDF exported.

How can I show this graphic layer in the PDF result of the PrintTask?

Thanks

0 Kudos
7 Replies
ChrisSergent
Regular Contributor III

Can you post your code?

0 Kudos
BrianCachia
New Contributor II

This is the click event on the Print button. Notice the visibility setting of the layers. There is also another graphic layer (which I would like to show) that is included within the map but is not shown.

$("#btnPrint").click(function () {

        require(["dojo/dom", "esri/dijit/Print", "esri/tasks/PrintTemplate"

        ], function (dom, Print, PrintTemplate) {

            showLoading();

            RAGMapServer.setVisibility(true);

            pointLayer.setVisibility(false);

            polygonLayer.setVisibility(false);

            polylineLayer.setVisibility(false);

            var printMap = new esri.tasks.PrintTask("http://aphrodite/arcgis/rest/services/Layout/WSC_PRINT_TECH/GPServer/Export%20Web%20Map");

            var params = new esri.tasks.PrintParameters();

            var template = new esri.tasks.PrintTemplate();

            template.exportOptions = { dpi: 96 };

            template.format = "PDF";

            template.layout = "WSC-Print1";

            template.preserveScale = true;

            template.showAttribution = false;

            template.layoutOptions = {

                legendLayers: [],

                scalebarUnit: "Feet",

                titleText: "PIN",

            };

            params.map = map;

            params.template = template;

            printMap.execute(params, printResult);

            function printResult(result) {

                if (result != null && result !== undefined) {

                    RAGMapServer.setVisibility(false);

                    pointLayer.setVisibility(true);

                    polygonLayer.setVisibility(true);

                    polylineLayer.setVisibility(true);

                    $("#btnPrint").empty().append('<i class="fa fa-print"></i><span style="padding-left:7px;">Print Map</span>');

                    window.open(result.url, "_blank");

                }

                hideLoading();

            };

        });

    });

0 Kudos
BryanMc
Occasional Contributor

We've had this issue before as well. Not sure if fixed yet (or if even considered a bug), but the only graphics layer that will print is the map's default graphics layer. Any new graphics layer(s) you create will not print. You will need to copy the features to the default layer, or just use the default. You can change the order of graphics once in the default or add polys, then lines, then points to default to make sure they show on top.

Again, hoping this is fixed as I haven't checked lately, but worth trying the default to make sure.

BrianCachia
New Contributor II

Hi Bryan,

thanks for the tip, just tried this by adding a small for loop to include additional graphics in the map's default graphic layer:

for (var i = 0; i < graphicsLayer.graphics.length; i++)

            {

                map.graphics.add(graphicsLayer.graphics);

            }

Still the graphic did not show up.

0 Kudos
BrianCachia
New Contributor II

Just resolved this issue, my graphic had a very low opacity and did not see it before I removed all other layers from the map lol

0 Kudos
BryanMc
Occasional Contributor

Hi Brian Cachia , did your graphic layer work or did you need to copy to the default layer? Just wondering since haven't tried in a while.

0 Kudos
BrianCachia
New Contributor II

Hi Bryan,

I Just copied my graphics that were within the graphic layer into the map's default graphic layer. Thanks for the tip. The problem with the line was as stated, it had a very low opacity and was barely visible.

0 Kudos