VDF常见问题整理(三十四):如何选定实体的用户操作?

VectorDraw Developer Framework试用版下载


问:

    如何选定实体的用户操作/p>

答:

    为了选择许多图形并对其进行处理,请参见以下代码:

 //Set the section window colors.It is not important but help the user for selecting.  vdcanvas.SetActionFillColor(new Array(0, 0, 255, 100));// fill color for simple window select, from left to right                                                          // ( select only entities completely inside rectangle).  vdcanvas.SetActionCrossFillColor(new Array(0, 255, 0, 100));//fill color for crossing window select ,from right to left                                                               // (select entities that are inside or intersect rectangle).  //begin a selection action  //If a user pick to a point with no entity a new window select will open  //continue add entities until command cancel by right click   //   -or-   // a vdcanvas.ActiveAction.cancel(); method is called by your application  //Selected entities are drawn with Red color  //cmdselectCallback a callback function that is fire when the selection is successfully finished.  vdcanvas.CmdSelect(_cmdselectCallback);  //Is fired when selection successfully finished  function _cmdselectCallback(action) {    //enum all selected entities    if (!action.customData || action.customData.length == 0) return;    for (var k = 0; k < action.customData.length; k++) {        var fig = action.customData[k];//get the selected figure        //do something with figure like hightlight it        fig.HighLight = true;    }    action.vdrawOwner().redraw();  }In order select a single figure see following code:   vdcanvas.PickSize = 8;// 8 pixel wide  vdcanvas.GetUserPoint(_onActionPointIdStateChanged); // prompts the user to pick a point on the control and fire the                                            // _onActionPointIdStateChanged when the action finsh or cancel     function _onActionPointIdStateChanged(action, status) {            var vdcanvas = action.vdrawOwner();            if (status == 'start') {                vdcanvas.Prompt('pick a point');            } else if (status == 'end') {                if (!action.IsCanceled()) {                    //vdcanvas.Prompt('X= ' + action.ResValue[X].toString() + ' Y= ' + action.ResValue[Y].toString());                    var p1 = vdcanvas.WorldToPixel(action.ResValue); //transorm the passed action point from world to pixel                    var fig = vdcanvas.GetEntityFromPoint(p1[X], p1[Y]); //get the last drawn entity passing throw a pick box                                                                   //with center the p1 and size define by vdcanvas.PickSize                    if (fig) {                        //do somthing with selected figure                        //for example mark as highlight and re-draw it                        fig.HighLight = true;                        //redraw a single entity procedure                        vdcanvas.UpdateFig(fig);                        vdcanvas.DrawEntity(fig);                        vdcanvas.Refresh();                        vdcanvas.Prompt(String(fig.HandleId) + " selected");//display the selected figure handle                    }                } else {                    vdcanvas.Prompt('');                }            }        }

    对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

  • 如何排除GroundSurface对象的三角形区域/strong>

  • 复杂自定义对象的入门指南


    如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年10月3日
下一篇 2019年10月3日

相关推荐

发表回复

登录后才能评论