要在改變圖形大小的時候改變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的時候可以自定義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;
};