博客
关于我
mxGraph改变图形大小重置overlay位置
阅读量:794 次
发布时间: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/

你可能感兴趣的文章
MongoDB学习笔记(四)--索引 && 性能优化
查看>>
MongoDB安装及shell简介
查看>>
mongodb定时备份数据库
查看>>
mssql 字增自段怎样重置(重新自增)|清空表已有数据
查看>>
mongodb导出csv json
查看>>
MongoDB工具MagicMongoDBTool使用介绍(一) -- 简单MongoDB入门
查看>>
mongodb工具类
查看>>
MongoDB常见面试题总结(上)
查看>>
MongoDB常见面试题总结(下)
查看>>
MongoDB开发规范与数据建模
查看>>
MongoDB快速入门
查看>>
MongoDB快速插入1000w测试数据(Java)
查看>>
MongoDB性能调优
查看>>
MongoDB插入数据的3种方法
查看>>
mongoDB教程(一):数据库简介
查看>>
mongoDB教程(七):集合的操作
查看>>
mongoDB教程(三):服务开启关闭
查看>>
mongoDB教程(九):可视化管理工具
查看>>
mongoDB教程(二):下载安装
查看>>
mongoDB教程(五):命名规范
查看>>