Select to view content in your preferred language

Problem with geometryService.relation()

992
6
06-02-2010 05:14 PM
__1
by
Emerging Contributor
geoService.relation(graphics1,graphics2,GeometryService.SPATIAL_REL_WITHIN,null);
 

This is a piece of my code.geoService represents the  geometryService and the "graphics1�?? and �?�graphics2�?? are not null,but when i execute this method the property "relationLastResult" become null.

Why does it execute fail?

Hope for your help!
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
jmuguy,

   So the documentation for the 1.3 API states
public function relation(graphics1:Array, graphics2:Array, spatialRelationship:String, comparisonString:String = null, responder:IResponder = null):AsyncToken


so is your
geoService.relation(graphics1,graphics2,GeometrySe rvice.SPATIAL_REL_WITHIN,null);

graphics1 and graphics2 of type array or are they graphics

if they are just graphics then change to this
geoService.relation([graphics1],[graphics2],GeometryService.SPATIAL_REL_WITHIN,null); 
0 Kudos
__1
by
Emerging Contributor
rscheitlin,
Both graphics1 and graphics2 are array.This is my full code,could you find something wrong with it?

<?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="vertical"    styleName="plain"   
  pageTitle="GeometryService">
  <mx:Script>
   <![CDATA[
    import com.esri.ags.events.GeometryServiceEvent;
    import com.esri.ags.Graphic;
    import com.esri.ags.tasks.FeatureSet;
    import com.esri.ags.events.QueryEvent;
    import com.esri.ags.tasks.Query;
    import mx.controls.Alert;
    import mx.rpc.AsyncResponder;
    private var graphics1:Array;
     private var graphics2:Array;
     
    private function queryCities():void
    {
     graphics1 = new Array();
     var query:Query = new Query();
     query.geometry = myMap.extent;
     query.where = "FID <> 0";
     query.outFields = ["name"];
     query.returnGeometry = true;
     queryCitiesTask.execute(query,new AsyncResponder(queryCitiesResult,onFault));
     function queryCitiesResult(result:FeatureSet,token:Object=null):void
     {
       for each(var g:Graphic in result.features)
        {
      graphics1.push(g);
        }
     }    
    }
    
        private function queryProvince():void
    {
   graphics2 = new Array();
   var query:Query = new Query();
   query.geometry = myMap.extent;
   query.where = "name like '%"+txtInput.text+"%'";
   query.outFields=["name"];
   query.returnGeometry = true;   
   queryProvinceTask.execute(query,new AsyncResponder(queryProvinceResult,onFault));
      function queryProvinceResult(result:FeatureSet,token:Object = null):void
     {
     var g:Graphic = result.features[0];
     graphics2.push(g);
     geoService.relation(graphics1,graphics2,GeometryService.SPATIAL_REL_WITHIN,null);   
     }  
    }  
    private function onFault(info:Object,token:Object = null):void
  {
   Alert.show(info.toString(),"ERROR");
  }
    
    private function onRelationComplete(event:GeometryServiceEvent):void
    {
     var relation:Array = event.relations;
     myGraphicsLayer.clear();
     for(var i:int=0;i<relation.length;i++)
     {
      var g:Graphic = relation.graphics1;
      myGraphicsLayer.add(g);
     }
    }
     
   ]]>
  </mx:Script>
  <esri:GeometryService id="geoService" relationComplete="onRelationComplete(event)" url="http://howiepc:8399/arcgis/rest/services/Geometry/GeometryServer"/>
  <esri:QueryTask id="queryCitiesTask" url="http://howiepc:8399/arcgis/rest/services/jmuguy/MapServer/1"/>
  <esri:QueryTask id="queryProvinceTask" url="http://howiepc:8399/arcgis/rest/services/jmuguy/MapServer/2"/>
  <mx:HBox horizontalAlign="center" width="100%">
  <mx:Label id="lab" text="Please input the name" fontWeight="bold"/>
  <mx:TextInput id="txtInput" text="abc"/>
  <mx:Button id="btnQuery" label="Query" click="queryProvince()" mouseOver="queryCities()"/>
  </mx:HBox>
 <esri:Map id="myMap" scaleBarVisible="false" logoVisible="false">
  <esri:ArcGISDynamicMapServiceLayer url="http://howiepc:8399/arcgis/rest/services/jmuguy/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer"/>
 </esri:Map>
</mx:Application>


Hope for your help!Best wishes!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
jmuguy,

   Here is an example that I got working from yours. I changed a couple of things.
<mx:Application  
  xmlns:mx="http://www.adobe.com/2006/mxml" 
  xmlns:esri="http://www.esri.com/2008/ags"  
  layout="vertical"    styleName="plain"   
  pageTitle="GeometryService">
  <mx:Script>
   <![CDATA[
    import com.esri.ags.events.GeometryServiceEvent;
    import com.esri.ags.Graphic;
    import com.esri.ags.tasks.FeatureSet;
    import com.esri.ags.events.QueryEvent;
    import com.esri.ags.tasks.Query;
    import mx.controls.Alert;
    import mx.rpc.AsyncResponder;
    import mx.utils.ObjectUtil;
    
    private var graphics1:Array;
     private var graphics2:Array;
     
    private function queryCities():void
    {
     cursorManager.setBusyCursor();
     graphics1 = new Array();
     var query:Query = new Query();
     query.geometry = myMap.extent;
     query.where = "OBJECTID <> 0";
     query.outFields = ["NAME"];
     query.returnGeometry = true;
     queryCitiesTask.execute(query,new AsyncResponder(queryCitiesResult,onFault));
     function queryCitiesResult(result:FeatureSet,token:Object=null):void
     {
       for each(var g:Graphic in result.features)
        {
      graphics1.push(g);
        }
        queryProvince();
     }    
    }
    
        private function queryProvince():void
    {
   graphics2 = new Array();
   var query:Query = new Query();
   query.geometry = myMap.extent;
   query.where = "STATE_NAME like '%"+txtInput.text+"%'";
   query.outFields=["STATE_NAME"];
   query.returnGeometry = true;   
   queryProvinceTask.execute(query,new AsyncResponder(queryProvinceResult,onFault));
      function queryProvinceResult(result:FeatureSet,token:Object = null):void
     {
     var g:Graphic = result.features[0];
     graphics2.push(g);
     callLater(doRelate,null);
     }  
    }  
    
    private function doRelate():void
    {
     geoService.relation(graphics1,graphics2,GeometryService.SPATIAL_REL_WITHIN,null);
    }
    
    private function onFault(info:Object,token:Object = null):void
  {
   Alert.show(info.toString(),"ERROR");
   cursorManager.removeBusyCursor();
  }
    
    private function onRelationComplete(event:GeometryServiceEvent):void
    {
     var relation:Array = event.relations;
     myGraphicsLayer.clear();
     //trace(ObjectUtil.toString(relation));
     for(var i:int=0;i<relation.length;i++)
     {
      var g:Graphic = relation.graphic1;
      myGraphicsLayer.add(g);
     }
     cursorManager.removeBusyCursor();
    }
     
   ]]>
  </mx:Script>
  <esri:GeometryService id="geoService" fault="onFault(event)" relationComplete="onRelationComplete(event)" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
  <esri:QueryTask id="queryCitiesTask" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3"/>
  <esri:QueryTask id="queryProvinceTask" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
  <mx:HBox horizontalAlign="center" width="100%">
  <mx:Label id="lab" text="Please input the name" fontWeight="bold"/>
  <mx:TextInput id="txtInput" text="Alabama"/>
  <mx:Button id="btnQuery" label="Query" click="queryCities()"/>
  </mx:HBox>
 <esri:Map id="myMap" scaleBarVisible="false" logoVisible="false">
  <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer"/>
 </esri:Map>
</mx:Application>
0 Kudos
__1
by
Emerging Contributor
Scheitlin,thank you for your help!Your code really helped me,but i can't really understand the meaning of "graphic1".
  for(var i:int=0;i<relation.length;i++) 

var g:Graphic = relationgraphic1
myGraphicsLayer.add(g); 
}

In debug mode,i found "relation[0]" have graphic1 and graphic2,does graphic1 represents the first parameter of relation?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
jmuguy,

    Documentation is a little lacking in the explanation of this but the way I see it is yes Graphic1 is from the first graphic array the is within the second graphic array.
0 Kudos
__1
by
Emerging Contributor
rscheitlin�?
Yes,i search the documentation,but i can find nothing about it.
You helps me a lot,thank you very much!Best wishes!
0 Kudos