How to printout the current map view?

493
23
03-01-2019 12:48 PM
CarlTownsend1
New Contributor III

I'm trying to add a map printout functionality to my javascript 3.27 based map, and I've got a problem with the print functions. In the print script code there is this:

......
        Printapp.map = new esri.Map
  ("map",
  {
          basemap: "topo",
         center: [-102, 54.75],
          zoom: 6,
         slider: false
       }
 );

.........
But I already have other script basically to loop through a map service and show the layers with the map type, coordinates and layers on startup. Then I click print, it defaults to this instead of what's on the screen. I can change the zoom level, basemap map type etc. and it will print out the changes instead of what's showing on the screen.

If I comment this bit out, it doesn't work. Basically I just want the print function to print out what's on the current map screen. How do I do this?

Thanks

0 Kudos
23 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

  SO when you run the html in your browser you can hit F12 to open the developer tools and in the developer tools you will see the web console. The console shows any errors you have in your code.

0 Kudos
CarlTownsend1
New Contributor III

My browser console reports the following (When I click the print button):


  

Error: "Unable to complete operation."

    load https://js.arcgis.com/3.27/:1038 _ioSetArgs https://js.arcgis.com/3.27/:88 c https://js.arcgis.com/3.27/:104 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 xhr https://js.arcgis.com/3.27/:93 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 d https://js.arcgis.com/3.27/:140 f https://js.arcgis.com/3.27/:144

Print.js:9:144

    _printError https://js.arcgis.com/3.27/esri/dijit/Print.js:9 hitch https://js.arcgis.com/3.27/:64 _errorHandler https://js.arcgis.com/3.27/:2304 hitch https://js.arcgis.com/3.27/:64 _pendingDfd https://js.arcgis.com/3.27/esri/tasks/PrintTask.js:6 hitch https://js.arcgis.com/3.27/:64 c https://js.arcgis.com/3.27/:104 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 hitch https://js.arcgis.com/3.27/:64 c https://js.arcgis.com/3.27/:104 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 _errorHandler https://js.arcgis.com/3.27/:2304 hitch https://js.arcgis.com/3.27/:64 f https://js.arcgis.com/3.27/esri/tasks/PrintTask.js:13 _errorHandler https://js.arcgis.com/3.27/:2304 hitch https://js.arcgis.com/3.27/:64 error https://js.arcgis.com/3.27/esri/tasks/Geoprocessor.js:14 I https://js.arcgis.com/3.27/:1055 c https://js.arcgis.com/3.27/:104 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 f https://js.arcgis.com/3.27/:1052 c https://js.arcgis.com/3.27/:104 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 errback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 c https://js.arcgis.com/3.27/:105 e https://js.arcgis.com/3.27/:104 callback https://js.arcgis.com/3.27/:106 xhr https://js.arcgis.com/3.27/:93 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 a https://js.arcgis.com/3.27/:109 l https://js.arcgis.com/3.27/:108 k https://js.arcgis.com/3.27/:108 resolve https://js.arcgis.com/3.27/:110 d https://js.arcgis.com/3.27/:140 f https://js.arcgis.com/3.27/:144

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

  Please provide your code for review. If you open this thread (do not attempt to do this from the inbox) then you will see an advanced editor link that you can click on and then you will see an attach link at the bottom of your reply where you can attach your full code.

0 Kudos
CarlTownsend1
New Contributor III

I created a stripped down html document with just two scripts in it, the main map viewer and the print scripts, and replaced my mapservice with this example one:
layer = new ArcGISDynamicMapServiceLayer = ("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapSe..." .......

I also replaced it here:
  var layerUrl = "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapSe...";

and the printout works!

So now I have to figure out why my published mapservice causes the print function to fail.

0 Kudos