Dear All , i am using arcGIS server 10.0 with java plate form and Flex API 2.3 . , i have only dynamicMapService in my server. 01. i want to export Map in PDF and JPEG (or any image format) format , for converting into pdf m using fxPDF API. i am attacing code which i using to perform task. problem is that m not getting image as m seeing in map control. my map goes to in small size.
02. and i want to also export map with Legend..
Do u have any idea with following code (or any other idea)...Plz help me....
/**************************************/ First Method... /**************************************/
public function exportMap():void{ //http://forums.esri.com/Thread.asp?c=158&f=2421&t=277380 try{ var pdfDoc:HPDF_Doc; var map:Map= FlexGlobals.topLevelApplication.appViewer; const pngDecoder:PNGEncoder=new PNGEncoder(); const fileReference:FileReference = new FileReference(); var layer:ArcGISDynamicMapServiceLayer= FlexGlobals.topLevelApplication.appViewer.dynServLyr; var imageParams:ImageParameters=new ImageParameters(); var responder:IResponder; var mapImage:MapImage=new MapImage(); var downloadURL:URLRequest; //var fileName:String = layer.name + ".png"; imageParams.layerOption='show'; imageParams.format=='jpg';
//imageParams.layerIds=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]; Alert.show(layer.visibleLayers.toArray()+'\n\n'+layer.layerDefinitions); imageParams.layerIds=layer.visibleLayers.toArray(); imageParams.layerDefinitions=layer.layerDefinitions; imageParams.width=350; imageParams.height=400; imageParams.transparent=false; //imageParams.extent=map.extent; layer.exportMapImage(imageParams,new AsyncResponder(onResult,onFault)); function onResult(mi:MapImage, token:Object = null):void { mi.extent=map.extent; mi.scale=40; mapImage = mi; downloadURL = new URLRequest(); downloadURL.url = mapImage.href; //Alert.show('Image Href: '+mapImage.href+''); //var request:URLRequest = new URLRequest(downloadURL); //var request:URLRequest = new URLRequest( mapImage.href); var urlLoader:URLLoader =new URLLoader(); var loadedFile:ByteArray; urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete); urlLoader.addEventListener(Event.CANCEL,onURLLoaderCancel); urlLoader.dataFormat=URLLoaderDataFormat.BINARY; urlLoader.load(downloadURL); function onURLLoaderComplete(event:Event):void { loadedFile = event.target.data; pdfDoc=PrintMap.run(loadedFile); if ( pdfDoc ) // save to file { //Alert.show("Saving File","Alert"); try{ pdfDoc.HPDF_SaveToStream(); var memAttr : HPDF_MemStreamAttr = pdfDoc.stream.attr as HPDF_MemStreamAttr; memAttr.buf.position = 0; Alert.show("AAA, JPG is created would you like to download it now?", "File Creation Complete",Alert.YES | Alert.NO, null,AlertHandler1,null,Alert.YES); function AlertHandler1(evt:CloseEvent):void{ fileReference.save( memAttr.buf, "Map.pdf" ); } }catch(e:Error){ Alert.show('Error at PDF Saving.\n'+e.message); } }else{ Alert.show("PDF Creation error.","Alert"); } } function onURLLoaderCancel(event:Event):void { Alert.show('Error at URL Loader'); } //fileReference.save(mapImage,fileName); } function onFault(info:Object, token:Object = null):void { Alert.show('Map could not be exported.\n'+info.toString(), "Export Problem"); }