博客
关于我
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/

你可能感兴趣的文章
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>