Select to view content in your preferred language

PrintTemplate height and width not applied in Print Output

940
5
Jump to solution
10-16-2013 09:01 AM
DK5
by
Deactivated User
I am using a polygon (rectangle) to define a print region in my map.  Before I print, I set the map extent to the extent of the polygon, and in the printTemplate.exportOptions I set the width and height to the polygons extent.getWidth() and extent.getHeight().  However, the output includes some of the map that is beyond the polygon and is not just the polygon extent.  I have preserveScale = true and dpi is 96 (not sure if that makes a difference).

Any ideas or suggestions on what may be going on here?
0 Kudos
1 Solution

Accepted Solutions
JasonZou
Frequent Contributor
You will need to translate the geometry dimension into screen dimension. Here is what I use.

Convert the geometry dimension into screen dimension. geom should be either a polyline or polygon.
var extScreenWidth = map.width * (geom.getExtent()).getWidth() / map.extent.getWidth(); var extScreenHeight = map.height * (geom.getExtent()).getHeight() / map.extent.getHeight();


Then round the numbers to convert into integers, and fed to exportOptions.

printTemplate.exportOptions = {  width: Math.round(extScreenWidth),  height: Math.round(extScreenWidth),  dpi: 96 };

View solution in original post

0 Kudos
5 Replies
JasonZou
Frequent Contributor
Did you set the printTemplate.layout to be "MAP_ONLY"? If so, there should have no problem. I have an app doing exactly the same thing, and I can get the map image showing the exact map area constrained with the drawn rectangle area. The DPI is set to 96. Please note that the exportOptions.width and height only work and required for MAP_ONLY.

If you use other layout options, the map size is determined by the map area defined in the map template you choose. With that, if the map size on the template is different than that on the screen, which is true most of the cases, then the map area you see on the printout will be different than that on the screen.

Hope it helps.
0 Kudos
DK5
by
Deactivated User
Thanks for the response.  I set the layout to be "MAP_ONLY", however it is still off.  I think I am missing something with the width and height here.

When I print with using the height and width of the div the map is hosted in - it prints accurately (what you see on screen matches the print output)
Ex. height: 762, width: 1046

When I change the printtemplate exportoptions width and height to be that of the polyline.getExtent().getWidth() / .getHeight() I am getting numbers like height:1032.669...., width: 1047.011...  These number are much larger than my map div height and width but the polyline is smaller and fits well within the div.  Is there some translation I need to do to convert the geometry extent width and height to screen width and height?
0 Kudos
JasonZou
Frequent Contributor
You will need to translate the geometry dimension into screen dimension. Here is what I use.

Convert the geometry dimension into screen dimension. geom should be either a polyline or polygon.
var extScreenWidth = map.width * (geom.getExtent()).getWidth() / map.extent.getWidth(); var extScreenHeight = map.height * (geom.getExtent()).getHeight() / map.extent.getHeight();


Then round the numbers to convert into integers, and fed to exportOptions.

printTemplate.exportOptions = {  width: Math.round(extScreenWidth),  height: Math.round(extScreenWidth),  dpi: 96 };
0 Kudos
DK5
by
Deactivated User
Yes, that was exactly what I was missing - thank you very much!!!
0 Kudos
JasonZou
Frequent Contributor
Glad to help:) Please consider to mark your question as "Answered" so that other people might find it helpful. Thanks.
0 Kudos