PrintTask. Bug with layer definitions and/or standardized queries?

2356
3
06-23-2014 10:07 PM
TimCollyer
Occasional Contributor
I'm using JSAPI 3.8 on AGS10.2.1.

I'm creating a very simple print task like this

var url = configuration.servicesHome + "/Utilities/PrintingTools/GPServer/Export Web Map Task";


console.log(url);


var template = new PrintTemplate();
template.layoutOptions = {
        titleText: "Selected Work",
        legendLayers: []
        
};
template.format = "PDF";
template.layout = "A4 Landscape";
template.exportOptions = {
        width: 1024,
        height: 786,
        dpi: 96
};


var params = new PrintParameters();
params.template = template;
params.map = map;


showLoading();


var printTask = new PrintTask(url);
printTask.execute(params, function(results){
    window.open(results.url);
    hideLoading();
});


If I check the request, I get a value for Web_Map_as_JSON that looks like this...

{
    "mapOptions": {
        "showAttribution": true,
        "extent": {
            "xmin": 503082.44985599886,
            "ymin": 6944909.337356286,
            "xmax": 503759.78454400157,
            "ymax": 6945403.050843714,
            "spatialReference": {
                "wkid": 28356,
                "latestWkid": 28356
            }
        },
        "spatialReference": {
            "wkid": 28356,
            "latestWkid": 28356
        },
        "scale": 1999.9999999999995
    },
    "operationalLayers": [{
        "id": "layer2",
        "title": "layer2",
        "opacity": 1,
        "minScale": 1000000,
        "maxScale": 200,
        "url": "http://gisapps/ArcGIS/rest/services/gis_cache_prd/MapServer"
    },
    {
        "id": "layer3",
        "title": "layer3",
        "opacity": 1,
        "minScale": 1000000,
        "maxScale": 200,
        "url": "http://gisapps/ArcGIS/rest/services/gis_client_prd/MapServer"
    },
    {
        "id": "layer4",
        "title": "layer4",
        "opacity": 1,
        "minScale": 500000,
        "maxScale": 0,
        "url": "http://gisapps/arcgis/rest/services/work_orders_prd/MapServer",
        "visibleLayers": [1,
        3,
        4,
        5,
        6,
        7],
        "layers": []
    },
    {
        "id": "graphicsLayer5",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    },
    {
        "id": "graphicsLayer6",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    },
    {
        "id": "graphicsLayer7",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    },
    {
        "id": "graphicsLayer8",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    },
    {
        "id": "graphicsLayer9",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    },
    {
        "id": "map_graphics",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": [{
                "layerDefinition": {
                    "name": "pointLayer",
                    "geometryType": "esriGeometryPoint"
                },
                "featureSet": {
                    "geometryType": "esriGeometryPoint",
                    "features": [{
                        "geometry": {
                            "x": 503421.1172000002,
                            "y": 6945156.1941,
                            "spatialReference": {
                                "wkid": 28356,
                                "latestWkid": 28356
                            }
                        },
                        "attributes": {
                            "SITE_SUN": 1529778
                        },
                        "symbol": {
                            "color": [0,
                            255,
                            0,
                            64],
                            "size": 13.5,
                            "angle": 0,
                            "xoffset": 0,
                            "yoffset": 0,
                            "type": "esriSMS",
                            "style": "esriSMSSquare",
                            "outline": {
                                "color": [0,
                                255,
                                0,
                                255],
                                "width": 0.75,
                                "type": "esriSLS",
                                "style": "esriSLSSolid"
                            }
                        }
                    }]
                }
            }]
        }
    }],
    "exportOptions": {
        "outputSize": [1024,
        786],
        "dpi": 96
    },
    "layoutOptions": {
        "titleText": "Selected Work",
        "scaleBarOptions": {
            
        },
        "legendOptions": {
            "operationalLayers": []
        }
    }
}


And the resulting map appears as I expect.

If however I add a layer definition to one of the layers such that the resulting Web_Map_as_JSON is this

// Everything is identical except the layer definition on "layer4" which now looks like this...

//...
    {
        "id": "layer4",
        "title": "layer4",
        "opacity": 1,
        "minScale": 500000,
        "maxScale": 0,
        "url": "http://gisapps/arcgis/rest/services/work_orders_prd/MapServer",
        "visibleLayers": [1,
        3,
        4,
        5,
        6,
        7],
        "layers": [{
            "id": 7,
            "layerDefinition": {
                "definitionExpression": "LAST_SCH_DATE >= date '2014-4-1' and LAST_SCH_DATE <= date '2014-8-31'",
                "layerTimeOptions": null
            }
        }]
    },
// ...


That layer ("layer4") no longer appears on my print map and I can see a "severe" error in my ArcGIS server log which reads "layer4: invalid or corrupt file".

Has anyone else had success adding layer definitions (particularly when using dates and/or other standardized queries) to maps for print tasks?
0 Kudos
3 Replies
Noah-Sager
Esri Regular Contributor
Hi Tim,

Does this map service contain dynamic layers? To check, look in ArcGIS Server Manager and go to the Map Service >> Capabilities under Dynamic Workspaces and see if the checkbox next to "Allow per request modification of layer order and symbology" is selected. Unless you are using this ability, this should not be checked. Server Manager may require a restart for this change to take effect.

Another option to consider is upgrading to AGS 10.2.2.

Hope this helps!

-Noah
0 Kudos
TorrinHultgren2
New Contributor III

Disabling dynamic layers resolves this problem, but it's an unsatisfying fix. Why would having dynamic layers enabled somehow prevent the use of layerDefinition elements in the ExportWebMap schema? This issue still exists at 10.5.1, and the layerDefinition (and definitionExpression) aren't being hand-coded, they're a built-in property of the esri.Map object in the JavaScript API that's passed into the parameters of a esri.tasks.PrintTask. DynamicLayers support definitionExpressions, so why the incompatibility?

0 Kudos
DuarteCarreira
Occasional Contributor II
0 Kudos