Javascript 如何在draw2d中的特定位置添加图形?
我想在连接的开始或结束位置添加标签。但在这里我并没有找到定位器,除了曼哈顿IDPOINT定位器。那我该怎么做呢?如何将标签放置在连接的位置?Javascript 如何在draw2d中的特定位置添加图形?,javascript,draw2d-js,Javascript,Draw2d Js,我想在连接的开始或结束位置添加标签。但在这里我并没有找到定位器,除了曼哈顿IDPOINT定位器。那我该怎么做呢?如何将标签放置在连接的位置? 请在下面找到我的代码 draw2d.LabelConnection = function() { draw2d.Connection.call(this); this.sourcePort = null; this.targetPort = null; this.lineSegments = []; this.setColor(new
请在下面找到我的代码
draw2d.LabelConnection = function() {
draw2d.Connection.call(this);
this.sourcePort = null;
this.targetPort = null;
this.lineSegments = [];
this.setColor(new draw2d.Color(0, 255, 0));
this.setLineWidth(2);
var label = new draw2d.Label("Message");
label.setBackgroundColor(new draw2d.Color(230, 230, 250));
label.setBorder(new draw2d.LineBorder(1));
this.addFigure(label, new draw2d.Locator());
};
draw2d.LabelConnection.prototype = new draw2d.Connection();
draw2d.LabelConnection.prototype.type = "draw2d.LabelConnection";
上述代码在(0,0)位置显示标签。
请帮帮我。我不确定你所说的“任何位置”是什么意思,但如果你实现了自己的定位器,那就相当简单了
查看曼哈顿IDPOINT定位器的代码。在重新定位函数中,您了解画布上连接的所有信息。因此,您只需发明一个标签位置的计算。现在使用Graphiti代替Draw2D,但定位器的代码应如下所示(未测试):
draw2d.StartConnectionLocator=函数(/*:draw2d.Connection*/Connection)
{
draw2d.ConnectionLocator.call(this,connection);
};
draw2d.StartConnectionLocator.prototype.relocate=函数(/*:draw2d.Figure*/target)
{
var conn=this.getConnection();
var points=conn.getPoints();
var索引=数学地板((points.getSize()-2)/2);
如果(points.getSize()使用:
连接。getStartPoint()以确定连接的开始点
检索连接的所有段
问候语我想在起始位置而不是中间位置找到这个标签。那么我该怎么做呢?我使用了Locator(),但它在(0,0)位置找到了它。plz帮助?正如Andreas建议的那样,你可以使用connection.getStartPoint()代替var startPoint=points.get(0);我使用了connection.getStartPoint(),但它给了我错误定位器。relocate()不是函数。请帮助我了解如何调用重定位方法。请在draw2d.ContextmenuConnection=function(src,target){draw2d.Connection.call(this);this.sourceAnchor.setOwner(src);this.targetAnchor.setOwner(target);var label=new draw2d.label(“消息”);this.addFigure(label,this.getStartPoint());var arrowConnector=new draw2d.arrowconnectioncorator();arrowConnector.setBackgroundColor(new draw2d.Color(0,255,0));};我使用了Connection.getStartPoint()方法,它给了我错误定位器。relocate()不是一个函数。请帮助我。我尝试实现relocate()方法,但似乎不起作用。
draw2d.StartConnectionLocator=function(/*:draw2d.Connection*/ connection)
{
draw2d.ConnectionLocator.call(this,connection);
};
draw2d.StartConnectionLocator.prototype.relocate=function(/*:draw2d.Figure*/ target)
{
var conn = this.getConnection();
var points = conn.getPoints();
var index = Math.floor((points.getSize() -2) / 2);
if (points.getSize() <= index+1)
return;
var startPoint = points.get(0);
var myPosition = new draw2d.Point();
myPosition.x = startPoint.x +5;
myPosition.y = startPoint.y +5;
target.setPosition(myPosition.x,myPosition.y);
};