2017-08-16 139 views
0

我已經使用以下代碼拖拽事件

function addOverlay(vertex,graph) { 
    var imgo = new mxImage("images/collapsed.gif",11,11); 
    var overlay = new mxCellOverlay(imgo,"", 
      mxConstants.ALIGN_RIGHT,mxConstants.ALIGN_MIDDLE, 
      new mxPoint(1, 1),mxConstants.CURSOR_TERMINAL_HANDLE); 
    graph.addCellOverlay(vertex, overlay); 

    // Installs a handler for clicks on the overlay 
    overlay.addListener(mxEvent.CLICK, function(sender, evt2) { 
     var cell = evt2.getProperty('cell'); 
     var state = graph.view.getState(cell); 
     graph.connectionHandler.start(state, 1, 1); 
     graph.isMouseDown = true; 
     graph.isMouseTrigger = true; 
     mxEvent.consume(evt2); 
    }); 
} 

該功能的工作原理創建節點插入到圖像節點上的覆蓋如下

node with overlay

現在上示出的圖像中的點擊覆蓋圖,通過將邊連接到所需的頂點來正確添加邊,但我想通過拖動覆蓋圖來繪製邊。

我該如何做到這一點?

回答

0

Overrride mxCellRenderer.installCellOverlayListeners如下:

graph.cellRenderer.installCellOverlayListeners = function(state, 
    overlay, shape) 
{ 
    mxEvent.addGestureListeners(shape.node, function(evt) 
    { 
    graph.connectionHandler.start(state, 1, 1); 
    graph.isMouseDown = true; 
    graph.isMouseTrigger = true; 
    mxEvent.consume(evt); 
    }); 
}; 
+0

多謝,這是解決我的情況 – Saurabh