//Grab the FeatureLayer of interest var l = MyMap.Layers["MyFeatureLayerID"] as FeatureLayer; //Create the graphic, set its Geometry with your X,Y values var g = new Graphic() { Geometry = new MapPoint(x, y, MyMap.SpatialReference) }; //Set graphic.Attributes //One way of setting graphic.Attributes is to give them default values. //GetDefaultValueForFieldType() is something you need to write foreach (var f in l.LayerInfo.Fields) { if (f.Editable) g.Attributes[f.Name] = f.Nullable ? null : GetDefaultValueForFieldType(f.Type); } //Another way is to get the PrototypeAttributes that your sevice have defined. //You can get this from either FeatureTypes or Templates (use one of the two following lines) var prototypeAttributes = l.LayerInfo.FeatureTypes.FirstOrDefault().Value.Templates.FirstOrDefault().Value.PrototypeAttributes; var prototypeAttributes = l.LayerInfo.Templates.FirstOrDefault().Value.PrototypeAttributes; foreach (var a in prototypeAttributes) g.Attributes[a.Key] = a.Value; //Finally, add the graphic to your GraphicCollection. On AutoSave=True (which is default), //this will fire a save request. Otherwise, you need to call l.SaveEdits(); l.Graphics.Add(g);
private void InsertByCoordinates(object parameter) { Map map = parameter as Map; if (map != null) { FeatureLayer editableLayer = map.Layers["Editable Layer"] as FeatureLayer; Graphic graphic = new Graphic() { Geometry = new MapPoint(double.Parse(X), double.Parse(Y), map.SpatialReference) }; var atributes = editableLayer.LayerInfo.Templates.FirstOrDefault().Value.PrototypeAttributes; foreach (var atribute in atributes) { graphic.Attributes[atribute.Key] = atribute.Value; } graphic.Attributes.Remove("CODItemIMustPlace"); graphic.Attributes.Add("CODItemIMustPlace", InfoObject.CodItemIMustPlace); editableLayer.Graphics.Add(graphic); editableLayer.SaveEdits(); } }