<?xml version="1.0" encoding="utf-8"?> <!-- /////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010-2011 Esri. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////////// --> <viewer:BaseWidget 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:viewer="com.esri.viewer.*" xmlns:esri="http://www.esri.com/2008/ags" creationComplete="init()"> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.events.GeoprocessorEvent; import com.esri.ags.layers.GraphicsLayer; import com.esri.ags.tasks.supportClasses.ExecuteResult; import com.esri.ags.tasks.supportClasses.LinearUnit; import com.esri.ags.tasks.supportClasses.ParameterValue; import mx.controls.Alert; import mx.rpc.AsyncResponder; public var graphiclayer:GraphicsLayer=new GraphicsLayer(); private var mybufferdistance:LinearUnit= new LinearUnit(); private function init():void { myGraphicsLayer.clear(); graphiclayer=new GraphicsLayer(); graphiclayer.symbol= buffpointSimpleFill; map.addLayer(graphiclayer); } private function createRequestObject():Object { var myfeatureset:FeatureSet=new FeatureSet(); mybufferdistance.distance=Number(bufferdistance.text); mybufferdistance.units="esriMeters"; var params:Object= { "GPBuffer_DBO_points": myfeatureset, "Distance_ ": mybufferdistance } return params; } private function buffer():void { var params:Object=createRequestObject(); gp.execute(params,new AsyncResponder(onResult, onFault)); function onResult(gpResultat:ExecuteResult=null,token:Object=null):void { var pv:ParameterValue=gpResultat.parameterValues[0]; var fs:FeatureSet=pv.value as FeatureSet; graphiclayer.graphicProvider=fs.features; } function onFault(info:Object,token:Object=null):void { Alert.show(info.tostring()); graphiclayer.clear(); } } private function DoClear():void { graphiclayer.clear(); } ]]> </fx:Script> <fx:Declarations> <esri:SimpleFillSymbol id="buffpointSimpleFill" alpha="0.5" color="0xFF0000"> <esri:SimpleLineSymbol width="1" alpha="0.5" color="0x000000"/> </esri:SimpleFillSymbol> <esri:Geoprocessor id="gp" url="http://localhost:6080/arcgis/rest/services/Geotraitement/BufferPoint/GPServer/BufferPoint" useAMF="false"/> </fx:Declarations> <esri:GraphicsLayer id="myGraphicsLayer"/> <viewer:WidgetTemplate id="MyTestWidget" width="300" height="300"> <s:TextInput x="86" y="76" id="bufferdistance"/> <s:Button x="114" y="149" label="buffer" click="buffer()"/> <s:Button x="115" y="212" label="Clear" click="DoClear()"/> </viewer:WidgetTemplate> </viewer:BaseWidget>
Solved! Go to Solution.
<?xml version="1.0" encoding="utf-8"?> <!-- /////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010-2011 Esri. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////////// --> <viewer:BaseWidget 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:viewer="com.esri.viewer.*" xmlns:esri="http://www.esri.com/2008/ags" creationComplete="init()"> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.events.LayerEvent; import com.esri.ags.layers.FeatureLayer; import com.esri.ags.layers.GraphicsLayer; import com.esri.ags.tasks.supportClasses.ExecuteResult; import com.esri.ags.tasks.supportClasses.LinearUnit; import com.esri.ags.tasks.supportClasses.ParameterValue; import com.esri.ags.tasks.supportClasses.Query; import com.esri.viewer.utils.ErrorMessageUtil; import mx.controls.Alert; import mx.rpc.AsyncResponder; [Bindable] private var msgVisible:Boolean = false; [Bindable] public var graphiclayer:GraphicsLayer=new GraphicsLayer(); private var mybufferdistance:LinearUnit= new LinearUnit(); private var queryLayer:FeatureLayer; private var myfeatureset:FeatureSet; [Bindable] private var bufferLyrLen:int; private function init():void { graphiclayer=new GraphicsLayer(); graphiclayer.symbol= buffpointSimpleFill; map.addLayer(graphiclayer); queryLayer = new FeatureLayer(); queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.addEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); queryLayer.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer/2"; queryLayer.outFields = ["*"]; } private function queryLayer_loadHandler(event:LayerEvent):void { queryLayer.removeEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.removeEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); var query:Query = new Query(); query.where = "1=1"; query.outSpatialReference = map.spatialReference; queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { myfeatureset = featureSet; bufferBtn.enabled = true; } function onFault(info:Object, token:Object = null):void { showMessage(info.toString(), false); } } private function queryLayer_loadErrorHandler(event:LayerEvent):void { queryLayer.removeEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.removeEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); var errorMessage:String = getDefaultString("layerFailedToLoad", event.layer.name, ErrorMessageUtil.makeHTMLSafe(ErrorMessageUtil.buildFaultMessage(event.fault))); showError(errorMessage); } private function showMessage(msg:String, swfVisible:Boolean):void { txtMessage.text = msg; swfMessage.visible = swfVisible; msgVisible = true; } private function createRequestObject():Object { mybufferdistance.distance=Number(bufferdistance.text); mybufferdistance.units="esriMeters"; var params:Object= { "GPBuffer_DBO_points": myfeatureset, "Distance_": mybufferdistance } return params; } private function buffer():void { var params:Object=createRequestObject(); gp.execute(params,new AsyncResponder(onResult, onFault)); function onResult(gpResultat:ExecuteResult=null,token:Object=null):void { var pv:ParameterValue = gpResultat.results[0]; var fs:FeatureSet = pv.value as FeatureSet; graphiclayer.graphicProvider=fs.features; bufferLyrLen = graphiclayer.numGraphics; msgVisible = true; zoomAll(); } function onFault(info:Object,token:Object=null):void { Alert.show(info.toString()); graphiclayer.clear(); } } private function clearBuffer():void { bufferLyrLen = 0; graphiclayer.clear(); } private function zoomAll():void { if(myfeatureset.features){ if (myfeatureset.features.length == 1 && myfeatureset.features[0].geometry.type == Geometry.MAPPOINT){ var mp:MapPoint = myfeatureset.features[0].geometry as MapPoint; map.zoom(1 / 16, mp); map.centerAt(mp); }else{ var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(myfeatureset.features); if(graphicsExtent){ map.zoomTo(graphicsExtent.expand(1.2)); }else{ var mp2:MapPoint = myfeatureset.features[0].geometry as MapPoint; map.zoom(1 / 16, mp2); map.centerAt(mp2); } } } } ]]> </fx:Script> <fx:Declarations> <esri:SimpleFillSymbol id="buffpointSimpleFill" alpha="0.5" color="0xFF0000"> <esri:SimpleLineSymbol width="1" alpha="0.5" color="0x000000"/> </esri:SimpleFillSymbol> <esri:Geoprocessor id="gp" url="http://localhost:6080/arcgis/rest/services/Geotraitement/BufferPoint/GPServer/BufferPoint" useAMF="false"/> </fx:Declarations> <viewer:WidgetTemplate id="MyTestWidget" width="400" height="200"> <viewer:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="top"/> </viewer:layout> <s:HGroup id="boxMessage" width="100%" includeInLayout="{msgVisible}" visible="{msgVisible}"> <mx:Image id="swfMessage" source="assets/images/loader.swf" visible="false"/> <s:Label id="txtMessage" width="90%" text=""/> <s:Label buttonMode="true" textAlign="right" click="clearBuffer()" fontWeight="bold" includeInLayout="{bufferLyrLen > 0}" text="Clear Buffers" textDecoration="underline" visible="{bufferLyrLen > 0}"/> </s:HGroup> <s:HGroup width="100%" verticalAlign="middle" horizontalAlign="left" paddingTop="5"> <s:Label text="Enter the Buffer distance" /> <s:TextInput x="86" y="76" id="bufferdistance" text="1000"/> </s:HGroup> <s:HGroup horizontalAlign="right" width="100%" height="100%" verticalAlign="bottom"> <s:Button x="114" y="149" id="bufferBtn" label="Buffer Features..." click="buffer()" enabled="false"/> </s:HGroup> </viewer:WidgetTemplate> </viewer:BaseWidget>var myfeatureset:FeatureSet=new FeatureSet();
var fs:FeatureSet = gpResultat.results[0].value[0] as FeatureSet;(this is me just guessing what your GPService is actually returning.
<?xml version="1.0" encoding="utf-8"?> <!-- /////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010-2011 Esri. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////////// --> <viewer:BaseWidget 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:viewer="com.esri.viewer.*" xmlns:esri="http://www.esri.com/2008/ags" creationComplete="init()"> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.events.LayerEvent; import com.esri.ags.layers.FeatureLayer; import com.esri.ags.layers.GraphicsLayer; import com.esri.ags.tasks.supportClasses.ExecuteResult; import com.esri.ags.tasks.supportClasses.LinearUnit; import com.esri.ags.tasks.supportClasses.ParameterValue; import com.esri.ags.tasks.supportClasses.Query; import com.esri.viewer.utils.ErrorMessageUtil; import mx.controls.Alert; import mx.rpc.AsyncResponder; [Bindable] private var msgVisible:Boolean = false; [Bindable] public var graphiclayer:GraphicsLayer=new GraphicsLayer(); private var mybufferdistance:LinearUnit= new LinearUnit(); private var queryLayer:FeatureLayer; private var myfeatureset:FeatureSet; [Bindable] private var bufferLyrLen:int; private function init():void { graphiclayer=new GraphicsLayer(); graphiclayer.symbol= buffpointSimpleFill; map.addLayer(graphiclayer); queryLayer = new FeatureLayer(); queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.addEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); queryLayer.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_PublicSafety_Louisville/MapServer/2"; queryLayer.outFields = ["*"]; } private function queryLayer_loadHandler(event:LayerEvent):void { queryLayer.removeEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.removeEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); var query:Query = new Query(); query.where = "1=1"; query.outSpatialReference = map.spatialReference; queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { myfeatureset = featureSet; bufferBtn.enabled = true; } function onFault(info:Object, token:Object = null):void { showMessage(info.toString(), false); } } private function queryLayer_loadErrorHandler(event:LayerEvent):void { queryLayer.removeEventListener(LayerEvent.LOAD, queryLayer_loadHandler); queryLayer.removeEventListener(LayerEvent.LOAD_ERROR, queryLayer_loadErrorHandler); var errorMessage:String = getDefaultString("layerFailedToLoad", event.layer.name, ErrorMessageUtil.makeHTMLSafe(ErrorMessageUtil.buildFaultMessage(event.fault))); showError(errorMessage); } private function showMessage(msg:String, swfVisible:Boolean):void { txtMessage.text = msg; swfMessage.visible = swfVisible; msgVisible = true; } private function createRequestObject():Object { mybufferdistance.distance=Number(bufferdistance.text); mybufferdistance.units="esriMeters"; var params:Object= { "GPBuffer_DBO_points": myfeatureset, "Distance_": mybufferdistance } return params; } private function buffer():void { var params:Object=createRequestObject(); gp.execute(params,new AsyncResponder(onResult, onFault)); function onResult(gpResultat:ExecuteResult=null,token:Object=null):void { var pv:ParameterValue = gpResultat.results[0]; var fs:FeatureSet = pv.value as FeatureSet; graphiclayer.graphicProvider=fs.features; bufferLyrLen = graphiclayer.numGraphics; msgVisible = true; zoomAll(); } function onFault(info:Object,token:Object=null):void { Alert.show(info.toString()); graphiclayer.clear(); } } private function clearBuffer():void { bufferLyrLen = 0; graphiclayer.clear(); } private function zoomAll():void { if(myfeatureset.features){ if (myfeatureset.features.length == 1 && myfeatureset.features[0].geometry.type == Geometry.MAPPOINT){ var mp:MapPoint = myfeatureset.features[0].geometry as MapPoint; map.zoom(1 / 16, mp); map.centerAt(mp); }else{ var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(myfeatureset.features); if(graphicsExtent){ map.zoomTo(graphicsExtent.expand(1.2)); }else{ var mp2:MapPoint = myfeatureset.features[0].geometry as MapPoint; map.zoom(1 / 16, mp2); map.centerAt(mp2); } } } } ]]> </fx:Script> <fx:Declarations> <esri:SimpleFillSymbol id="buffpointSimpleFill" alpha="0.5" color="0xFF0000"> <esri:SimpleLineSymbol width="1" alpha="0.5" color="0x000000"/> </esri:SimpleFillSymbol> <esri:Geoprocessor id="gp" url="http://localhost:6080/arcgis/rest/services/Geotraitement/BufferPoint/GPServer/BufferPoint" useAMF="false"/> </fx:Declarations> <viewer:WidgetTemplate id="MyTestWidget" width="400" height="200"> <viewer:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="top"/> </viewer:layout> <s:HGroup id="boxMessage" width="100%" includeInLayout="{msgVisible}" visible="{msgVisible}"> <mx:Image id="swfMessage" source="assets/images/loader.swf" visible="false"/> <s:Label id="txtMessage" width="90%" text=""/> <s:Label buttonMode="true" textAlign="right" click="clearBuffer()" fontWeight="bold" includeInLayout="{bufferLyrLen > 0}" text="Clear Buffers" textDecoration="underline" visible="{bufferLyrLen > 0}"/> </s:HGroup> <s:HGroup width="100%" verticalAlign="middle" horizontalAlign="left" paddingTop="5"> <s:Label text="Enter the Buffer distance" /> <s:TextInput x="86" y="76" id="bufferdistance" text="1000"/> </s:HGroup> <s:HGroup horizontalAlign="right" width="100%" height="100%" verticalAlign="bottom"> <s:Button x="114" y="149" id="bufferBtn" label="Buffer Features..." click="buffer()" enabled="false"/> </s:HGroup> </viewer:WidgetTemplate> </viewer:BaseWidget>