Help with Zoom to Feature Layer based on Query Selection_New

955
9
Jump to solution
06-05-2014 10:09 AM
JohnRitsko
New Contributor III
Greetings all,

  For some reason I'm having a bit of difficulty getting my zoom to feature layer work.  The  following clears the previously selected route (mySelectedRouteLayer) then utilizing the route they selected returns the "ROUTE" number I use to create a SELECTION_NEW from the Feature Layer and display that layer.  It will clear the feature layer when they select the next one my problem is that I can't seem to figure out how to zoom to this particularly selected feature.

I was using the myMap.zoomTo(graphic.geometry); but since I no longer use the Graphic Layer I'm not sure how to get the geometry out of my FeatureLayer to zoomTo it. 

Your input is greatly appreciated. Thank you in advance.

mySelectedRouteLayer.clear(); var graphic:Graphic; graphic = List(event.currentTarget).selectedItem as Graphic; var selectedRoute:int = graphic.attributes["ROUTE"]; query_Selection.where = "ROUTE = " + selectedRoute + ""; mySelectedRouteLayer.selectFeatures(query_Selection, FeatureLayer.SELECTION_NEW); mySelectedRouteLayer.selectionColor = NaN; // Zoomto the Extent of mySelectedRouteLayer
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnRitsko
New Contributor III
Sorry for delayed response.  I managed to simply use the geometry of the graphic to zoom to the extent of.


protected function routeList_changeHandler(event:IndexChangeEvent):void   {  mySelectedRouteLayer.clear();    var graphic:Graphic = List(event.currentTarget).selectedItem as Graphic;  var selectedRoute:int = graphic.attributes["ROUTE"];  query_Selection.where = "ROUTE = " + selectedRoute + "";  mySelectedRouteLayer.selectFeatures(query_Selection, FeatureLayer.SELECTION_NEW);  mySelectedRouteLayer.selectionColor = NaN;  highlightStops(graphic);   myMap.zoomTo(graphic.geometry.extent);  }  

View solution in original post

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
John,

  In your selectionComplete function you use the AsyncToken that is returned and get the features array and feed that array to a GraphicUtil object and call the getGraphicsExtent method to get a extent and then you feed that to the myMap.zoomTo.
0 Kudos
JohnRitsko
New Contributor III
Robert,

I tried something like that using this code below but it seems to zoom to all the features progressively as you keep selecting more of them.  So the first time you run the application and select a route it doesn't move at all.  Then once you select the next feature it seems to zoom to the extent of the two routes.

var ac:ArrayCollection = mySelectedRouteLayer.graphicProvider as ArrayCollection;
myMap.zoomTo(GraphicUtil.getGraphicsExtent( ac.toArray()) );



John,

  In your selectionComplete function you use the AsyncToken that is returned and get the features array and feed that array to a GraphicUtil object and call the getGraphicsExtent method to get a extent and then you feed that to the myMap.zoomTo.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
John,

   If you follow my advice on getting the features array from the AsyncToken in the selectionComplete function (and not the graphicsPrivider) than you should be ok.
0 Kudos
JohnRitsko
New Contributor III
Robert,

Thanks, I'm going to try and get that working.  I'll keep you posted and thanks for the input, much, much appreciated.


John,

   If you follow my advice on getting the features array from the AsyncToken in the selectionComplete function (and not the graphicsPrivider) than you should be ok.
0 Kudos
JohnRitsko
New Contributor III
Robert,

I can't put the GraphicUtil in the creationComplete function as it stores the extent of all my routes which is run only once when the program loads.  As such, it zooms to all of the routes only once and then never moves from there. The creationComplete function stores the geometry of my routes as routeList.dataProvider=new ArrayCollection(featureSet.features);

  I use a change event based on this routeList to get an attribute from the list in order to query stops and routes.

Perhaps you can help me think about how to address this.  Thanks.

protected function routeList_changeHandler(event:IndexChangeEvent):void
{
 mySelectedRouteLayer.clear();

 var graphic:Graphic = List(event.currentTarget).selectedItem as Graphic;
 var selectedRoute:int = graphic.attributes["ROUTE"];
    
 query_Selection.where = "ROUTE = " + selectedRoute + "";
 mySelectedRouteLayer.selectFeatures(query_Selection, FeatureLayer.SELECTION_NEW);
 mySelectedRouteLayer.selectionColor = NaN;
 highlightStops(graphic); 
 
/* var routeExtent:Extent = GraphicUtil.getGraphicsExtent(graphic.toArray()); */
/* myMap.extent = routeExtent; */
    
 var ac:ArrayCollection = mySelectedRouteLayer.graphicProvider as ArrayCollection;
 myMap.zoomTo(GraphicUtil.getGraphicsExtent(ac.toArray())); 
} 
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
John,

   Do you have a selectionComplete function?.. I mentioned that you need to use this function in both of my last posts.
0 Kudos
JohnRitsko
New Contributor III
I have a creationComplete function and I tried what you said but I personally couldn't get it working.  I've taken one 2 day course on Flex so I'm still very new to this.

protected function doQuery():void
{ 
 queryTask.execute(query, new AsyncResponder(onResult, onFault));
 function onResult(featureSet:FeatureSet, token:Object = null):void
 {
  routeList.dataProvider = new ArrayCollection(featureSet.features);
 }
 function onFault(info:Object, token:Object = null):void
 {
  Alert.show( info.toString() );
 }
}


<s:List id="routeList"
  x="10" y="10"
  width="225" height="575" 
  rollOverColor="#CCCCCC"
  horizontalScrollPolicy="on"
  creationComplete="doQuery()"
  change="routeList_changeHandler(event)"> 
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
John,

   You started out asking about a FeatureLayer.SelectFeatures, now you are talking about a QueryTask... Maybe you should just post all of your code in a zip file for me to look at and see exactly what you are attempting.
0 Kudos
JohnRitsko
New Contributor III
Sorry for delayed response.  I managed to simply use the geometry of the graphic to zoom to the extent of.


protected function routeList_changeHandler(event:IndexChangeEvent):void   {  mySelectedRouteLayer.clear();    var graphic:Graphic = List(event.currentTarget).selectedItem as Graphic;  var selectedRoute:int = graphic.attributes["ROUTE"];  query_Selection.where = "ROUTE = " + selectedRoute + "";  mySelectedRouteLayer.selectFeatures(query_Selection, FeatureLayer.SELECTION_NEW);  mySelectedRouteLayer.selectionColor = NaN;  highlightStops(graphic);   myMap.zoomTo(graphic.geometry.extent);  }  
0 Kudos