/// <summary> /// Rectangle_DrawObject DrawComplete event handler /// Adds user drawn rectangle to Projects FeatureLayer /// </summary> /// <param name="sender"></param> /// <param name="args">DrawEventArgs</param> private void Rectangle_DrawObject_DrawComplete(object sender, DrawEventArgs args) { Rectangle_DrawObject.IsEnabled = false; //Ready the graphic Graphic graphic = new Graphic() { Geometry = args.Geometry }; // Input spatial reference for buffer operation defined by first feature of input geometry array graphic.Geometry.SpatialReference = Map.SpatialReference; AddProjectGraphic(graphic); } /// <summary> /// AddProjectGraphic /// Adds graphic to Projects_Edit featurelayer /// </summary> /// <param name="graphic">Graphic to be added</param> private void AddProjectGraphic(Graphic graphic) { // Retrieve the Projects featurelayer from the application FeatureLayer projects = Map.Layers["Projects_Edit"] as FeatureLayer; // add attributes to the graphic // loop through the field list foreach (var field in projects.LayerInfo.Fields) { // only add fields that are editable and set to null if (field.Editable) { graphic.Attributes[field.Name] = null; } } // end loop // Add the buffered line graphic to the featurelayer if (projects != null) { projects.Graphics.Add(graphic); // turn off datagrid/turn on dataform DocumentFeatureDataGrid.Visibility = Visibility.Collapsed; DocumentFeatureDataForm.Visibility = Visibility.Visible; // set the data forms source to new graphic DocumentFeatureDataForm.GraphicSource = graphic; } }Solved! Go to Solution.
var env = e.Geometry as Envelope; Polygon p = new Polygon() { SpatialReference = env.SpatialReference }; PointCollection ring = new PointCollection(); ring.Add(new MapPoint(env.XMin, env.YMin)); ring.Add(new MapPoint(env.XMin, env.YMax)); ring.Add(new MapPoint(env.XMax, env.YMax)); ring.Add(new MapPoint(env.XMax, env.YMin)); ring.Add(new MapPoint(env.XMin, env.YMin)); p.Rings.Add(ring); var graphic = new Graphic() { Geometry = p }; var env = e.Geometry as Envelope; Polygon p = new Polygon() { SpatialReference = env.SpatialReference }; PointCollection ring = new PointCollection(); ring.Add(new MapPoint(env.XMin, env.YMin)); ring.Add(new MapPoint(env.XMin, env.YMax)); ring.Add(new MapPoint(env.XMax, env.YMax)); ring.Add(new MapPoint(env.XMax, env.YMin)); ring.Add(new MapPoint(env.XMin, env.YMin)); p.Rings.Add(ring); var graphic = new Graphic() { Geometry = p };
Graphic graphic;
if (Rectangle_DrawObject.DrawMode == DrawMode.Rectangle)
{
var env = args.Geometry as Envelope;
ESRI.ArcGIS.Client.Geometry.Polygon p = new ESRI.ArcGIS.Client.Geometry.Polygon() { SpatialReference = env.SpatialReference };
ESRI.ArcGIS.Client.Geometry.PointCollection ring = new ESRI.ArcGIS.Client.Geometry.PointCollection();
ring.Add(new MapPoint(env.XMin, env.YMin));
ring.Add(new MapPoint(env.XMin, env.YMax));
ring.Add(new MapPoint(env.XMax, env.YMax));
ring.Add(new MapPoint(env.XMax, env.YMin));
ring.Add(new MapPoint(env.XMin, env.YMin));
p.Rings.Add(ring);
graphic = new Graphic() { Geometry = p };
}
else
{
//Ready the graphic
graphic = new Graphic()
{
Geometry = args.Geometry
};
}