Select to view content in your preferred language

zoom to results using query and querytask

2251
2
09-07-2010 05:50 AM
eddiequinlan
Deactivated User
Hi all,

On my map, I'm trying to zoom to the extent of my selected features after performing a query.  I've read the posts regarding this issue by using "findtask" and "findparameters" and then looping thru the results.

However, my code has already been written to select features by geometry/attributes.  I'd like to zoom to the selected features without having to write my code all over using "findtask".

thanx,
Eddie
GIS Coord
Okaloosa County
Tags (2)
0 Kudos
2 Replies
eddiequinlan
Deactivated User
Hi all,

As soon as I posted this question, I found the answer.  I'm not sure if this is the most efficient way, but it works.

After the query has returned the selected features set the first one to

var selectedExtent:Extent;       
var newGraphic:Graphic=featureSet.features[0];
selectedExtent=Polygon(newGraphic.geometry).extent;

then loop thru the results combining the extents of each polygon as you loop

for each (var myGraphic:Graphic in featureSet.features )

    selectedExtent=selectedExtent.union(Polygon(myGraphic.geometry).extent);

then zoom to the new extent, or a zoom factor, or whatever you choose.

Thanx forum,
Eddie
0 Kudos
DanJensen
Deactivated User
Eddie,

In the samples section you may find a more efficient solution.  Look under Query Tasks --> Zoom to Query result for a little different approach.

Good Luck,
-Dan
0 Kudos