Export to JPEG or PDF using esri.layers.ImageParameters ( constructor )

1459
1
07-01-2010 03:35 PM
DavidAshton
Occasional Contributor III
I'm trying to utilize the esri.layers.ImageParameters - constructor and the mapservice.exportMapImage but I'm having trouble figuring out where my image is saving and how I can grab it.  Can someone take a look at my code and let me know what I'm doing wrong or possibly what I need to add.  I think I'm close.

Here's my code in my JavaScript that is doing the work
function createpdf1() {

//Show progress bar page while waiting
 pdfresultframe.document.location.href = "progressbar.html"  

//making the <div...> or framelayer active/visible: functionpdf3
 activateFunction('pdf3') 

//populate figsize value in pdform in map.asp file
 pagesize = document.pdfform.figsize.value     

//populate orientation value in pdform in map.asp file
 orientation = document.pdfform.orientation.value
 
//populate resolution value in pdform in map.asp file
 resolution = document.pdfform.resolution.value 

//populate printoption value in pdform in map.asp file 
 printoption = document.pdfform.printoption.value 

//populate layoutstyle value in pdform in map.asp file
 layoutstyle = document.pdfform.layoutstyle.value 

//Class hierarchy = esri.layers.ImageParameters - constructor
 //Creates a new ImageParameters object. The constructor takes no parameters
 //http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm
figuresettings = new esri.layers.ImageParameters() 

//Set image formate property could be png | png8 | png24 | jpg | pdf | bmp | gif | svg 
 figuresettings.format = "jpg" 
//set width property Requested image width in pixels
 figuresettings.width = width * resolution  
 //set height property Requested image width in pixels 
 figuresettings.height = height * resolution  
//set Dots per inch setting for an ArcGISDynamicMapServiceLayers
 figuresettings.dpi = resolution    


if (printoption == "honorscale") {
  theOriginalWidth = map.width/96
  theOriginalHeight = map.height/96
  if ((width/height) > (theOriginalWidth/theOriginalHeight)) {
   theFactor = height/theOriginalHeight
  }
  else {
   theFactor = width/theOriginalWidth
  }
  theOriginalExtent = map.extent
  theNewExtent = theOriginalExtent.expand(theFactor)
  figuresettings.bbox = theNewExtent
 }


//exportMapImage - IMapImage exportMapImage(IMapDescription mapDesc,IImageDescription imageDesc)
// Use ExportMapImage to retrieve a file (image or vector format) of the map.
//ExportMapImage to generate an image of the map.The input parameter MapDescription  
//contains properties 
 //http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/mapimage.htm

 mapservice.exportMapImage(figuresettings,createpdf2) 
}


//Use IMapImage to access properties of an ExportMapImage  result. 

function createpdf2(mapImage) {  
             
 document.pdfform.mapimagehref.value = mapImage.href    //URL to returned image.
 document.pdfform.printscale.value = mapImage.scale    ///Scale of requested dynamic map.
 document.pdfform.submit()  // Javascript to submit form / submit call

}                   



In my map.asp page I'm populating a form, here is where I will send my values
<form name="pdfform" method="post" action="createpdf.asp" target="pdfresultframe">   <!--declaring form name and asp action-->
  <input type="hidden" name="mapImagehref"   value="">
  <input type="hidden" name="printscale"   value="">



I guess my question is: is do I actually set the mapimage.href URL and the mapImage.scale info or is this defaulted somehow.  I feel like I'm so close but I'm so confused.

Thanks
David Ashton
0 Kudos
1 Reply
AdamPfister
Esri Contributor
your mapImage variable will hold a URL to where the image was created.  you can pop open a new window with that URL or stream it back to the client to be saved as an image file, etc.

It will also have other properties.  See here for the list: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/mapimage.htm

Can you do some debugging to figure out if the mapImage variable has these properties?
0 Kudos