Select to view content in your preferred language

Loop through featureSet and get xy of features

1256
3
Jump to solution
08-23-2013 04:04 AM
MikeSmith7
Emerging Contributor
I need to loop through a feature set that I always get one result in, if there is more I can take just the first or last one.  I want to zoom to that selected point.  I have not found a good example on how to do this.  I can hard code xy values and get it to work, but I want the xy of the record that is returned in my record set.  Any help would be appreaciated.


   private function doQuery():void
   {
    // clear the graphics layer
    myGraphicsLayer.clear();
   
    queryTask.execute(query, new AsyncResponder(onResult, onFault));
    function onResult(featureSet:FeatureSet, token:Object = null):void
    {
     Alert.show("In Function" + featureSet.features.length);
     if (featureSet.features.length == 0)
     {
      Alert.show("No Feature found. Please try again.");
     }
     else
     {
      Alert.show("Record Found");
      const mapPoint:MapPoint = new MapPoint();
//dynamically get xy here
      mapPoint.x=-7033340.3;
      mapPoint.y=5827584.9;
      map.scale=15000;
      map.centerAt(mapPoint);
     }
    }
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show(info.toString());
    }
   }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Mike,

   I have to assume that the returned geometry type is a map point as you do not mention what type it is:

            private function doQuery():void             {                 // clear the graphics layer                 myGraphicsLayer.clear();                                  queryTask.execute(query, new AsyncResponder(onResult, onFault));                 function onResult(featureSet:FeatureSet, token:Object = null):void                 {                     Alert.show("In Function" + featureSet.features.length);                     if (featureSet.features.length == 0)                     {                         Alert.show("No Feature found. Please try again.");                     }                     else                     {                         Alert.show("Record Found");                         map.scale = 15000;                         map.centerAt(featureSet.features[0].geometry as MapPoint);                     }                 }                 function onFault(info:Object, token:Object = null):void                 {                     Alert.show(info.toString());                 }             }

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Mike,

   I have to assume that the returned geometry type is a map point as you do not mention what type it is:

            private function doQuery():void             {                 // clear the graphics layer                 myGraphicsLayer.clear();                                  queryTask.execute(query, new AsyncResponder(onResult, onFault));                 function onResult(featureSet:FeatureSet, token:Object = null):void                 {                     Alert.show("In Function" + featureSet.features.length);                     if (featureSet.features.length == 0)                     {                         Alert.show("No Feature found. Please try again.");                     }                     else                     {                         Alert.show("Record Found");                         map.scale = 15000;                         map.centerAt(featureSet.features[0].geometry as MapPoint);                     }                 }                 function onFault(info:Object, token:Object = null):void                 {                     Alert.show(info.toString());                 }             }
0 Kudos
MikeSmith7
Emerging Contributor
Hi Robert, this is great thank you.  I am assuming that the 0 in featureSet.features[0].geometry is the position in the array?

Thanks,
Mike
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
correct 0 is the first graphic in the array of graphics that the featureset features returns.
0 Kudos