How to use extent.intersects correctly?

478
2
Jump to solution
06-28-2013 07:35 AM
DavidBoiano
Occasional Contributor
Can anyone please help explain to me how to use extent.intersects correctly? I understand the input parameter needs to be a geometry type and it will return a boolean value.  I am ultimately trying to check if each individual feature in my featureLayer exists in the current extent (kind of like the Attribute Table) and if the feature exists, I then would like to export/copy that feature to another array to populate a data grid.  One of my many attempts is:

//Code for Data Download button       public function dataDownload():void    {     var featureSet:FeatureSet = new FeatureSet(ArrayCollection(myFeatureLayer.graphicProvider).toArray());     var records:Array = featureSet.attributes;     var exportSet:Array = new Array();     for (var i:int=0; i<records.length; i++){      if (myMap.extent.intersects(records.geometry))      {       exportSet.push(records);      }     }     ssoDataGrid.dataProvider = new ArrayList(exportSet);    }


I have checked the records array and it is being correctly populated by my feature layer.  I am struggling with writing the correct loop to loop through the features, but more importantly I don't think my "if statement" has ever returned "True" because the exportSet array is always empty.  I think I am messing up by not looping through the graphicProvider to access the geometry, but I don't know how to loop through that unless it's an array...

I am still fairly new to flex and OO programming, so any suggestions or reference would be greatly appreciated!

Thank you very much.

David
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
SarthakDatt
Occasional Contributor III
Hi David,

You can simply do something like this:

public function dataDownload():void    {     var featureCollection:ArrayCollection = myFeatureLayer.graphicProvider as ArrayCollection;     var exportSet:Array = [];      for (var i:int=0; i < featureCollection.length; i++){                                         var graphic:Graphic = featureCollection.getItemAt(i) as Graphic;      if (myMap.extent.intersects(graphic.geometry))      {            exportSet.push(graphic);      }     }                                                                OR                                  for each (var graphic:Graphic in featureCollection){                                                     if (myMap.extent.intersects(graphic.geometry))      {            exportSet.push(graphic);      }     }      ssoDataGrid.dataProvider = new ArrayList(exportSet);    } 

View solution in original post

0 Kudos
2 Replies
SarthakDatt
Occasional Contributor III
Hi David,

You can simply do something like this:

public function dataDownload():void    {     var featureCollection:ArrayCollection = myFeatureLayer.graphicProvider as ArrayCollection;     var exportSet:Array = [];      for (var i:int=0; i < featureCollection.length; i++){                                         var graphic:Graphic = featureCollection.getItemAt(i) as Graphic;      if (myMap.extent.intersects(graphic.geometry))      {            exportSet.push(graphic);      }     }                                                                OR                                  for each (var graphic:Graphic in featureCollection){                                                     if (myMap.extent.intersects(graphic.geometry))      {            exportSet.push(graphic);      }     }      ssoDataGrid.dataProvider = new ArrayList(exportSet);    } 
0 Kudos
DavidBoiano
Occasional Contributor
Sarthak,

THANK YOU! That works exactly as I needed it to.  All I had to do was add
exportSet.push(graphic.attributes);
and the array was populated with everything correctly.  Thanks again very much!

David
0 Kudos