本文主要是介绍ArcGIS For Server10.1新特性之-服务器端打印服务及前端调用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ArcGIS For Server10.1新特性之一就是服务器端打印,这个打印功能使用起来非常的方便,因为它是一个现成的GP服务,使用的时候只要输入相应的地图,地图范围,模板的名称等,就可以按需打印出你需要的地图。下面我们来看一下从制作模版到发布服务及服务调用的整个流程吧:
1、自己定义一个打印模板,如下图是布局视图:
将模版保存到C:\Program Files (x86)\ArcGIS\Desktop10.1\Templates\ExportWebMapTemplates(当然你也可以保存到其他路径下,在发布服务的时候你可以指定你自己的路径)
2、在ArcToolBox中打开Export Web Map工具:
输入参数:Web Map as JSON为空;Output File为默认参数;Format可以自己输入;Layout Templates Folder(optional)选择一个模板文件夹(这里选择ArcGIS安装目录的模板文件夹),然后Layout Templates (optional)就可以选择一个默认的模板了
点击OK,打开菜单栏Geoprocessing/Results,执行完成后选中Export Web Map右键Share as Geoprocessing services
下一步、下一步:Analyse后如果没有错误,直接点击Publish发布:
ArcCatalog中查看如下:
3、服务发布好后,可一下在Flex中如何调用一把:ArcGIS Flex API3.0也增加了对该打印服务的支持:
代码如下:print.mxml
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags"xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --></fx:Declarations><fx:Script><![CDATA[import mx.managers.PopUpManager; private function onclick(event:MouseEvent):void{var popWin:printForm = printForm(PopUpManager.createPopUp(this,printForm,false)); popWin.printTask.getServiceInfo();//调用 打印 GP,获取模版和格式参数 popWin.map = this.myMap;}]]></fx:Script><esri:Map id="myMap"> <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/routTest2/MapServer"/></esri:Map><mx:Button id="button" x="409" y="10" label="打印" click="onclick(event)"/> </s:Application>
printForm.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/spark"xmlns:mx="library://ns.adobe.com/flex/mx"xmlns:esri="http://www.esri.com/2008/ags"width="100%" height="100%"close="PopUpManager.removePopUp(this)"><fx:Script><![CDATA[import com.esri.ags.Map;import com.esri.ags.events.PrintEvent;import com.esri.ags.tasks.supportClasses.DataFile;import com.esri.ags.tasks.supportClasses.JobInfo;import com.esri.ags.tasks.supportClasses.ParameterValue;import com.esri.ags.tasks.supportClasses.PrintServiceInfo;import com.esri.ags.tasks.supportClasses.LegendOptions;import com.esri.ags.tasks.supportClasses.LegendLayer;import mx.collections.IList;import mx.controls.Alert;import mx.managers.PopUpManager;import mx.rpc.events.FaultEvent;import com.esri.ags.layers.*;[Bindable] public var map:Map;//打印结束后处理 private function printTask_executeCompleteHandler(event:PrintEvent):void{var paramValue:ParameterValue = event.executeResult.results[0];var dataFile:DataFile = paramValue.value as DataFile;navigateToURL(new URLRequest(dataFile.url));}private function printTask_getResultDataCompleteHandler(event:PrintEvent):void{var dataFile:DataFile = event.parameterValue.value as DataFile;navigateToURL(new URLRequest(dataFile.url));}private function printTask_jobCompleteHandler(event:PrintEvent):void{var jobInfo:JobInfo = event.jobInfo;if (jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED){printTask.getResultData(jobInfo.jobId);}else{Alert.show(jobInfo.jobStatus);}}//获取打印参数(模版和格式)protected function printTask_getServiceInfoCompleteHandler(event:PrintEvent):void{ initLayoutTemplates(event.serviceInfo);initFormats(event.serviceInfo);printButton.enabled = true;}//获得所有支持的打印格式private function initFormats(serviceInfo:PrintServiceInfo):void{var formatsVisibility:Boolean = true;var formats:IList = serviceInfo.formats;formatsDDL.selectedItem = serviceInfo.defaultFormat;}//获得所有模版private function initLayoutTemplates(serviceInfo:PrintServiceInfo):void{var layoutTemplatesVisibility:Boolean = true; layoutTemplatesFI.label = "模版"; var layoutTemplates:IList = serviceInfo.layoutTemplates; layoutTemplatesDDL.selectedItem = serviceInfo.defaultLayoutTemplate;}//获取打印比例尺private function printButton_exportWebMapClickHandler(event:MouseEvent):void{layoutOptions.title = txtTitle.text;layoutOptions.legendOptions = getLegendOptions();var oldscale:Number;var oldLODs:Array;if (scaleCheckbox.selected){oldscale =map.scale;oldLODs = map.lods;map.lods = null; //prevent LOD snapping map.scale = Number(scaleInput.text);}if (printTask.getServiceInfoLastResult.isServiceAsynchronous){printTask.submitJob(printParameters);}else{printTask.execute(printParameters);}if (scaleCheckbox.selected){map.scale = oldscale;map.lods = oldLODs;}}private function getLegendOptions():LegendOptions{var result:LegendOptions = new LegendOptions();var legendLayers:Array = [];for each (var layer:Layer in map.layers){if (layer.name.indexOf("hiddenLayer_") == -1 && !(layer is GraphicsLayer && !(layer is FeatureLayer))){ var legendLayer:LegendLayer = new LegendLayer();legendLayer.layerId = layer.id;legendLayers.push(legendLayer); }}result.legendLayers = legendLayers;return result;}protected function printTask_faultHandler(event:FaultEvent):void{Alert.show(event.fault.toString());}]]></fx:Script><fx:Declarations><esri:PrintTask id="printTask" url="http://localhost:6080/arcgis/rest/services/ExportWebMap/GPServer/Export%20Web%20Map" executeComplete="printTask_executeCompleteHandler(event)"fault="printTask_faultHandler(event)"getResultDataComplete="printTask_getResultDataCompleteHandler(event)"getServiceInfoComplete="printTask_getServiceInfoCompleteHandler(event)"jobComplete="printTask_jobCompleteHandler(event)"showBusyCursor="true"/><esri:PrintParameters id="printParameters"format="{formatsDDL.selectedItem}"layoutTemplate="{layoutTemplatesDDL.selectedItem}"map="{map}"preserveScale="{scaleCheckbox.selected}"><esri:layoutOptions><esri:LayoutOptions id="layoutOptions"/></esri:layoutOptions></esri:PrintParameters></fx:Declarations><mx:FormItem id="titleFI" width="100%" label="标题" > <s:TextInput id="txtTitle" width="100%" text="请输入标题"/> </mx:FormItem><mx:FormItem id="layoutTemplatesFI" includeInLayout="true" width="100%" label="模版" visible="true"> <s:DropDownList id="layoutTemplatesDDL" width="175" dataProvider="{printTask.getServiceInfoLastResult.layoutTemplates}"requireSelection="true"/> </mx:FormItem><mx:FormItem id="formatsFI" width="100%" label="格式" visible="true"> <s:DropDownList id="formatsDDL" dataProvider="{printTask.getServiceInfoLastResult.formats}" width="100" requireSelection="true"/> </mx:FormItem><s:HGroup id="scaleFI"width="100%"horizontalAlign="center"visible="true"><s:CheckBox id="scaleCheckbox" label="打印比例尺"/><s:TextInput id="scaleInput"width="100%" enabled="{scaleCheckbox.selected}"restrict="0-9"/></s:HGroup><s:HGroup width="100%" horizontalAlign="center" ><s:Button id="printButton" label="打印" click="printButton_exportWebMapClickHandler(event)" enabled="false"/></s:HGroup> </mx:TitleWindow>
这篇关于ArcGIS For Server10.1新特性之-服务器端打印服务及前端调用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!