Select to view content in your preferred language

Print Task produces errors

3190
3
06-05-2014 06:34 AM
SaqibAmin2
Deactivated User
The following is the JavaScript function:

function Print() {
      var app = {};
   
      require([
        "esri/map", "esri/layers/FeatureLayer", "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/dijit/Print", "esri/tasks/PrintTemplate",
        "esri/request", "esri/config",
        "dojo/_base/array", "dojo/dom", /*"dojo/parser",*/
        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
      ], function(
        Map, FeatureLayer, ArcGISDynamicMapServiceLayer, 
        Print, PrintTemplate, 
        esriRequest, esriConfig,
        arrayUtils, dom/*, parser*/
      ) {

        //parser.parse();
  
  app.printUrl = "http://www.mapping2.cityoflondon.gov.uk/arcgis/rest/services/Printing/ExportWebMap/GPServer/Export%20Web%20Map";
  
  esriConfig.defaults.io.proxyUrl = "http://vmgisapp02/proxy/proxy.ashx";

   app.map = map;
/*
 app.map = new esri.Map("map");
 var permitUrl = "http://vmgisapp03/arcgis/rest/services/Test4YellowLines/MapServer/0";
        var poolFeatureLayer = new FeatureLayer(permitUrl, {
          "mode": FeatureLayer.MODE_SNAPSHOT
        });
        app.map.addLayer(poolFeatureLayer);
*/

        // get print templates from the export web map task
        var printInfo = esriRequest({
          "url": app.printUrl,
          "content": { "f": "json" }
        });

        printInfo.then(handlePrintInfo, handleError);

        function handlePrintInfo(resp) {
          var layoutTemplate, templateNames, mapOnlyIndex, templates;

          layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {
            return param.name === "Layout_Template";
          });
          
          if ( layoutTemplate.length == 0 ) {
            //alert("print service parameters name for templates must be \"Layout_Template\"");
            return;
          }
          templateNames = layoutTemplate[0].choiceList;
  
          // remove the MAP_ONLY template then add it to the end of the list of templates
          mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");
          if ( mapOnlyIndex > -1 ) {
            var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
            templateNames.push(mapOnly);
          }
  
          // create a print template for each choice
          templates = arrayUtils.map(templateNames, function(ch) {
            var plate = new PrintTemplate();
            plate.layout = plate.label = ch;
            plate.format = "PDF";
            plate.layoutOptions = {
              "authorText": "Made by:  Esri's JS API Team",
              "copyrightText": "<copyright info here>",
              "legendLayers": [], 
              "titleText": "Pool Permits", 
              "scalebarUnit": "Miles" 
            };
            return plate;
          });
          app.printer = new Print({
            "map": app.map,
            "templates": templates,
            url: app.printUrl
          }, dom.byId("print_button"));
          app.printer.startup();
        }
        function handleError(err) {
          alert("Something broke: ", err);
        }
      });
}


When this function is outputted on a html map page, I get Cross Origin errors, these don't stop the code from working??
( Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://vmgisapp03/arcgis/rest/services/Printing/ExportWebMap/GPServer/Export%20Web%20Map/execute. This can be fixed by moving the resource to the same domain or enabling CORS. )

The following error is more worrying:

POST http://www.mapping2.cityoflondon.gov.uk/arcgis/r...ExportWebMap/GPServer/Export%20Web%20Map/execute

Aborted
  60s
init.js (line 157)
RequestTimeoutError: Timeout exceeded


...g"],function(b){return function(m,e,p,n){p=p||Error;var k=function(b){if(p===Err...

I have tested the line.... "app.map = map;"

When I comment out "app.map = map;" and uncomment the code block below it, everything works fine.

The line "app.map=map;" is taking the existing map object from another JS file elsewhere.

It would be great to hear your thoughts.

Thanks,
Saqib.
0 Kudos
3 Replies
SaqibAmin2
Deactivated User
I have realised all my code is "correct", the problem it seems is not in my code but in which basemap I am using.

We are using Bing basemapping, when I switch this off, the printing functions correctly.

Is there anything I can do to allow Bing basemaps to print?
0 Kudos
MuditAgarwal
Occasional Contributor
Hi Saqib,

Please try adding Bing base map as separate base map layer instead of passing map object with base map.

Regards
Mudit
0 Kudos
SaqibAmin2
Deactivated User
Hi Mudit,

I've added the Bing map as a separate basemap layer and I get the following message in console:

"NetworkError: 500 ConnectFailure - http://vmgisapp02/proxy/proxy.ashx?http://dev.virtualearth.net/REST/v1/Imagery/Metadata/road?key=AnH..."

I get the same error when I put the double url in my browser, in this case I checked my proxy.config file and the virtual earth url is already present "http://dev.virtualearth.net/REST/"

The problem is obviously Bing isn't allowed through proxy. I also added the following line "esri.config.defaults.io.alwaysUseProxy = true;" to the code, setting the variable to false ends up giving me a CORS error.

Regards,
Saqib.
0 Kudos