通用
getBBox()
获取元素的包围盒。
返回值
- 返回值类型:object。
返回值对象包括以下属性:
名称 | 类型 | 描述 |
---|---|---|
x | number | 视口x坐标 |
y | number | 视口y坐标 |
width | number | bbox宽度 |
height | number | bbox高度 |
centerX | number | 中心点x坐标 |
centerY | number | 中心点y坐标 |
用法
item.getBBox();
getContainer()
获取元素的容器。
返回值
- 返回值类型:G.Group;
- 返回元素所在的group。
用法
// 获取元素的容器
const group = item.getContainer();
// 等价于
const group = item.get('group');
getKeyShape()
获取元素的关键形状,用于计算节点大小、连线截距等。
返回值
- 返回值类型:G.Shape;
- 返回元素的keyShape。
用法
// 获取元素的容器
const keyShape = item.getKeyShape();
// 等价于
const keyShape = item.get('keyShape');
getModel()
获取元素的数据模型。
返回值
- 返回值类型:object;
- 返回元素的数据模型。
用法
// 获取元素的容器
const model = item.getModel();
// 等价于
const model = item.get('model');
getType()
获取元素的类型。
返回值
- 返回值类型:string;
- 返回元素的类型。
用法
// 获取元素的容器
const type = item.getType();
// 等价于
const type = item.get('type');
enableCapture(enable)
是否拾取及触发该元素的交互事件。
参数
名称 | 类型 | 是否必选 | 描述 |
---|---|---|---|
enable | boolean | true | 是否允许该元素响应事件的标识,如果为true,则允许,否则不允许 |
用法
// 不允许元素响应事件
item.enableCapture(false);
// 允许元素响应事件
item.enableCapture(true);
clearCache()
更新或刷新等操作后,清除缓存。
用法
// 清除缓存
item.clearCache();