mxGraph 叠加层上的拖动事件
Drag event on mxGraph overlay
我使用以下代码在图像节点上插入了一个叠加层
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);
});
}
此功能有效创建节点,如下图所示
现在单击叠加层,通过将其连接到所需的顶点来正确添加边,
但我想通过在叠加层上拖动来绘制边缘。
我怎样才能做到这一点?
重写 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);
});
};
我使用以下代码在图像节点上插入了一个叠加层
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);
});
}
此功能有效创建节点,如下图所示
现在单击叠加层,通过将其连接到所需的顶点来正确添加边, 但我想通过在叠加层上拖动来绘制边缘。
我怎样才能做到这一点?
重写 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);
});
};