本文共 1718 字,大约阅读时间需要 5 分钟。
在调整图形大小的同时改变overlay的位置,这就需要对原有的图形重置方法进行改进。以下是源文件中的代码:
mxGraph.prototype.resizeCells = function(cells, bounds) { this.model.beginUpdate(); try { this.cellsResized(cells, bounds); this.fireEvent(new mxEventObject(mxEvent.RESIZE_CELLS, 'cells', cells, 'bounds', bounds)); } finally { this.model.endUpdate(); } return cells;};
为了在这个方法中调整overlay的位置,我们需要对其进行适当的修改。首先,需要获取当前图形的所有overlays,并在创建overlay时设置一些属性,如index,这样可以更方便地定位特定的overlay进行调整。
修改后的代码如下:
mxGraph.prototype.resizeCells = function(cells, bounds) { this.model.beginUpdate(); try { this.cellsResized(cells, bounds); this.fireEvent(new mxEventObject(mxEvent.RESIZE_CELLS, 'cells', cells, 'bounds', bounds)); var _this = this; $.each(cells, function(i, item) { var overlays = _this.getCellOverlays(item); $.each(overlays, function(j, overlay) { if (overlay.tooltip === '辐射图') { if (ylCommon.isAllowEdit()) { overlay.offset.x = item.geometry.width - 35; } else { overlay.offset.x = item.geometry.width - 15; } } if (overlay.image.src.indexOf('lock.png') > 0) { overlay.offset.x = item.geometry.width - 15; } }); }); } finally { this.model.endUpdate(); } return cells;};
在这个修改后的代码中,我们首先获取了每个单元格的overlays,然后检查每个overlay的tooltip是否为"辐射图"。如果允许编辑,则将该overlay的位置设置为item.geometry.width - 35
;否则,则设置为item.geometry.width - 15
。此外,如果overlay的图片路径包含"lock.png",则将其位置设置为item.geometry.width - 15
。
这种方法通过直接修改overlay的位置属性,使得在调整图形大小时,overlay的位置也能随之改变。
转载地址:http://tjffk.baihongyu.com/