返回介绍

绘制矩形框标注

发布于 2023-08-09 23:10:34 字数 4903 浏览 0 评论 0 收藏 0

js中实现代码说明:

动态拖放时的绘制事件:

function  DynWorldDrawComment2( pCustomEntity,pWorldDraw,  curPt) {
    var mxOcx = document.getElementById("MxDrawXCtrl");
    // 得到绘制参数.
    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 mxOcx = document.getElementById("MxDrawXCtrl");
    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 DoComment3() {
    var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getPt.message = "点取第一点";
    if (getPt.go() != 1) {
        return;
    }
    var frstPt = getPt.value();
    if (frstPt == null)
        return;
    var utl = mxOcx.NewUtility();
    var secondPt = utl.GetCorner(frstPt, "点取第二点");
    if (secondPt == null)
        return;
    var param = mxOcx.NewResbuf();
    param.AddString("");
    param.AddDouble(200);
    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 getSecondPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getSecondPt.message = "输入标注位置点";
    getSecondPt.basePoint = secondPt;
    getSecondPt.setUseBasePt(false);
    spDrawData = getSecondPt.InitUserDraw("DrawComment2");
    // 设置动态绘制参数.
    spDrawData.SetPoint("BasePoint", secondPt);
    spDrawData.SetString("Text", txt);
    spDrawData.SetDouble("TextHeight", txtH);
    spDrawData.SetLong("EdgeNumber", 2);
    spDrawData.SetDouble("ShapRadius", 1);

    // 开始取第二个点。
    if (getSecondPt.go() != 1)
        return;
    var ent = mxOcx.DrawCustomEntity("TestMxCustomEntity1", "");
    ent.SetPoint("BasePoint", secondPt);
    ent.SetString("Text", txt);
    ent.SetDouble("TextHeight", txtH);
    ent.SetLong("EdgeNumber", 2);
    ent.SetDouble("ShapRadius", 1);
    ent.SetPoint("DimPoint", getSecondPt.value());
    ent.SetPoint("First", frstPt);
    ent.TextStyle = "MyCommentFont";
    ent.colorIndex = txtColorIndex;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文