Printing map with ArcGIS JS API is not correct scale

05-16-2019 10:57 AM
New Contributor III


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);
// }  
 //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);
 ], function(PrintTemplate, PrintParameters, PrintTask, SpatialReference, LegendLayer) {
    var urlToThePrintServer = "";
    //Create map title
    var mTitle;
    if (ptitle !== "") {
     mTitle = "Parcel ID: " + ptitle + " Vicinity Map";
    }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 = [{}];
    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);
    //var sr = new SpatialReference(2260);
    //var sr = new SpatialReference(3857);  //map.spatialReference);
    var params = new PrintParameters(); = 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);
Any help is greatly appreciated!
George Hilton
Town of Queensbury, NY
Tags (1)
0 Replies