Andres Toussaint wrote:

how do you recover the actual visual coordinates of a rotated item in the canvas?

When you talk about coordinates you need to be clearer what coodinate system you mean. Also it isn't clear what you mean by 'item'.

When you click on the item, it gives you the coordinates as if the object was not translated, i imagine to keep the hotspot active, regardless of the transformation.

The Click clientX/Y attributes have the location of the click relative to the upper left of the JSVGComponent. It sounds a bit like you want to transform this to the coordinate system of the root SVG element (after the viewing transform - user pan/zoom/rotate and after the viewBox transform - width/height -> viewBox).

I need to get the actual translated (rotated) coordinates of the click location (in reference to the full canvas) as well, since i am doing some graphics 2D on top of my SVG. Is there a way to get these coordinates, or shall i perform my own formulas?

Essentially you should replace 'evt.getTarget()' with the element you want the point to be in the user coordinate system of. In this case I think you want the root SVG element. It is possible that you don't want the viewBox transform in which case you would need to combine 'getScreenCTM' with 'getCTM' (read the SVG Spec on SVGLocatable for details).

I am retrieving my coordinates by:

public class OnMoveAction implements EventListener {
public void handleEvent(Event evt) {
//Cast the event onto a Batik Mouse event, co we can get ccordinates
DOMMouseEvent elEvt = (DOMMouseEvent)evt;
int nowToX = elEvt.getClientX();
int nowToY = elEvt.getClientY();
//convert it to a point for use with the Matrix
SVGOMPoint pt = new SVGOMPoint(nowToX, nowToY);
//Get the item¥s screen coordinates, and apply the transformation
SVGMatrix mat = ((SVGLocatable)evt.getTarget()).getScreenCTM(); // elem -> screen
mat = mat.inverse(); // screen -> elem
dragpt = (SVGOMPoint)pt.matrixTransform(mat);
...
}
}



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to