Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using the PrintTask() function from the ArcGIS Online API. Works like a charm...untill you add your own graphics.

When I don't run the addedAskedSymbolsToMap function in the code below, and only have one feature layer, then the print is perfectly created. When I do run it, i'm adding custom symbols. The console shows the following error:

"Error performing execute operation"

What's the deal with custom graphics and PrintTask, how should I adjust the code below to something that's okay with the PrintTask function?

Here's the code:

dojo.require("dijit.dijit"); // optimize: load dijit layer
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("esri.map");
    dojo.require("esri.graphic");
    dojo.require("esri.symbol");
    dojo.require("esri.layers.FeatureLayer"); 
    dojo.require("dijit.layout.TabContainer");
    dojo.require("esri.tasks.query");
    dojo.require("esri.dijit.Print");
    dojo.require("esri.tasks.PrintTask");

    var map;
    var testedArea = 'nederland';
    var basemapUrl = "http://tiles.arcgis.com/tiles/nSZVuSZjHpEZZbRo/arcgis/rest/services/Topografie_in_de_klas_"+testedArea+"_ondergrond/MapServer";
    var featureLayerUrl = "http://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Topografie_in_de_klas_"+testedArea+"/FeatureServer/0";
    var printUrl = "http://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";

    function init(){
        esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
        var initialExtent = new esri.geometry.Extent({"xmin":127181.62867976735,"ymin":6618002.046143801,"xmax":1141291.3011197727,"ymax":7298584.615330108,"spatialReference":{"wkid":102100}});
        map = new esri.Map("map", {
            extent: initialExtent,
            //zoom: 2
        });
        dojo.connect(map, "onLoad", doQueries);
        //dojo.connect(map, "onLoad", createPrint);
        map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer(basemapUrl));
    }

    function doQueries(){

        content = 'Cito100_onderdeel=1';
        queryContentSelect = new esri.tasks.Query();
        queryContentSelect.returnGeometry = true;
        queryContentSelect.outFields = ["Type", "NAME"];
        queryContentSelect.where = content;
        var featureLayer = new esri.layers.FeatureLayer(featureLayerUrl,{
            mode: esri.layers.FeatureLayer.MODE_SELECTION,
            outFields: ["*"]
        });
        map.addLayer(featureLayer);
        //featureLayer.clearSelection();
        featureLayer.selectFeatures(queryContentSelect, esri.layers.FeatureLayer.SELECTION_NEW);

        //Set the content of the graphicsLayer selection
        var queryGraphicsTask = new esri.tasks.QueryTask(featureLayerUrl);
        var queryGraphicsSelect = new esri.tasks.Query();
        queryGraphicsSelect.returnGeometry = true;
        queryGraphicsSelect.outFields = ["Type", "NAME"];
        queryGraphicsSelect.objectIds = [1,12,14,15,24,25,89, 20];
        queryGraphicsTask.execute(queryGraphicsSelect, addAskedSymbolsToMap);
    }

    function addAskedSymbolsToMap(featureSet){
        var graphicsLayer = new esri.layers.GraphicsLayer();
        map.addLayer(graphicsLayer);

        //Add asked places to the graphics layer
        var i =1;
        dojo.forEach(featureSet.features, function(feature) {
            if(feature.attributes.Type == 'Gebied'){
                iconSymbolNumbered = new esri.symbol.PictureMarkerSymbol({
                    "url":"http://tpgrf.nl/testserver/alpha/wp-content/themes/topografieindeklas/style/img/toetsNumberIcons/icon-"+feature.attributes.Type+"-"+i+".jpg",
                    'width':24,
                    'height':24,
                    'xoffset':0,
                    'yoffset': 0});
            }else{
                iconSymbolNumbered = new esri.symbol.PictureMarkerSymbol({
                    "url":"http://tpgrf.nl/testserver/alpha/wp-content/themes/topografieindeklas/style/img/toetsNumberIcons/red/NumberIcon"+i+".png",
                    'width':15,
                    'height':20,
                    'xoffset':0,
                    'yoffset': 10});
            }
            var graphic = new esri.Graphic(feature.toJson());
            graphic.setSymbol(iconSymbolNumbered);
            graphicsLayer.add(graphic);
            //map.graphics.add(graphic);
            i++;
        });
        createPrint();
    }

    function createPrint(){
        //Set up print stuff
        var printTask = new esri.tasks.PrintTask(printUrl);
        var params = new esri.tasks.PrintParameters();
        var template = new esri.tasks.PrintTemplate();

        params.map = map;
        template.exportOptions = {
            width: 595,
            height: 842,
            dpi: 96
        };
        template.layout = "MAP_ONLY";
        template.preserveScale = false;

        params.template = template;

        //dojo.connect(map, "onLoad", function() {//Fire the print task
        //printTask.execute(params, printResult, printError);
        setTimeout(function(){printTask.execute(params, printResult, printError);},2500);
    }

    function printResult(result){
        console.log(result.url)
    }
    function printError(result){
        console.log(result);
    }

    dojo.addOnLoad(init);
share|improve this question
    
which version you are using for ArcGIS Server (10 or 10.1) and JSAPI (3.1or 3.3). I would recommend you to use sample reset services as mentioned in the examples and then try (some times print task does nor support 10.0 version) and please put your code in JSFiddle so it will easy to debug. thanks –  Sunil Apr 22 '13 at 5:03
    
The server is om 10.11, i'm using API verse 3.4. So that shouldn't be the problem. I've browsed through the samples, like developers.arcgis.com/en/javascript/jssamples/… but can't find the 'reset services' that you mentioned. What do you mean by that? A Fiddle isn't gonne work for the printtask, see jsfiddle.net/zKzcA –  Dennis Hunink Apr 22 '13 at 8:23
    
sorry it was REST (not 'reset' spelling mistake) service..I will check JSFiddle and let you know ..thanks.. –  Sunil Apr 22 '13 at 9:35

1 Answer 1

up vote 5 down vote accepted
+50

As far as I know, there's two problems in this code. First one is, both Query and QueryTask doesn't define outputSpatialreference parameters. So this query returns there own spatialreference geometries instead of map's spatialreference.

tasks.Query...
queryContentSelect.outSpatialReference = map.spatialReference;

tasks.QueryTask...
queryGraphicsSelect.outSpatialReference = map.spatialReference;

And second one is so strange. In this case, it's using jpeg file at PicureMarkerSymbol in some places. At this time, such a error was happened. So, I converted these symbols to png file, then error doesn't happened. unfortunately, I'm not sure why printTask won't works with jpeg. But I hope this workaround will helps you.

share|improve this answer
1  
Thanks a Million! The trick was indeed in the combination of the spatialreference, the .png icons and additionally the moment the printTask is started. I had to set the first layer to MODE_SNAPSHOT and fire the PrintTask only onUpdateEnd(); But I wouldn't have figured that out without you're suggestions. Thanks so so much! –  Dennis Hunink Apr 22 '13 at 8:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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