Printing map with ArcGIS JS API is not correct scale

368
0
05-16-2019 10:57 AM
GeorgeHilton__GISP
New Contributor III

Hello,

I have some code I've written to allow users to print a map.  When the map is printed it is printed at a scale that is not the same as the current map Scale. Here is the code:

function doprintclck() {
 var incleg;
 var tst = $('#legchkbox').prop('checked');
  
 //Set incleg variable based on checked property of legchkbox.  This is used to add or hide legend
 if ($('#legchkbox').prop('checked')) {
  incleg = true;
 }else {
  incleg = false;
 }
  
 var sctxt = $('#inptscale').val();
  
 //Test to see if it is a number
 //TODO Put this into an input function for the input box
 //if (isNaN(Number(sctxt))) {
  //var sc = Math.round(map.getScale() / 12);
  //$('#inptscale').val(sc);
  //return;
// }  
 
 //Get Scale from input box as RF
 var outscale = $('#inptscale').val() * 12;
  
 //Create Print Map
 createprintmap(incleg, outscale);
}
function createprintmap(leg, scl) {
 console.log(leg, scl);
 require(["esri/tasks/PrintTemplate",
          "esri/tasks/PrintParameters",
    "esri/tasks/PrintTask",
    "esri/SpatialReference",
    "esri/tasks/LegendLayer"
 
 ], function(PrintTemplate, PrintParameters, PrintTask, SpatialReference, LegendLayer) {
    var urlToThePrintServer = "https://qbygis.queensbury.net/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
      
    //Create map title
    var mTitle;
    if (ptitle !== "") {
     mTitle = "Parcel ID: " + ptitle + " Vicinity Map";
     console.log(mTitle);
    }else {
     mTitle = "Queensbury Vicinity Map";
    }
   
    //Get visible layers to add to legend
    var legitems = getLegLyrs();
   
   //Create Print Template
   var pt = new PrintTemplate();
   
   //Create Map Legend    
   var ll = new LegendLayer();
   ll.layerId = "layer2";
   //if include legend not checked show no legend
   if(leg != true) {
    ll.subLayerIds = [{}];
   }else{
    ll.subLayerIds = legitems;
   }
       
   //Set Print Template Options
   pt.layoutOptions = {
    titleText: mTitle, //"Title",
    copyrightText: "Map Produced by Queensbury GIS.  Map is for General Reference Purposes Only",
    scalebarUnit: "Feet",
    legendLayers: [ll]
   
   }
   
    pt.format = 'pdf';
    pt.layout = 'Letter ANSI A Portrait';
   
    pt.preserveScale = true;
   
    //Set Scale Here
    pt.outScale = Number(scl);
    console.log(pt.outScale);
   
    //var sr = new SpatialReference(2260);
    //var sr = new SpatialReference(3857);  //map.spatialReference);
   
    var params = new PrintParameters();
    params.map = map;
   
    params.outSpatialReference = map.spatialReference;   //new SpatialReference(102100); 
       
    params.template = pt;
   
    var printTask = new PrintTask(urlToThePrintServer);
    printTask.on("error", function(error) { alert(error.code)});
    printTask.on("complete", openprintmap);
    printTask.execute(params);
    
 });
}
Any help is greatly appreciated!
George Hilton
Town of Queensbury, NY
Tags (1)
0 Replies