Select to view content in your preferred language

Example of zooming to all results of FindTask

853
2
07-20-2011 12:03 PM
DorothyMortenson
Deactivated User
Hello,
I have a FindTask that I really like. Yeah. It will find the records searching through several layers. It puts the results in a grid. (Very similar to the sample online).

It does not, however, zoom to all the records. Right now, the user has to click on the specific record in the datagrid to zoom to that area.

Anyone have some sample code as to how to zoom to all the records found?

Thanks!
Dorothy
0 Kudos
2 Replies
BrandonCopeland
Emerging Contributor
Quick and untested, but something like...

findTask.ExecuteCompleted += OnExecuteCompleted;


private void OnExecuteCompleted(object sender, FindEventArgs e)
{
     Geometry zoomGeometry;
     foreach (var result in e.FindResults)
     {
          if (zoomGeometry == null)
          {
               zoomGeometry = result.Feature.Geometry.Extent;
               continue;
          }

          zoomGeometry = zoomGeometry.Extent.Union(result.Feature.Geometry.Extent);
     }
     
     YourMap.Extent = zoomGeometry;
}


YourMap is a reference to your map control
0 Kudos
JMcNeil
Deactivated User
Something like this might help and works:

 // If an item has been selected           
            GraphicsLayer AgraphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            //   graphicsLayer.ClearGraphics();

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                // Show selected feature attributes in DataGrid
                foreach (Graphic selectedFeature in featureSet.Features)
                {

                    // Hightlight selected feature
                    selectedFeature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;

                    AgraphicsLayer.Graphics.Insert(0, selectedFeature);

                    // Zoom to selected feature (define expand percentage)

                    ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.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);


                    Map.ZoomTo(new Envelope(displayExtent.XMin + 1.45, displayExtent.YMin + 1.45, displayExtent.XMax - 1.45, displayExtent.YMax - 1.45));
                }

                ResultsDisplay.IsExpanded = true;
            }
                
            MyDrawSurface.IsEnabled = false;


J
0 Kudos