Select to view content in your preferred language

can we zoom to a feature set

2620
4
04-01-2011 01:28 PM
MuralidharMoka
Emerging Contributor
Hi,

How do I zoom to a featureSet.
void queryTask2_ExecuteCompleted(object sender, QueryEventArgs e)
        {
            FeatureSet feast = e.FeatureSet;
            if(feast!=null & feast.Features.Count > 1)
            {
               
            }
            //..what will be the code here can we do MyMap.ZoomTo(..)
        }
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
You can take the union of each FeatureSet.Features.Geometry.Extent and zoom to this resulting extent.
0 Kudos
AsseticTop_Administrator
Emerging Contributor
You can take the union of each FeatureSet.Features.Geometry.Extent and zoom to this resulting extent.


I have not been able to get your method to work:

private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
           
            if (args.FeatureSet.Features.Count > 0)
            {
                Envelope env = new Envelope();
                ESRI.ArcGIS.Client.Geometry.Geometry geometry = null;

                foreach (Graphic resultFeature in args.FeatureSet.Features)
                {
                    if (resultFeature.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                    {
                        graphicsLayer.Graphics.Add(resultFeature);
                        env.Union(resultFeature.Geometry.Extent);

                        try
                        {
                            resultFeature.Symbol = DefaultLineSymbol;
                        }
                        catch (Exception ex)
                        {
                            //
                        }
                    }
                }
                MyMap.ZoomTo(env.Extent);
            }
            else
            {
                MessageBox.Show("No features found");
            }
        }

I'm still pretty stumped on this problem after reading through the forums - any code example would be great.
0 Kudos
nakulmanocha
Esri Regular Contributor
FeatureSet featureSet = args.FeatureSet;

if (featureSet != null && featureSet.Features.Count > 0)
            {
                ESRI.ArcGIS.Client.Geometry.Envelope  env = new ESRI.ArcGIS.Client.Geometry.Envelope();

                foreach (Graphic feature in featureSet.Features)
                {
                    env = env.Union(feature.Geometry.Extent);                    
                    feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                    graphicsLayer.Graphics.Insert(0, feature);
                }
                //ResultsDisplay.Visibility = Visibility.Visible;
                MyMap.ZoomTo(env);
            }
0 Kudos
JenniferNery
Esri Regular Contributor
Sure, you can with minor adjustment to your code. When you perform a Union between two extents, they both have to be valid extents. The first extent (new Envelope()) does not have its XMin, YMin, XMax, YMax properties set.

if (featureSet != null && featureSet.Features.Count > 0)
{
 Envelope env = null;
 foreach (Graphic feature in featureSet.Features)
 {
  if (env == null)
   env = feature.Geometry.Extent;
  else
   env.Union(feature.Geometry.Extent);
  feature.Symbol = LayoutRoot.Resources["MySymbol"] as SimpleFillSymbol;
  graphicsLayer.Graphics.Insert(0, feature);
 }
 MyMap.ZoomTo(env);
}
0 Kudos