Force scale when printing

2668
7
09-12-2014 08:41 AM
RyanSellman
Occasional Contributor II

Does anyone know how to allow printing at user defined scales?  As it stands right now, I have a drop down list of scale options that match the levels of detail in my basemaps.  It works great, but its somewhat limiting.  I would like to have a text box where folks can type in a scale, then print. 

I assume the only way to do this is to create my own JSON and use it with my printing service, but I have no idea how to do this and haven't seen an example of someone else successfully doing it.  Any ideas?  Maybe there is another way to accomplish this?

Any help/insight is greatly appreciated!!

0 Kudos
7 Replies
RyanSellman
Occasional Contributor II

I found this bit of code while researching this topic and think that it may be a step in the right direction, but I am not sure.  It allows for manipulation of the ExportWebMap JSON, specific to the rotation of the map.  I haven't been able to do it successfully yet, but can I do something similar to this to edit the scale before the process is executed?

Here is the fiddle - Edit fiddle - JSFiddle

0 Kudos
AdrianMarsden
Occasional Contributor III

I've not had any problems here (that I recall) I have a drop down list for scale too, and my print function is below.  It reads in a few extra user stuff, like template, quality, notes (the varibles returned by the various dijit.byId and Dojo.byID).  But seems to work.  I'm sure I did some tweaking, but cannot remember what.

function DoPrint() {

    graphicsClear();

    var legendLayer = new esri.tasks.LegendLayer();

    legendLayer.layerId = "mainmap";

    SelectedTemplate = dijit.byId('templateselect').attr('value');

    vPrintTitle = dojo.byId("PrintTitle").value;

    vPrintComments = dojo.byId("PrintComments").value;

    vQuality = dijit.byId('quality').attr('value');

    var printTemplate = new esri.tasks.PrintTemplate();

    if (SelectedTemplate == "maponly") {

        printTemplate.format = "JPG";

    } else {

        printTemplate.format = "PDF";

    }

    printTemplate.layout = SelectedTemplate;

    printTemplate.exportOptions = {

        width: 2125.98,

        height: 2362.2,

        dpi: vQuality

    };

    // console.debug(printTemplate);

    var layoutOptions = {

        "copyrightText": currentcopyright,

        authorText: vPrintComments,

        titleText: vPrintTitle,

        scalebarUnit: 'Miles',

        legendLayers: [legendLayer]

    };

    printTemplate.layoutOptions = layoutOptions;

    var printParams = new esri.tasks.PrintParameters();

    printParams.map = map;

    printParams.outSpatialReference = map.spatialReference;

    printParams.template = printTemplate;

    var printURL = "http://zzzzzzzzzzzzzzzzzzzzzzzzz/rest/services/PrintService2/GPServer/Export%20Web%20Map";

    var printTask = new esri.tasks.PrintTask(printURL);

    printTask.execute(printParams, function (result) {

        window.open(result.url + "?timestamp=" + (new Date().getTime()), '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=600');

        printbox.hide();

    });

}

0 Kudos
RyanSellman
Occasional Contributor II

Hi Adrian!

Thanks so much for the response!  Are the options in your scale drop down, contingent upon the levels of detail or scales in your basemaps?

Ryan

0 Kudos
AdrianMarsden
Occasional Contributor III

No, as I don't use a tiled base map so I have no set zoom scales (well, actually, my base map is a dynamic service, but that dynamic service has, for most scales, a set of tiles, only lower than 1:3,000 does it then hit the fine detailed vector maps)

So, my pull down just has a list of common scales the users want, plus allows type in of values

0 Kudos
RyanSellman
Occasional Contributor II

I see.  Unfortunately I have to use a few tiled services as basemap options in the app, which limits me to using the scales defined in those basemaps. 

0 Kudos
AdrianMarsden
Occasional Contributor III

mmm - I think the issue will be the fact that the ArcMap side of this may try to get the extent in, rather than prioritize the scale.  beyond me now I'm afraid.

0 Kudos
RyanSellman
Occasional Contributor II

No problem!  I appreciate your help!

0 Kudos