同步异步说明:
gp服务分为同步和异步两种模式,两者的区别是:
同步:适合于快速的处理,数据量较小,本质区别在于同步模式,服务器处理之后,处理结果并不在服务器端保存,而是将结果发送至客户端,由客户端去显示。如果客户端也没有 保存结果,那么处理结果就丢失了。
异步:适合长时间的处理,数据量较大,本质区别在于异步模式,服务器处理之后,处理结果保存在服务器端,可以在arcgisjobs文件中找到。
所以Web客户端调用gp服务,要依据是哪种模式。以flex api为例,如果是同步模式,那么只能使用gp.execute(para);,得到的结果只能是executeResult;如果是异步,则只能使用gp.submitJob(para);,得到的结果只能使用gp.getResultData(evt.jobInfo.jobId,"Buffer_shp")去服务器端取结果,因为异步模式服务器端是保留了你的处理结果的。
同步调用方法
标签:
<esri:Geoprocessor id="gp" executeComplete="gp_executeCompleteHandler(event)"
fault="gp_faultHandler(event)"
outSpatialReference="{map.spatialReference}"
processSpatialReference="{map.spatialReference}"
useAMF="false"/>
调用:
var geoArr:Array=[]; for each(var geo:Geometry in geoCollArray) { geoArr.push({geometry:geo}); } var fs:FeatureSet=new FeatureSet(); fs.features=geoArr; var params:Object={"INPUT_FEATURESET":fs,"GHLAYER_PATH":"'"+dataList.selectedItem.path+"'"};
gp.url=configXML.gpurl.toString(); gp.execute(params);
结果
protected function gp_faultHandler(event:FaultEvent):void { Alert.show("空间分析异常,请联系管理员", "图形分析"); } protected function gp_executeCompleteHandler(event:GeoprocessorEvent):void { var fs:FeatureSet=event.executeResult.results[0].value as FeatureSet; controlEnabled=true; showMessage("", false, false); ViewerContainer.getInstance().resultContainer.Container.removeAllElements(); resultComp=new GeometryAnalysisResultComp(); var areas:Array=GeometryUtil.geodesicAreas(geoCollArray,Units.SQUARE_METERS); var area:Number=Number(areas[0]); resultComp.initData={fs:fs,fields:fs.fields,groupfield:dataList.selectedItem.showField.toString(),geo:geoCollArray[0],zarea:area,url:configXML.saveAnalysis}; ViewerContainer.getInstance().resultContainer.Container.addElement(resultComp); ViewerContainer.getInstance().resultContainer.showBottomNavi(); }
异步调用方法:
标签
<esri:Geoprocessor id="gp" fault="gp_faultHandler(event)" getResultDataComplete="gp_getResultDataCompleteHandler(event)" jobComplete="gp_jobCompleteHandler(event)" outSpatialReference="{myMap.spatialReference}" proxyURL="https://developers.arcgis.com/sproxy/" url="https://logistics.arcgis.com/arcgis/rest/services/World/ServiceAreas/GPServer/GenerateServiceAreas"/>
调用
var featureSet:FeatureSet = new FeatureSet(); featureSet.features = [ graphic ]; var params:Object = { "Facilities": featureSet, "Break_Values": "2", "Break_Units": "Minutes" }; gp.submitJob(params);
结果
protected function gp_faultHandler(event:FaultEvent):void { Alert.show("This service request an ArcGIS Organizational subscription You can also try the example on the ArcGIS API for Flex Resource Center" + event.fault.faultString, "Drive Time"); progressMessage.clearMessage(); } protected function gp_jobCompleteHandler(event:GeoprocessorEvent):void { if (event.jobInfo.jobStatus == JobInfo.STATUS_SUCCEEDED) { var jobID:String = event.jobInfo.jobId; progressMessage.setMessage("Retrieving drive time"); gp.getResultData(gp.submitJobLastResult.jobId, "Service_Areas"); } else { Alert.show(event.jobInfo.jobStatus, "Analysis Status"); } } protected function gp_getResultDataCompleteHandler(event:GeoprocessorEvent):void { /* The parameterValue property is set when the type is getResultDataComplete, * getInputComplete or getResultImageComplete. */ if (event.parameterValue) { progressMessage.showMessage("Calculating population within drive time", true); var serviceAreas:FeatureSet = event.parameterValue.value as FeatureSet; var feature:Graphic = serviceAreas.features[0]; var symbol:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, 0xCA0013, 0.1); symbol.outline = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xB3B3B3, 1.0, 2); feature.symbol = symbol; myMap.defaultGraphicsLayer.add(feature); query.geometry = feature.geometry; queryTask.execute(query); //Note: the zoomTo method was added at version 3.1 myMap.zoomTo(feature.geometry.extent); } else { Alert.show("Service did not return any results", "Drive Time"); gpPending = false; } }
转换:
fs->json字符串
saveWindow.fs=JSONUtil.encode(FeatureSet(initData.fs).toJSON())
json字符串- >fs
var fs:FeatureSet=FeatureSet.fromJSON(JSONUtil.decode(jsonObjTem[0].content));