Select to view content in your preferred language

How to Select a graphic

774
3
12-22-2010 10:54 AM
PLadd
by
Frequent Contributor
I want to select a graphic that has already been drawn on the map.  I can't seem to piece this together from sample code so I would appreciate some help.

I have a tiled parcel layer.  When a user IDs (selects) a parcel, a graphic is created showing that selected parcel.  The user would then open a Buffer distance window, enter in a distance and hit OK.  The OK button would fire some kind of code-behind to select the graphic created by the selected parcel (and eventuall buffer it - but I'll ask that in another post if needed).

Can somebody throw me some code that will select an existing graphic?  Thanks.
0 Kudos
3 Replies
ThaoLe
by
Regular Contributor
Can you post the code you currently have?

I think what you can do is to keep a reference to the geometry that you get back from your IdentifyTask. Use that geometry and send it to your buffer.
0 Kudos
PLadd
by
Frequent Contributor
After clicking on a parcel, the two pieces of code below run:

private void MyDrawSurface_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
        {
            GraphicsLayer selectionGraphicslayer = MyMap.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            selectionGraphicslayer.ClearGraphics();

            QueryTask selqueryTask = new QueryTask("http://myserver/arcgis/rest/services/Parcels/MapServer/0");
            selqueryTask.ExecuteCompleted += selQueryTask_ExecuteCompleted;
            selqueryTask.Failed += selQueryTask_Failed;

            // Bind data grid to query results
            Binding resultFeaturesBinding = new Binding("LastResult.Features");
            resultFeaturesBinding.Source = selqueryTask;
           
            Query query = new ESRI.ArcGIS.Client.Tasks.Query();

            // Specify fields to return from query
            query.OutFields.AddRange(new string[] {"GIS_ID", "StreetNumber", "StreetName", "CurrentOwner"});
            query.Geometry = args.Geometry;

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

            selqueryTask.ExecuteAsync(query);

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

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

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

            if (featureSet != null && featureSet.Features.Count > 0)
            {
                int i = 0;
                myGIS_ID = "";
               
                foreach (Graphic feature in featureSet.Features)
                {
                    feature.Symbol = selResultsFillSymbol;
                    graphicsLayer.Graphics.Insert(0, feature);

                    if (i == 0)
                    {
                        myGIS_ID = featureSet.Features.Attributes["GIS_ID"].ToString();
                    }
                    else
                    {
                        myGIS_ID = myGIS_ID + "," + featureSet.Features.Attributes["GIS_ID"].ToString();
                    }
                   
                    i = i + 1;

                }

                LoadAssessor("Map"); //load Property Grid from parcel(s) clicked on
            }
           // MyDrawSurface.IsEnabled = false; //removed so user can continuously use tool - add to ID enable tool
        }
0 Kudos
PLadd
by
Frequent Contributor
This seems to be doing the trick:

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            Graphic g = new ESRI.ArcGIS.Client.Graphic();

            if (graphicsLayer.Graphics.Count > 0)
            {
                IList<Graphic> graphicsList = graphicsLayer.Graphics;

                foreach (Graphic graphic in graphicsList)
                {
                    g.Geometry = graphic.Geometry;
                }
            }
            else
            {
                MessageBox.Show("Nothing selected");
                return;

            }

Then I can buffer the GraphicsLayer.  It's got other issues that need to be worked out but this will get me up and running.
0 Kudos