Select to view content in your preferred language

What is wrong with this line?

1215
10
06-23-2011 12:57 PM
NathalieNeagle
Regular Contributor
Why is this failing...what I am I missing?


  private void ExecuteSpatialSpeciesNameButton_Click(object sender, RoutedEventArgs e)
        {

            GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            selectionGraphicslayer.ClearGraphics();


            QueryTask queryTask = new QueryTask((Layers.SelectedItem as FeatureLayer).Url);

            queryTask.ExecuteCompleted += QuerySpa_ExecuteCompleted;
            queryTask.Failed += QuerySpa_Failed;

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

            query.OutFields.Add("*");

//I think it doesn't like this

            FeatureLayer f = Map.Layers[4] as FeatureLayer;

// IT FAILS right after this HERE 
//-------------------------------------------------------??
            query.Geometry = f.Geometry;

            // Return geometry with result features
            query.ReturnGeometry = true;

            queryTask.ExecuteAsync(query);

           
            

        }



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

      
            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features retured from query");
                return;
            }

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


            if (featureSet != null && featureSet.Features.Count > 0)

               // ResultsDisplay.Visibility = Visibility.Visible;

            {
                foreach (Graphic feature in featureSet.Features)
                {

                    switch (featureSet.GeometryType.ToString())
                    {
                        case "Polygon":
                            feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                            break;
                        case "Polyline":
                            feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol;
                            break;
                        case "Point":
                            feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
                            break;
                    }

                    graphicsLayer.Graphics.Insert(0, feature);

                }
                //ResultsDisplay.Visibility = Visibility.Visible;
                ResultsDisplay.IsExpanded = true;
            }
            MyDrawSurface.IsEnabled = false;
        }

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





Please help.
Nathalie
0 Kudos
10 Replies
JenniferNery
Esri Regular Contributor
Ahh! I think what you are attempting to do is clone the attributes?
graphic.Attributes.Add("*", pointLayer.Graphics[pair.Graphic1Index].Attributes);


If yes then, here's how you do it. You need to iterate through the source.Attributes.
Graphic source = pointLayer.Graphics[pair.Graphic1Index];
Graphic graphic = new Graphic(){Geometry = source.Geometry};
foreach(var item in source.Attributes)
 graphic.Attributes[item.Key]= item.Value;


Drinks or no drinks, see you at the UC! 😄
0 Kudos