0
私はSVGとポイント(例えば(x、y)=(250,112))を持っています。 BATIKでノード(DOM要素)を特定のポイントに取得することは可能ですか?バティックの座標でSVGノードを取得する方法
私はSVGとポイント(例えば(x、y)=(250,112))を持っています。 BATIKでノード(DOM要素)を特定のポイントに取得することは可能ですか?バティックの座標でSVGノードを取得する方法
ユーザーテンプレートによって開発されたbatik users forumの回答が見つかりました。私はここで解決策を再投稿しますので、より多くの暴露を加えることができます。
public Element elementAtPosition(Document doc, Point2D point) {
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext context = new BridgeContext(userAgent, loader);
context.setDynamicState(BridgeContext.DYNAMIC);
GVTBuilder builder = new GVTBuilder();
GraphicsNode rootGraphicsNode = builder.build(context, doc);
// rootGraphicsNode can be offseted relative to coordinate system
// that means calling this method on coordinates taken directly from the svg file might not work
// check the bounds of rootGraphicsNode to determine where the elements actually are
// System.out.println(rootGraphicsNode.getBounds());
GraphicsNode graphicsNode = rootGraphicsNode.nodeHitAt(point);
if (graphicsNode != null) {
return context.getElement(graphicsNode);
} else {
// if graphicsNode is null there is no element at this position
return null;
}
}
バティック1.9で試験した。このメソッドは、指定された位置の最上位の要素のみを返します。回避策として、要素を削除してnodeHitAtを再度呼び出すことができます。