leader
本文回答:
MLeaderEnt多重引线 —— 箭头 + 转折引线 + 文字块。
一、创建(位置参数)
// new MLeaderEnt(arrowPoint?, landingPoint?, textContent?, textHeight?)
const leader = new vjmapext.MLeaderEnt(
[100, 100], // arrowPoint:箭头指向点
[300, 200], // landingPoint:文字侧锚点(起落平台位置)
'注意这里', // textContent(不叫 text)
12 // textHeight
);
leader.color = 0xff0000;
mapcadLayer.addEntity(leader);
二、核心属性(d.ts 真实成员)
| 属性 | 说明 |
|---|---|
arrowPoint |
箭头顶点 |
landingPoint |
文字侧锚点(landing 平台端点) |
vertices |
Point2D[] 中间转折点数组(箭头→landing 之间的折点) |
textContent |
注记内容(单行纯文本,不支持 \P/富文本码;不叫 text) |
textHeight |
文字高度 |
arrowSize |
箭头大小 |
landingLength |
末端水平段(dogleg)长度,默认 textHeight × 1.5 |
textColor |
文字颜色 |
ownerRefs |
关联实体(setOwnerRefs / updateFromOwners) |
三、多转折引线
转折点放 vertices 数组:
const leader = new vjmapext.MLeaderEnt([50, 50], [220, 100], '多段引线', 12);
leader.vertices = [
vjmapext.Point2D.fromArray([100, 100]),
vjmapext.Point2D.fromArray([180, 100])
];
leader.changed();
mapcadLayer.addEntity(leader);
引线几何 = arrowPoint → vertices... → landingPoint → landingLength 水平段 → 文字。
四、文本说明
textContent 渲染时整串构造一个 TextEnt(bundle 中即 new TextEnt(pos, textContent, height) 后直接 toGeoJSON())——不解析 \P 换行、\n 分行、{\C…} 颜色等 MText 富文本码,写了会按字面渲染出来。要多行/富文本请改用 MTextEnt(其内部按 \n 分行),或拆多个实体:
leader.textContent = '更新后的内容';
leader.changed();
五、编辑
- 拖
arrowPoint移动箭头方向 - 拖
vertices中间点调整转折 - 拖文字锚点移动文字块
leader.textContent = '更新后的内容';
leader.changed();
六、与独立实体组合 vs MLeader
| 方式 | 优点 | 缺点 |
|---|---|---|
LineEnt + TextEnt 手工组合 |
完全自由 | 不联动,修改繁琐 |
MLeaderEnt |
文字 / 箭头 / 转折一体 | 部分属性固定 |
推荐 MLeader 用于标准化注记。
七、常见坑
- 构造是位置参数:
(arrowPoint, landingPoint, textContent, textHeight)——没有leaderPoints/textoptions 键;转折点用.vertices数组。 - 属性名:
textContent/landingLength,不是text/dogleg;无arrowType/textAttachment属性(d.ts 里没有)。 - arrowSize 过大:会遮挡指向点;5–10 常见。
- 改 textContent 没刷新:调
changed()。 toJSON/fromJSON会丢 MLEADER(1.0.1):Serializer 无 MLEADER 分支,存成data: {}、读回被静默丢弃(见 drawing/serialize)。