如何在draw2d-js中创建连接时滚动我的画布?

时间:2017-02-28 20:46:51

标签: javascript draw2d-js

我有两个数字,一个在画布的可见区域,另一个在外面(右侧)。由于无法达到其他数字,因此无法建立连接。是否可以在创建连接时向右自动滚动,以便我可以连接到该图?

2 个答案:

答案 0 :(得分:0)

不幸的是,你必须自己处理滚动。试试这样的事情

var canvas = new draw2d.Canvas("canvas_id");
var scrollElement = canvas.getScrollArea();
var viewArea = new draw2d.geo.Rectangle(
                            scrollElement.scrollLeft(), scrollElement.scrollTop(),
                            scrollElement.width() * canvas.zoomFactor, scrollElement.height() * canvas.zoomFactor);

var outputLocator  = new draw2d.layout.locator.OutputPortLocator();
var port = figure.createPort("output", outputLocator);

port.on('drag', function(){

  if (!viewArea.contains(port.getBoundingBox())) {
    // -- the port has moved off the visible area of the canvas so scroll the view.   
  }
})

答案 1 :(得分:0)

画布政策:

var myScroll = draw2d.policy.canvas.CanvasPolicy.extend ({ NAME: 'myScroll',
                init: function() {
                this._super();
              },


onMouseMove: function(the, mouseX, mouseY, shiftKey, ctrlKey) {

        this._super(the, mouseX, mouseY, shiftKey, ctrlKey);

        if (mouseX>the.getWidth()-100+the.getScrollLeft()) { 

            $buffer = $("#canvas").scrollLeft();
            $treshold = 10;
            $("#canvas").scrollLeft($buffer+$treshold);


        }
}