Select to view content in your preferred language

Add Graphic with attributes

1063
1
04-26-2012 09:52 PM
DeepikaJain
Occasional Contributor
Dear All

I am currently wokring on ArcGIS API for Silverlight version 2.4. I working on the fcutnionaltiy of TRIM features where in the user can select the line feature to be trimmed, it does generate the result but it generates as a graphic, I am trying to replace that feature with the result graphic, but I am not able to do it.

Here is the code for that:
protected void TrimEnd_Click(object sender, EventArgs e)
        {
            foreach (string layerID in featureLayerIDs)
            {
                FeatureLayer fLayer = this.MapControl.Layers[layerID] as FeatureLayer;


                    foreach (Graphic g in fLayer.SelectedGraphics)
                    {
                        if(g != null)
                        {
                            getFeatLayer = fLayer;
                            MyDrawObject = new Draw(this.MapControl)
                            {
                                DrawMode = DrawMode.Polyline,
                                IsEnabled = true,
                                LineSymbol = this.Resources["NewLineSymbol"] as ESRI.ArcGIS.Client.Symbols.LineSymbol
                             };
                        }

                    }
                    MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;

                }
           }

        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MyDrawObject.IsEnabled = false;

            //getFeatLayer.ClearGraphics();

            Polyline polyline = args.Geometry as Polyline;
            polyline.SpatialReference = this.MapControl.SpatialReference;

            GeometryService geometryService =
            new GeometryService("http://*****/ArcGIS/rest/services/Geometry/GeometryServer");
            geometryService.TrimExtendCompleted += GeometryService_TrimExtendCompleted;
            geometryService.Failed += GeometryService_Failed;

            List<Polyline> polylineList = new List<Polyline>();
            foreach (Graphic g in getFeatLayer.SelectedGraphics)
                polylineList.Add(g.Geometry as Polyline);

            geometryService.TrimExtendAsync(polylineList, polyline, CurveExtension.DefaultCurveExtension);
        }

        void GeometryService_TrimExtendCompleted(object sender, GraphicsEventArgs e)
        {
            //getFeatLayer.ClearGraphics();
            Graphic resultGraphic = null;
            foreach (Graphic g in e.Results)
            {
               
                g.Symbol = this.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                resultGraphic = g;
                //getFeatLayer.Graphics.Add(g);
                GraphicsLayer TrimGraphicLyr = this.graphicsLayer as GraphicsLayer;
                //TrimGraphicLyr.ClearGraphics();
                //TrimGraphicLyr.Graphics.Add(g);
              
                getFeatLayer.Graphics.Add(g);
            }
              
                 foreach (Graphic g1 in getFeatLayer.SelectedGraphics)
                {
                    //resultGraphic.Attributes.Add(g1.Attributes.ToArray());

                    foreach (var f in getFeatLayer.LayerInfo.Fields)
                     {
                        resultGraphic.Attributes[f.Name] = f.Nullable ? null : "testing";
                     }

                     getFeatLayer.Graphics.Remove(g1);

                }

              
       
                //Editor editor = LayoutRoot.Resources["MyEditor"] as Editor;
               
                foreach (GraphicsLayer graphicsLayer in featureEditor.GraphicsLayers)
                {
                    if (graphicsLayer is FeatureLayer)
                    {
                        FeatureLayer featureLayer = graphicsLayer as FeatureLayer;
                        if (featureLayer.HasEdits)
                            featureLayer.Update();
                            featureLayer.SaveEditsFailed+=new EventHandler<TaskFailedEventArgs>(featureLayer_SaveEditsFailed);
                            featureLayer.SaveEdits();
                            featureLayer.Refresh();

                    }
                }

              
           

            MyDrawObject.IsEnabled = true;
        }



        protected void featureLayer_SaveEditsFailed(object sender, EventArgs e)
        {
          
        }
       
It thorws an error on saveedits failed with code 400- Unable to complete Operation, Unable to apply edits.

Any help would be greatly appreciated.
0 Kudos
1 Reply
dotMorten_esri
Esri Notable Contributor
Does the datatypes you set in your attributes match the fields? Ie. string for string types, double for double types etc. Also there are read-only fields (like ObjectID) that you shouldn't be setting.
0 Kudos