EditGeometry Rotation on Rectangle Causes NullReferenceException

937
3
Jump to solution
05-16-2012 06:53 PM
Labels (1)
RyanCoodey
Occasional Contributor III
If I create a DrawMode.Rectangle graphic, start an EditGeometry on it, move the rectangle, then try and rotate it... it throws a NullReferenceException.

If I don't move the rectangle first, the rotation works fine.  But after moving the rectangle, then rotating it crashes.  This does not seem to happen for any of the other DrawMode types... just the rectangle. 

Is this a known bug? Any workarounds?

I am running version 2.4 of the WPF API on .NET 4.

Thanks a lot for any info!

*UPDATE - The rectangle's Graphic.Geometry is of type Envelope... all others are of type Polygon.  So seems the problem is with rotating envelopes after a move.
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor
Actually, Rotation should not be enabled for Envelope geometry.

If however, you converted Envelope to Polygon, just as this code does:
   var env = e.Graphic.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);    e.Graphic.Geometry = p;


I still did not get NullReference after rotate.

View solution in original post

0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
Actually, Rotation should not be enabled for Envelope geometry.

If however, you converted Envelope to Polygon, just as this code does:
   var env = e.Graphic.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);    e.Graphic.Geometry = p;


I still did not get NullReference after rotate.
0 Kudos
RyanCoodey
Occasional Contributor III
Cool, thanks Jennifer... silly me didn't even think to convert it from an envelope to a polygon, but that worked great!

As far as reproducing the error, did you move the envelope around first?  Because the rotate does work until you move it around.  I can make this happen with this Silverlight example too: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DrawGraphics.  Create a rectangle, start editing, move the rectangle, then rotate it.  It doesn�??t throw an error in the example that I can see, but the rectangle does disappear and act up.

Thanks again!
0 Kudos
JenniferNery
Esri Regular Contributor
You're right the issue probably exist in v2.4.

It seems fixed in v3.0 Pre-release sample: http://resourcesbeta.arcgis.com/en/help/silverlight-api/samples/start.htm#DrawGraphics
0 Kudos