Select to view content in your preferred language

Zoom to extent of query results.

1336
3
03-03-2011 11:48 AM
ThomasDyer
Emerging Contributor
I'm using the Flexviewer 2.2 Query widget. I would like the map to zoom to the extent of the query results. I used the following code plugged into the "onResults" function of the widget:

        {
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
if (graphicsExtent)
{
map.extent = graphicsExtent.expand(2.0);
}
         }

It works fine ONCE, but will not work for the same query again. After stepping around the code, it seems that query results are stored somewhere and the query is not rerun every time, so my little piece of code is not run again. I have tried moving the code around, clearing arrays, clearing graphics layers and still nothing. So, I come humbly before the masters seeking advice. Be gentle I'm new to programming, especially Flex.
Tags (2)
0 Kudos
3 Replies
ReneRubalcava
Esri Frequent Contributor
Looking at the Query Widget, it looks like the query is just run the one time on the first load and results parsed and stored in queryResultAC. This is probably to save the time of having to rerun the query each time you close/open the widget.

If you'd like to zoom the query results each time the widget is open, you can listen for the addedToStage event on something. I tried it out and added it to the QueryResultDataGroup
<Query:QueryResultDataGroup id="queryResultDG" addedToStage="queryResultDG_addedToStageHandler(event)" ...


Then do something like this.
protected function queryResultDG_addedToStageHandler(event:Event):void
{
 if (graphicsLayer) // need this because on first load, value is null
  map.extent = GraphicUtil.getGraphicsExtent(ArrayCollection(graphicsLayer.graphicProvider).toArray());
}


That should get you started.
0 Kudos
ThomasDyer
Emerging Contributor
Rene,

That worked great! Thanks for the quick and helpful response.
0 Kudos
AsseticTop_Administrator
Emerging Contributor
Looking at the Query Widget, it looks like the query is just run the one time on the first load and results parsed and stored in queryResultAC. This is probably to save the time of having to rerun the query each time you close/open the widget.

If you'd like to zoom the query results each time the widget is open, you can listen for the addedToStage event on something. I tried it out and added it to the QueryResultDataGroup
<Query:QueryResultDataGroup id="queryResultDG" addedToStage="queryResultDG_addedToStageHandler(event)" ...


Then do something like this.
protected function queryResultDG_addedToStageHandler(event:Event):void
{
 if (graphicsLayer) // need this because on first load, value is null
  map.extent = GraphicUtil.getGraphicsExtent(ArrayCollection(graphicsLayer.graphicProvider).toArray());
}


That should get you started.


How do you do this with ArcGIS Silverlight API?
0 Kudos