博客
关于我
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教程(七):集合的操作
查看>>
mongoDB教程(三):服务开启关闭
查看>>
mongoDB教程(八):管理账户
查看>>
mongoDB教程(十一):文档的操作
查看>>
mongoDB教程(十):导入、导出
查看>>
mongoDB教程(四):用户角色
查看>>
MongoDB数据库/集合/文档基本操作
查看>>
mongodb数据库操作--备份 还原 导出 导入
查看>>
mongodb数据库的基本操作
查看>>
mongodb数据库运维常用语法
查看>>
MongoDB整理笔记の增加节点
查看>>
MongoDB文档常见查询
查看>>
MongoDB无法远程连接
查看>>
Mongodb日志报错too many open files,导致mongod进程down
查看>>
MongoDB框架零基础入门
查看>>
mongoDb概述(翻译自官网)
查看>>
mongodb每天上亿数据量定期清理
查看>>
MongoDB的Decimal128类型转换成Java的BigDecimal类型错误
查看>>
mongodb的一些语句使用
查看>>