Drawing oddities in 3.20 API

1244
16
04-10-2017 09:13 AM
TyroneBiggums
Occasional Contributor III

I have a draw tool using the draw and edit toolbar classes. The idea is that the user can draw a shape on the map. There is a UI that allows the user to select the drawn shape from a list. There is a context menu to edit the shape. The problem is with rectangle.

If the user starts to draw a rectangle and drags down and to the right, everything is fine. The edit UI displays, showing the top left point of the rectangle and the bottom right. However, the user cannot edit the bottom right point, to a point that is north of the top left point with out buggy behavior. In fact, if the once bottom right point (now top right) is edited a second time, the rectangle turns into a line.

And, this rectangle to line issue can be replicated by drawing a rectangle upside down. If the user clicks and drags north east, to make the rectangle, the top left point ends up being the bottom left.

I hope I explained this well enough. I understand this to be all in how the expected clockwise creation of points of a shape? Is there anything I can do to make cleaner shapes so they can be edited?

0 Kudos
16 Replies
TyroneBiggums
Occasional Contributor III

Maybe if I asked this differently. In code I have:

toolbar.on("draw-end", addGraphic);

The graphic object is passed to addGraphic.

To grab the top left point of a rectangle, I have this in code:

item.Geometry.Polygon.Rings[0][0][0] = x; // top-left x
item.Geometry.Polygon.Rings[0][0][1] = y; // top-left y

Since [0][0][0], [0][0][1] is the x, y of the first point drawn (where the user first clicks the map) to begin drawing the rectangle, x, y is not always the top left point of the rectangle.

Is there a way to draw, or re-draw, a shape clockwise from the top left most point on the map (that doesn't interfere with the API)?

Maybe the best way is to not go by array position but geo-math?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyrone,

   Since you are working with it as a polygon have you tried to run a GeometryService simplify on it is the polygon.isclockwise(ring) is false?

TyroneBiggums
Occasional Contributor III

Robert, I am using a GeometryService.simplify on it to measure. Thank you for directing me at isClockwise.

0 Kudos
TyroneBiggums
Occasional Contributor III

rscheitlin‌, kind of weird... if I draw a rectangle while clicking and dragging to the NW, the isClockwise returns true. If I click and drag NE or SW, isClockwise returns false. If I click and drag SE or NW, isClockwise will return true.

So, it was a start, but I'm still a little stuck.

0 Kudos
TyroneBiggums
Occasional Contributor III

Oops, actually... that's just using the draw toolbar. GeometryService.simplify puts everything in clockwise as if it is redrawn? isClockwise is true for every way I draw it, and the ring's points are in different positions compared to the draw toolbar.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyrone,

   Strange. What about running the isSimple GeometryEngine method?

https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#issimple 

0 Kudos
TyroneBiggums
Occasional Contributor III

Is that a 3.20 thing? The ref says added in 3.13 but Google doesn't have any results for "geometryEngineAsync issimple 3.20", the ref has no samples and geometryEngineAsync.isSimple (in code) isn't a thing.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyrone,

   Did the link I provide not work for you? There really would not be any samples as this is such a simple method, just create the GeometryEngine class and then run the isSimple(geometry) method and it returns a boolean. GeometryEngineAsync is just another class that run async instead of synchronous.

0 Kudos
TyroneBiggums
Occasional Contributor III

The link worked, however, the isSimple method gives me: TypeError: Object doesn't support property or method 'isSimple' TypeError: Object doesn't support property or method 'isSimple'

0 Kudos