js中实现代码说明:

动态拖放时的绘制事件:

function DoDynWorldDrawFun(dX,dY,pWorldDraw,pData) {
//自定义实体的GUID标识符
var sGuid = pData.Guid;
//设置自定义事件的返回值
mxOcx.SetEventRet(0); var curPt = mxOcx.NewPoint();
curPt.x = dX;
curPt.y = dY;
if (sGuid == "DrawCircle") {
var pt1 = pData.GetPoint("pt1");
var dR = curPt.DistanceTo(pt1) * 0.5;
var vec = curPt.SumVector(pt1);
vec.Mult(0.5);
pt1.Add(vec);
pWorldDraw.DrawCircle(pt1.x, pt1.y, dR);
} }

动态拖放时的绘制事件:

function  DynWorldDrawComment2( pCustomEntity,pWorldDraw,  curPt) {
// 得到绘制参数. var sText = pCustomEntity.GetString("Text");
var dTextHeight = pCustomEntity.GetDouble("TextHeight");
var iEdgeNumber = pCustomEntity.GetLong("EdgeNumber");
var dShapRadius = pCustomEntity.GetDouble("ShapRadius");
var basePoint = pCustomEntity.GetPoint("BasePoint");
// 创建一个批注对象.
var comment = mxOcx.NewEntity("IMxDrawComment");
comment.Text = sText;
comment.TextHeight = dTextHeight;
comment.EdgeNumber = iEdgeNumber;
comment.ShapRadius = dShapRadius;
comment.basePoint = basePoint;
comment.Position = curPt;
// 设置文字样式。
pWorldDraw.TextStyle = "MyCommentFont";
// 动态绘制.
pWorldDraw.DrawEntity(comment);
}

动态绘制文字:

function ExplodeFun(pCustomEntity, pWorldDraw, txt) {
var sGuid = pCustomEntity.Guid;
if (sGuid == "TestMxCustomEntity1") {
if (!pCustomEntity.IsHave("First"))
return;
var stp = pCustomEntity.GetPoint("First");
var ept = pCustomEntity.GetPoint("BasePoint");
var dimpt = pCustomEntity.GetPoint("DimPoint");
var txt = pCustomEntity.GetString("Text");
var textH = pCustomEntity.GetDouble("TextHeight");
var edgeNum = pCustomEntity.GetLong("EdgeNumber");
var shapRadius = pCustomEntity.GetDouble("ShapRadius");
var isCircle = pCustomEntity.GetLong("isCircle");
var comment = mxOcx.NewEntity("IMxDrawComment");
comment.Text = txt;
comment.TextHeight = textH;
comment.EdgeNumber = edgeNum;
comment.ShapRadius = shapRadius;
comment.basePoint = ept;
comment.Position = dimpt;
pWorldDraw.TextStyle = "MyCommentFont";
// 动态绘制.
pWorldDraw.DrawEntity(comment);
// 绘制矩形框.
if (isCircle) {
var dR = stp.DistanceTo(ept) * 0.5;
var vec = stp.SumVector(ept);
vec.Mult(0.5);
ept.Add(vec);
pWorldDraw.DrawCircle(ept.x, ept.y, dR);
}
else {
pWorldDraw.DrawLine(stp.x, stp.y, stp.x, ept.y);
pWorldDraw.DrawLine(stp.x, ept.y, ept.x, ept.y);
pWorldDraw.DrawLine(ept.x, ept.y, ept.x, stp.y);
pWorldDraw.DrawLine(ept.x, stp.y, stp.x, stp.y);
}
mxOcx.SetEventRet(1);
}
}

动态绘制文字:

function DoCloudLineComment() {
var param = mxOcx.NewResbuf();
param.AddString("");
param.AddDouble(100);
var ret = mxOcx.CallEx("Mx_ShowMTextDialog", param);
if (ret.AtString(0) != "Ok") {
return;
}
var txt = ret.AtString(1);
var txtH = ret.AtDouble(2);
var txtColorIndex = ret.AtLong(3);
// 加入换行操作符\\P
//txt = txt + "\\PTEST";
// 创建一个文字样式,用于批注文字字体.
mxOcx.AddTextStyle2("MyCommentFont", "黑体", 0.7);
// 创建一个与用户交互取点的对象。
var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
getPt.message = "输入标注插入基点";
// 设置动态绘制参数.
var spDrawData = getPt.InitUserDraw("DrawComment");
spDrawData.SetString("Text", txt);
spDrawData.SetDouble("TextHeight", txtH);
spDrawData.SetLong("EdgeNumber", 0);
spDrawData.SetDouble("ShapRadius", 300);
// 开始取第一个点。
if (getPt.go() != 1)
return;
// 创建一个与用户交互取点的对象。
var getSecondPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
getSecondPt.message = "输入标注位置点";
getSecondPt.basePoint = getPt.value();
getSecondPt.setUseBasePt(false);
spDrawData = getSecondPt.InitUserDraw("DrawComment2");
// 设置动态绘制参数.
spDrawData.SetPoint("BasePoint", getPt.value());
spDrawData.SetString("Text", txt);
spDrawData.SetDouble("TextHeight", txtH);
spDrawData.SetLong("EdgeNumber", 0);
spDrawData.SetDouble("ShapRadius", 300);
// 开始取第二个点。
if (getSecondPt.go() != 1)
return;
var ret = spDrawData.Draw();
// 设置绘制的批注文字样式。
for (var i = 0; i < ret.Count; i++) {
var ent = ret.AtObject(i);
ent.TextStyle = "MyCommentFont";
ent.colorIndex = txtColorIndex;
if(ent.ObjectName == "McDbComment")
{
ent.BoundingBoxType = 4;
ent.ArrowType = 2;
ent.ShapRadius = 40;
}
}
}

最新文章

  1. TabLayout和ViewPager简单实现页卡的滑动
  2. MMORPG大型游戏设计与开发(客户端架构 part2 of vgui)
  3. LoadRunner 录制IE 8卡死
  4. 实用技巧:简单而有用的nohup命令介绍(转)
  5. js原型和原型链个人理解(我的理解)
  6. UVA 12563 Jin Ge Jin Qu hao
  7. c_数据结构_队的实现
  8. Python的基本语法2
  9. bzoj 4767 两双手 - 动态规划 - 容斥原理
  10. 【VS2019】F12跳转到源码
  11. kafka AdminClient 闲时关闭连接
  12. 论如何优雅的自定义ThreadPoolExecutor线程池
  13. HTML中的table导出为Excel文件
  14. spring集成shiro报错解决(no bean named &#39;shiroFilter&#39; is defined)
  15. hadoop yarn组件介绍
  16. 【转】.NET NPOI操作Excel常用函数
  17. 进程process与线程thread
  18. 命令行模式启动VMWare虚拟机
  19. CF915E Physical Education Lessons
  20. Python制作回合制手游外挂简单教程(下)

热门文章

  1. mysql使用小结
  2. 51nod1242【矩阵快速幂】
  3. SpringBoot2.0 整合 Swagger2 ,构建接口管理界面
  4. SimpleDateFormat线程不安全(转)
  5. js监听键盘提交表单
  6. VLAN-5-802.1Q-in-Q隧道
  7. python 生成器与迭代器
  8. 牛客网Java刷题知识点之Java集合类里面最基本的接口有哪些
  9. Ubuntu安装LAMP
  10. JavaScriptSerializer类序列化日期时需要注意的问题