PrintTask

549
0
04-14-2013 07:03 AM
DennisHunink
New Contributor III
I did posted a similar question earlier, but it seems I can't delete that one. I there presented code with a couple of other issues.

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);
0 Kudos
0 Replies