Flex 1.3 - Multiple Calls to Geometry Service not producing output

674
8
05-09-2011 07:03 AM
DaviKucharski
New Contributor II
Hello. Below you will see my code for a GeometryService, function to call the GeometryService and the symbol I am using to apply to the graphic the comes out of the result. If I call this function 1 time, the system will product a circle with a radius of whatever my parameter is using the x and y parameters as the center point. The problem is when I call this function multiple times, no graphics will be displayed. The code is still running fine and I believe correctly. Just no circle graphic. I was wondering if there is an issue with calling this multiple times.

Again, if I run the following code a circle appears:
highlightStoresArea(-87.8658, 41.6694, 5)

If I try to run the following statements no graphics. If I comment 1 of them out, circle appears.
highlightStoresArea(-87.8658, 41.6694, 5)
highlightStoresArea(-88.1995, 41.7070, 5)



<esri:GeometryService id="myGeometryService"
url="http://dg2k8esridev1/ArcGISDevelopment/rest/services/Geometry/GeometryServer"/>


public function highlightStoresArea(x:Number, y:Number, radius:Number):void
{
var myMapCenterPoint:Graphic = new Graphic();
myMapCenterPoint.geometry = new MapPoint(x, y, new SpatialReference(4326));
  
             var bufferParameters:BufferParameters = new BufferParameters();               
bufferParameters.features = [myMapCenterPoint];               
bufferParameters.distances = [radius];               
bufferParameters.unit = BufferParameters.UNIT_STATUTE_MILE;               
bufferParameters.bufferSpatialReference = new SpatialReference(4326);               
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);               
myGeometryService.buffer(bufferParameters);               
  
               function bufferCompleteHandler(event:GeometryServiceEvent):void               
{                   
  myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);           
  for each (var graphic:Graphic in event.graphics)                   
  {    
   graphic.symbol = sfs;         
   myGraphicsLocationsLayer.add(graphic);
  }
}
}

<esri:SimpleFillSymbol id="sfs" color="0xFF0000" alpha="0.0">       
<esri:SimpleLineSymbol color="0x000000"/>   
</esri:SimpleFillSymbol>
Tags (2)
0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus
Davi,

   In your code after the first buffer result is complete you remove the event listener... If you are going to do that then you need to add it back each time you call the highlightStoresArea function.
0 Kudos
DaviKucharski
New Contributor II
First thank you for your reply.

I thought I was adding back the listener in the function. I have highlighted the lines in question. Is there some other place to do it. For each call the system has a result and goes into the event handler. It is just when I run them together neither graphic is displayed. I would have expected the first graphic to display but not the second if me removing the listener was the issue. Neither displays.

public function highlightStoresArea(x:Number, y:Number, radius:Number):void
{
var myMapCenterPoint:Graphic = new Graphic();
myMapCenterPoint.geometry = new MapPoint(x, y, new SpatialReference(4326));

var bufferParameters:BufferParameters = new BufferParameters();
bufferParameters.features = [myMapCenterPoint];
bufferParameters.distances = [radius];
bufferParameters.unit = BufferParameters.UNIT_STATUTE_MILE;
bufferParameters.bufferSpatialReference = new SpatialReference(4326);
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler); myGeometryService.buffer(bufferParameters);

function bufferCompleteHandler(event:GeometryServiceEvent):void
{
myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler); for each (var graphic:Graphic in event.graphics)
{
graphic.symbol = sfs;
myGraphicsLocationsLayer.add(graphic);
}
}
}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Davi,

   I missed that line. What is the concurrency of your myGeometryService set to?
0 Kudos
DaviKucharski
New Contributor II
Davi,

   I missed that line. What is the concurrency of your myGeometryService set to?


I don't know where that is. I have looked into ArcGIS Server Manager and I don't see anything about concurrency. Just pooling.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Davi,

   Search your code for myGeometryService and find out is it declared in MXML or actionscript and verify if the concurrency="last" or what.
0 Kudos
DaviKucharski
New Contributor II
Davi,

   Search your code for myGeometryService and find out is it declared in MXML or actionscript and verify if the concurrency="last" or what.


<esri:GeometryService id="myGeometryService"       
  url="http://dg2k8esridev1/ArcGISDevelopment/rest/services/Geometry/GeometryServer"/>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Davi,

   Here is a complete application example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 xmlns:esri="http://www.esri.com/2008/ags"
 layout="absolute">

 <esri:GeometryService id="myGeometryService" concurrency="multiple" bufferComplete="bufferCompleteHandler(event)"
  url="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
  
 <mx:Script>
  <![CDATA[
   import com.esri.ags.events.GeometryServiceEvent;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.Graphic;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.tasks.BufferParameters;
   
   private function buttonClick(evt:MouseEvent):void
   {
    highlightStoresArea(-87.8658, 41.6694, 5);
    highlightStoresArea(-88.1995, 41.7070, 5);
   }
   
   public function highlightStoresArea(x:Number, y:Number, radius:Number):void
   {
    var myMapCenterPoint:Graphic = new Graphic();
    myMapCenterPoint.geometry = new MapPoint(x, y, new SpatialReference(4326));
    var bufferParameters:BufferParameters = new BufferParameters();
    bufferParameters.features = [myMapCenterPoint];
    bufferParameters.distances = [radius];
    bufferParameters.unit = BufferParameters.UNIT_STATUTE_MILE;
    bufferParameters.bufferSpatialReference = new SpatialReference(4326);
    myGeometryService.buffer(bufferParameters);
   }
   
   private function bufferCompleteHandler(event:GeometryServiceEvent):void
   {
    myGraphicsLocationsLayer.add(event.graphics[0]);
   }
  ]]>
 </mx:Script>

 <esri:SimpleFillSymbol id="sfs" color="0xFF0000" alpha="1.0">
  <esri:SimpleLineSymbol color="0x000000"/>
 </esri:SimpleFillSymbol> 
 
 <esri:Map id="myMap">
  <esri:extent>
   <esri:Extent xmin="-89.925" ymin="40.222" xmax="-83.894" ymax="42.205">
    <esri:spatialReference>
     <esri:SpatialReference wkid="4326"/>
    </esri:spatialReference>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer
   url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLocationsLayer" symbol="{sfs}" />
 </esri:Map>
 <mx:Button click="buttonClick(event)" label="Buffer" />
</mx:Application>
0 Kudos
DaviKucharski
New Contributor II
Davi,

   Here is a complete application example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 xmlns:esri="http://www.esri.com/2008/ags"
 layout="absolute">

 <esri:GeometryService id="myGeometryService" concurrency="multiple" bufferComplete="bufferCompleteHandler(event)"
  url="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
  
 <mx:Script>
  <![CDATA[
   import com.esri.ags.events.GeometryServiceEvent;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.Graphic;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.tasks.BufferParameters;
   
   private function buttonClick(evt:MouseEvent):void
   {
    highlightStoresArea(-87.8658, 41.6694, 5);
    highlightStoresArea(-88.1995, 41.7070, 5);
   }
   
   public function highlightStoresArea(x:Number, y:Number, radius:Number):void
   {
    var myMapCenterPoint:Graphic = new Graphic();
    myMapCenterPoint.geometry = new MapPoint(x, y, new SpatialReference(4326));
    var bufferParameters:BufferParameters = new BufferParameters();
    bufferParameters.features = [myMapCenterPoint];
    bufferParameters.distances = [radius];
    bufferParameters.unit = BufferParameters.UNIT_STATUTE_MILE;
    bufferParameters.bufferSpatialReference = new SpatialReference(4326);
    myGeometryService.buffer(bufferParameters);
   }
   
   private function bufferCompleteHandler(event:GeometryServiceEvent):void
   {
    myGraphicsLocationsLayer.add(event.graphics[0]);
   }
  ]]>
 </mx:Script>

 <esri:SimpleFillSymbol id="sfs" color="0xFF0000" alpha="1.0">
  <esri:SimpleLineSymbol color="0x000000"/>
 </esri:SimpleFillSymbol> 
 
 <esri:Map id="myMap">
  <esri:extent>
   <esri:Extent xmin="-89.925" ymin="40.222" xmax="-83.894" ymax="42.205">
    <esri:spatialReference>
     <esri:SpatialReference wkid="4326"/>
    </esri:spatialReference>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer
   url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLocationsLayer" symbol="{sfs}" />
 </esri:Map>
 <mx:Button click="buttonClick(event)" label="Buffer" />
</mx:Application>


That did the trick. I will try to diagnose this to see exactly where I was broken. Thanks again.
0 Kudos