Zoom to a single point!

778
3
07-08-2010 06:18 AM
PaulLang
New Contributor III
Get a query to zoom to a single point?
I have multiple points and polygon working, but not single point.
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Paul,

  The way ESRI handles it in their viewer is to set the maps scale to some predetermined value and center the maps extent on the MapPoint.
0 Kudos
ReneRubalcava
Frequent Contributor
Center and scale works well, but I use this function after determining it's a single point.
You could also have it check geometry type in the function to be safe if you want.
public static function getMapPointExtent(geometry:Geometry):Extent {
 if (geometry) {
  var mapPoint:MapPoint = geometry as MapPoint;
  return new Extent(mapPoint.x, mapPoint.y, mapPoint.x, mapPoint.y, mapPoint.spatialReference);
 }
 else
  return new Extent();
}
0 Kudos
PaulLang
New Contributor III
This is what I went with, thanks to you both for your help!

private function addressQuery():void
        {
         graphicsLayerAddress.clear();
         queryTaskAdd.execute(queryAdd, new AsyncResponder( onResult, onFault));

            function onResult(featureSet:FeatureSet, token:Object = null):void
            {
            
             if (featureSet.features.length == 0)
                {
                 Alert.show("Please try again.");
                }
                else
                {
              for each (var GraphicAddress:Graphic in featureSet.features)
              {
               GraphicAddress.toolTip = "High School:  " + GraphicAddress.attributes.DISTHIGH + "\n" + "Middle School:  "
               + GraphicAddress.attributes.DISTMIDDLE + "\n" + "Elementary School:  " + GraphicAddress.attributes.DISTELEMEN + "\n" +
               "Police District:  " + GraphicAddress.attributes.PoliceDistricts + "\n" +
               "Fire District:  " + GraphicAddress.attributes.FireDistrict  + "\n" +
               "EMS Rescue:  " + GraphicAddress.attributes.EMSRESCUE + "\n" +
               "EMS Gems:  " + GraphicAddress.attributes.EMSGEMS;
              
              }
              var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
              if (featureSet.features.length == 1)
              {
               var gra:Graphic = GraphicAddress;
      var pt:MapPoint = null;
      pt = gra.geometry as MapPoint;
      MainMap.scale = 1200;
      MainMap.centerAt(pt);
              }
              else
                    {
                        MainMap.extent = graphicsExtent;
                    }
     dpFlat.push(dataGridAddress.dataProvider.toString());
             }
            }
           
            function onFault(info:Object, token:Object = null):void
            {
                Alert.show(info.toString());
            }
        }
0 Kudos