Zoom to select Query results

566
2
12-16-2010 01:45 PM
DavidAshton
Occasional Contributor III
I have a simple query, which is working great...populates my tablegrid but I'm having trouble with the zoom to selected feature functionality.  Can someone help?


        #region Attribute Query

        private void ExcuteAPNQuery_Click(object sender, RoutedEventArgs e)
       
        {
            GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            selectionGraphicslayer.ClearGraphics();

            QueryTask queryTask = new QueryTask("http://dgpdch01/ArcGIS/rest/services/Parcels/MapServer/0");
            queryTask.ExecuteCompleted += AQueryTask_ExecuteCompleted;
            queryTask.Failed += AQueryTask_Failed;

            Query query = new ESRI.ArcGIS.Client.Tasks.Query();

            query.Where = string.Format("APN = '{0}'", FindAPN.Text);

            query.OutFields.Add("*");
           
            query.Text = FindAPN.Text;

            _queryTask.ExecuteAsync(query);
        }


        private void AQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
          //  FeatureSet featureSet = args.FeatureSet;

         //   GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;

         //   if (MySelectionGraphicsLayer = null && MySelectionGraphicsLayer.Features.Count > 0)
       //     {

               // Graphic feature = featureSet.Features[0];
               // foreach (Graphic feature in featureSet.Features)
                {
                //    feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                //    graphicsLayer.Graphics.Insert(0, feature);

                    // Zoom to selected feature (define expand percentage)

                    ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = Feature.Geometry.Extent;

                    double expandPercentage = 30;

                    double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100);
                    double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);

                    ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    selectedFeatureExtent.XMin - (widthExpand / 2),
                    selectedFeatureExtent.YMin - (heightExpand / 2),
                    selectedFeatureExtent.XMax + (widthExpand / 2),
                    selectedFeatureExtent.YMax + (heightExpand / 2));

                    Map.ZoomTo(displayExtent);

         //       }

                ResultsDisplay.Visibility = Visibility.Visible;
            }
            _drawSurface.IsEnabled = false;

        }

      
        private void AQueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query failed: " + args.Error);
        }



0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor

but I'm having trouble with the zoom to selected feature functionality.

What kind of trouble?

In your code, where is coming the 'Feature' from?
 
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = Feature.Geometry.Extent;


As a side note, in 2.1 an 'Expand' method has been added to Envelope class.
0 Kudos
DavidAshton
Occasional Contributor III
dbroux,

Thanks for the reply.  I got it.

Dave
0 Kudos