Select to view content in your preferred language

Zoom to selected feature doesn't work

3510
2
Jump to solution
06-24-2013 02:48 AM
TAMARADIEZ
Deactivated User
Hi,

We have an application developed on Siverlight. One of its tools is to zoom to a selected ward. It used to work but it stop working and I am not sure why. I have debugged the code and  I think it is failing on this part of the code:  
" ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.Geometry.Extent;". Please see all the code below and attached a screenshots of when I hover the selectedFeature and Geometry elements while debugging.

Could someone help me please?

Thanks,

T
  private void WardQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            var enumGraphics = from g in args.FeatureSet
                           orderby (g.Attributes["NAME"] as string) ascending
                           select g;

          
            {
                // If initial query to populate states combobox
                if ((args.UserState as string) == "initial")
                {
                    // Just show on initial load
                    QueryComboBox.Items.Add("Zoom to Ward");

                    //foreach (Graphic graphic in args.FeatureSet.Features)
                    //{
                    //    QueryComboBox.Items.Add(graphic.Attributes["NAME"].ToString());
                    //}
                    foreach (ESRI.ArcGIS.Client.Graphic gn in enumGraphics)
                    {
                        QueryComboBox.Items.Add(gn.Attributes["NAME"].ToString());
                    }


                    QueryComboBox.SelectedIndex = 0;
                    return;
                }

                // Remove the first entry if "Select..."
                if (QueryComboBox.Items[0].ToString().Contains("Zoom to Ward"))
                    QueryComboBox.Items.RemoveAt(0);

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

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


                    // Hightlight selected feature
                    selectedFeature.Symbol = WardSelectSymbol;
                    graphicsLayer.Graphics.Add(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 / 5),
                    selectedFeatureExtent.YMin - (heightExpand / 5),
                    selectedFeatureExtent.XMax + (widthExpand / 5),
                    selectedFeatureExtent.YMax + (heightExpand / 5));

                    Map.ZoomDuration = new TimeSpan(0, 0, 1);
                    Map.PanDuration = new TimeSpan(0, 0, 1);
                    Map.ZoomTo(displayExtent);


                }
            }
          
        }
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: tamadie

Hello tamadie,

I think this post belongs in the API-section of the forums.

However, I think your problem is that you don't return geometries from your query. Have a look at the ReturnGeometry setting.


Hi,

Yes, I add myQuery.ReturnGeometry = true; to the code and it fixed the issue.

I will make sure next time I post this kind of questions in the correct forum.

Many times for your help.

Kind Regards,

T

T

View solution in original post

0 Kudos
2 Replies
JohanCarlsson
Regular Contributor
Hello tamadie,

I think this post belongs in the API-section of the forums.

However, I think your problem is that you don't return geometries from your query. Have a look at the ReturnGeometry setting.
0 Kudos
by Anonymous User
Not applicable
Original User: tamadie

Hello tamadie,

I think this post belongs in the API-section of the forums.

However, I think your problem is that you don't return geometries from your query. Have a look at the ReturnGeometry setting.


Hi,

Yes, I add myQuery.ReturnGeometry = true; to the code and it fixed the issue.

I will make sure next time I post this kind of questions in the correct forum.

Many times for your help.

Kind Regards,

T

T
0 Kudos