博客
关于我
mxGraph改变图形大小重置overlay位置
阅读量:796 次
发布时间:2023-02-09

本文共 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/

你可能感兴趣的文章
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
MySQL DBA 进阶知识详解
查看>>
Mura CMS processAsyncObject SQL注入漏洞复现(CVE-2024-32640)
查看>>