Select to view content in your preferred language

Zoom to selected features, when one record returned it does not zoom to the graphic

780
4
Jump to solution
08-17-2012 06:04 AM
ionarawilson1
Deactivated User
Hi

Can anybody tell me why if I have just one record returned in the query, the map extent does not go to the graphics extent (most of the time when I have just one record returned)?   Here is the code snippet

for each(var graphic : Graphic in featureSet.features)       {                graphic.symbol = resultsSymbol;        graphic.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);        graphic.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);        if (graphic.attributes.Homepage !== " " || graphic.attributes.Email !==" ")        {        graphic.addEventListener(MouseEvent.CLICK, clickongraphic)        }                myGraphicslayer.add(graphic);                           }                             var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);       if (graphicsExtent)       {                        //IT STOPS WORKING AFTER A FEW  QUERIES!!!!        myMap.extent = graphicsExtent.expand(1.3); //zoom out a little               if (!myMap.extent.contains(graphicsExtent))        {         myMap.level--;        }        


I also tried this other code with no success:


   var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;                     var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());                     map.extent = graphicsExtent.expand(1.1); // zoom out a little                 }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Are you zooming to points? If so, take a look at this thread

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor
Are you zooming to points? If so, take a look at this thread
0 Kudos
ionarawilson1
Deactivated User
Thank you so much. That worked

I used

   if (featureSet.features.length == 1)
      {
      
       for each(var graphic2 : Graphic in featureSet.features)
       
       {var mapPoint:MapPoint = MapPoint(graphic2.geometry);
      
       myMap.centerAt(mapPoint);
       myMap.scale = 4500;
       }

      
      }


But I am wondering if it is just one point, would I have a better way to access that one point instead of creating a loop
using for each(var graphic2 : Graphic in featureSet.features)
0 Kudos
AnthonyGiles
Honored Contributor
ionara,

Yes as you are already doing a check for a single feature you do not need to have the for loop.

Just access the geometry of the single feature directly should be something like featureSet.features[0].geometry

Regards

Anthony
0 Kudos
ionarawilson1
Deactivated User
Thank you Anthony! U guys are awesome!
0 Kudos