Hi All,
I have created <g> element with 2 rectangles. I tried to move the group
element using translate. but it is not moving properly. Each time it is going
to initial position, which had before moving the element. I have attached my
sample code for your reference.
OnMouseDownAction
DOMMouseEvent elEvt = (DOMMouseEvent)evt;
actionNode = elEvt.getTarget();
action = DRAG;
Node n = ((Element)elEvt.getTarget()).getParentNode();
startPt = localPt((Element)n, elEvt.getClientX(), elEvt.getClientY());
dragged = false;
OnMouseMoveAction
if (action == DRAG) {
Element ee = (Element)((Element)actionNode).getParentNode();
SVGPoint pt = localPt(ee, elEvt.getClientX(), elEvt.getClientY());
float dx = pt.getX() - startPt.getX();
float dy = pt.getY() - startPt.getY();
ee.setAttribute("transform", "translate(" + dx + ", " + dy + ")");
}
private SVGPoint localPt(Element elem, int x, int y) {
SVGDocument svgDocument = svgCanvas.getSVGDocument();
SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
SVGMatrix imat = mat.inverse();
SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
cPt.setX(x);
cPt.setY(y);
cPt = cPt.matrixTransform(imat);
return cPt;
}
Please give me the better solution for dragging the SVG elements in SVGCanvas.
Thanks,
Selva
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]