Select to view content in your preferred language

How do i rotate a Polygon programmaticly?

2990
6
04-08-2014 02:18 PM
by Anonymous User
Not applicable
Original User: mmoles

I know the toolbar has a rotate option, but how can i rotate polygons programmaticly.

There must be some rotate function  like rotate(myPolygon, deg, centerPoint) somewhere in there.  If not, i guess i will need to write one myself =(
0 Kudos
6 Replies
JianHuang
Deactivated User
Unfortunately, we didn't make it as an API.
You need to check dojox/gfx/matrix library. Here is the short but essential code:

var tx = matrix.rotategAt(angle, anchor);
graphic.getDojoShape().setTransform(tx);
0 Kudos
by Anonymous User
Not applicable
Original User: mmoles

Unfortunately, we didn't make it as an API.
You need to check dojox/gfx/matrix library. Here is the short but essential code:

var tx = matrix.rotategAt(angle, anchor);
graphic.getDojoShape().setTransform(tx);


Sadly this wont work for me.   The command just modifies the svg and not the polygon ring.  I also wanted to use the geographic mercator system to define the location, which is probably still possible to do by creating a point in that coordinate or some other command.   The next issue that I run into is that, when i would zoom out, it then refreshes the layer which removes my changes because its just a graphical change and not the object itself.

I guess i will need to start doing some math =(
0 Kudos
JianHuang
Deactivated User
That code snippet is what we are using in the API to rotate the shape. Once it's done, you need to call graphic.setGeometry() to make it permanent.
There are a lot math going on, but still gfx library can do a lot heavy lifting part.
0 Kudos
by Anonymous User
Not applicable
Original User: mmoles

That code snippet is what we are using in the API to rotate the shape. Once it's done, you need to call graphic.setGeometry() to make it permanent.
There are a lot math going on, but still gfx library can do a lot heavy lifting part.


Is it better to do it this way, or to modify the object and having it redraw?

I was using the mercator system and i was trying var tx = dojox.gfx.matrix.rotategAt(45, -10372784, 3316853)  which sadly doesnt work.   So, how can i convert a geo point to a browser coordinate?

Aaaand, last question... setGeometry(geometry)   .... whats geometry do i pass in?  The tempGraphicsLayer.graphics[2].getDojoShape() object that i did the transformation says it has no getExtent method.
0 Kudos
JianHuang
Deactivated User
0 Kudos
by Anonymous User
Not applicable
Original User: mmoles

awesome, i knew that was in there somewhere.  I also edited my post after your reply asking 1 last question.

setGeometry(geometry) .... whats geometry do i pass in? The tempGraphicsLayer.graphics[2].getDojoShape() object that i did the transformation says it has no getExtent method.  Same goes with trying to pass in  tempGraphicsLayer.graphics[2].geometry funny enough.
0 Kudos