Select to view content in your preferred language

Geoprocessing widget bufferPoint problem

1272
6
Jump to solution
03-20-2014 01:48 PM
fatizanady
Deactivated User
I tried to develop a geoprocessing widget which allows to establish buffers around points from my map service.
on "onResult" function I encounter this problem:

"Access to the property parameterValues ??????perhaps not defined through a reference with static type com.esri.ags.tasks.supportClasses: ExecuteResult."

I don't understand this error , someone can help me please I am a beginner programming flex and I have a great desire to make this work.Thanks for any help that could be offered!

this is the entire code:

 <?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>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Fati,

   Here is an example widget (basically your with several fixes):

  1. It queries an esri sample mapservice to get the points to buffer.

  2. The widgets UI/UX has been improved.

<?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 &gt; 0}"                      text="Clear Buffers"                      textDecoration="underline"                      visible="{bufferLyrLen &gt; 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>

View solution in original post

0 Kudos
6 Replies
fatizanady
Deactivated User
any help please it is urgent
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Fati,

   I am not sure why you are trying to use a GPService for buffering when the Flex API has buffering capabilities... But, you have issues in your code.

  1. You are passing an empty FeatureSet!
    var myfeatureset:FeatureSet=new FeatureSet();

  2. ExecuteResult object does not have a ParameterValue at a property. You have to use the Results array first that gets you an array of ParameterValues.
    var fs:FeatureSet = gpResultat.results[0].value[0] as FeatureSet;
    (this is me just guessing what your GPService is actually returning.

Next as this is a widget you are working on you need to post your questions to the Flex Viewer forum  and not here in the Flex API forum.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Fati,

   Here is an example widget (basically your with several fixes):

  1. It queries an esri sample mapservice to get the points to buffer.

  2. The widgets UI/UX has been improved.

<?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 &gt; 0}"                      text="Clear Buffers"                      textDecoration="underline"                      visible="{bufferLyrLen &gt; 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>
0 Kudos
MichaelVolz
Esteemed Contributor
Robert:

How would you add your widget shown in this post to a compiled Flex app?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Michael,

   No, this is dependant on the user have a GP Service that has these exact parameters and would only buffer the Traffic Cameras from the Louisville Public Safety Map Service.
0 Kudos
fatizanady
Deactivated User
hi rscheitlin,

I find no words to thank you. you save my life :).
I am forced to work with geoprocessing services because it's  my topic in graduation project. thank you to correct the faults of the code and complete it I promise you to make more effort. thank you again. 🙂
0 Kudos