4

I have an Esri map, and a print task service, After loading the map, I have added custom graphics on my map, but when I tried to take the screenshot by using JavaScript Print Task (esri.tasks.PrintTask), it is only printing the default map same as it is ArcGIS Server, not printing the programmatically added custom graphics. Here is my code.

this.exportWebMap=function(url,map,width,height){

        var deferred = new Deferred();
        var printTask = new PrintTask(url);
        var attrs={};       
        var template = new PrintTemplate();
        var mapWidth=map&&map.width?map.width:this.currentMap.width;
        var mapHeight=map&&map.height?map.height:this.currentMap.height;
        template.exportOptions = {
            width: mapWidth,
            height: mapHeight,
            dpi: 96 
        };
        template.format = "JPG";
        template.layout = "MAP_ONLY",
        template.preserveScale = false;
        template.showLabels = true;
        template.showAttribution = false;

        template.layoutOptions = {
            "legendLayers": [], // empty array means no legend
            "scalebarUnit": "Miles",
            "copyrightText": "<div>xxx</div>",
        }
        var params = new PrintParameters();

        params.map = map||this.currentMap;
        params.template = template;

        printTask.execute(params, function(success){
            deferred.resolve(success);
        }, 
        function(error){
            deferred.resolve(error);
        });
        return deferred.promise;
    }

Print Task JSON

{
    "geometryType": "esriGeometryPolygon",
    "features": [{
        "geometry": {
            "rings": [
                [
                    [1394673.6791358888, 433055.85258604586],
                    [1394680.201104477, 433069.9998674691],
                    [1394686.46519956, 433083.3777934611],
                    [1394691.6935355663, 433094.899095878],
                    [1394704.8713307232, 433089.2193172127],
                    [1394716.3017540574, 433084.7445886284],
                    [1394727.1435958892, 433080.7009615451],
                    [1394739.709843725, 433076.03791312873],
                    [1394732.3896483928, 433060.93656538427],
                    [1394724.798128143, 433045.49433904886],
                    [1394720.2138197273, 433035.48615697026],
                    [1394708.6295253038, 433040.35196088254],
                    [1394698.9999513924, 433044.4631731361],
                    [1394688.3766130656, 433049.2423630506],
                    [1394677.6417263895, 433053.9851357192],
                    [1394673.6791358888, 433055.85258604586]
                ]
            ],
            "spatialReference": {
                "wkid": 102723,
                "latestWkid": 3735
            }
        },
        "symbol": {
            "color": [255, 26, 26, 255],
            "width": 1,
            "type": "esriSLS",
            "style": "esriSLSSolid"
        }
    }]
 }
5

seems like you are using SimpleLineSymbol for polygon geometry instead use "SimpleFillSymbol" and try, the JSON would look like as mentioned below

{
"geometryType": "esriGeometryPolygon",
"features": [{
    "geometry": {
        "rings": [
            [
                [1394673.6791358888, 433055.85258604586],
                [1394680.201104477, 433069.9998674691],
                [1394686.46519956, 433083.3777934611],
                [1394691.6935355663, 433094.899095878],
                [1394704.8713307232, 433089.2193172127],
                [1394716.3017540574, 433084.7445886284],
                [1394727.1435958892, 433080.7009615451],
                [1394739.709843725, 433076.03791312873],
                [1394732.3896483928, 433060.93656538427],
                [1394724.798128143, 433045.49433904886],
                [1394720.2138197273, 433035.48615697026],
                [1394708.6295253038, 433040.35196088254],
                [1394698.9999513924, 433044.4631731361],
                [1394688.3766130656, 433049.2423630506],
                [1394677.6417263895, 433053.9851357192],
                [1394673.6791358888, 433055.85258604586]
            ]
        ],
        "spatialReference": {
            "wkid": 102723,
            "latestWkid": 3735
        }
    },
    "symbol": {
        "color": [155,
            187,
            89,
            128
        ],
        "outline": {
            "color": [115,
                140,
                61,
                255
            ],
            "width": 1.5,
            "type": "esriSLS",
            "style": "esriSLSSolid",
            "marker": null
        },
        "type": "esriSFS",
        "style": "esriSFSSolid"
    }
}]

}

  • Kudos , You made my day, I was using SimpleLineSymbol to draw polygon. And when i changed it to SimpleFillSymbol , I've got exact web map as printed with added polygons on the map. this.symbol= new SimpleLineSymbol(); this.symbol.setColor(new Color([255,255,0,1])); changed to this this.polySymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([255, 26, 26, 1]),2),new Color([255, 26, 26, 0])); – AhammadaliPK Jul 4 '17 at 18:25
  • 1
    happy to hear, cheers!!! – Shamnas Pc Jul 5 '17 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.