标签:javascript mxgraph 复制 移动 图形
实现这个功能非常简单,只需要重写moveCells方法就可以了。下面是源文件中的代码:
mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) {
if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) {
this.model.beginUpdate();
try {
if (clone) {
cells = this.cloneCells(cells, this.isCloneInvalidEdges());
if (target == null) {
target = this.getDefaultParent();
}
}
this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null);
if (target != null) {
var index = this.model.getChildCount(target);
this.cellsAdded(cells, target, index, null, null, true);
}
this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt));
} finally {
this.model.endUpdate();
}
}
return cells;
};接下来要对这个方法进行改造。加一句就可以了mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) {
clone=evt.ctrlKey;//对,就是这啦!
if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) {
this.model.beginUpdate();
try {
if (clone) {
cells = this.cloneCells(cells, this.isCloneInvalidEdges());
if (target == null) {
target = this.getDefaultParent();
}
}
this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null);
if (target != null) {
var index = this.model.getChildCount(target);
this.cellsAdded(cells, target, index, null, null, true);
}
this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt));
} finally {
this.model.endUpdate();
}
}
return cells;
};mxGraph实现按住ctrl键盘拖动图形实现复制图形功能,布布扣,bubuko.com
标签:javascript mxgraph 复制 移动 图形
原文地址:http://blog.csdn.net/gua_381091614/article/details/35569699