• 怎么在c#中使用mapx5.0(二).NET教程,C#语言


       1:  接着第一篇文章,继续,这是在frmain.cs文件中除了第一篇文章里的代码外的第二部分: 
       2:  //******************************* 
       3:   
       4:  #region 创建自定义工具,用来测量距离(能折线)和测量面积 
       5:  //****************************888 
       6:  private void mapmain_polytoolused(object sender, axmapxlib.cmapxevents_polytoolusedevent e) //在创建好自己定义的工具后,会根据工具id来选择执行 
       7:   
       8:  { 
       9:   
      10:  if(e.toolnum == 10)//测量距离,这是自定义工具,测量多点的距离 
      11:   
      12:  { 
      13:   
      14:  mapxlib.points pts = (mapxlib.points)e.points; 
      15:   
      16:  mapxlib.point pt1,pt2; 
      17:   
      18:  double d=0.0; 
      19:   
      20:  //计算顺序两个点距离,累计得到总距离 
      21:   
      22:  for(int i=1;i<pts.count;i++) 
      23:   
      24:  { 
      25:   
      26:  pt1=pts._item(i); 
      27:   
      28:  pt2=pts._item(i+1); 
      29:   
      30:  d += axmap1.distance(pt1.x,pt1.y,pt2.x,pt2.y); 
      31:   
      32:  } 
      33:   
      34:  label1.text="距离:" + d.tostring(); 
      35:   
      36:  } 
      37:   
      38:  else if(e.toolnum == 11) //面积,这是自定义工具,这里借用了某位网友的文章,谢谢 
      39:   
      40:  { 
      41:   
      42:  mapxlib.points pts = (mapxlib.points)e.points; 
      43:   
      44:  mapxlib.featurefactory dd = axmap1.featurefactory; 
      45:   
      46:  mapxlib.style style = axmap1.defaultstyle; 
      47:   
      48:  label1.text="面积:" + dd.createregion(pts,style).area.tostring(); 
      49:   
      50:  } 
      51:   
      52:  } 
      53:  #endregion 
      54:  //******************************* 
      55:   
      56:  private void axmap1_mapviewchanged(object sender, system.eventargs e) //在地图大小改动时,显示出比例 
      57:  { 
      58:  label1.text=axmap1.zoom.tostring(); 
      59:  } 
      60:   
      61:  //******************************* 
      62:  private void mutuceng_click(object sender, system.eventargs e) //菜单按钮事件,显示图层控制面板 
      63:  { 
      64:  axmap1.layers.layersdlg(null,null); 
      65:  } 
      66:   
      67:  private void menuitem31_click(object sender, system.eventargs e) //菜单按钮事件,显示图层图层选择显示窗口 
      68:  { 
      69:  frmviewlyr frm=new frmviewlyr(); 
      70:  frm.owner=this; 
      71:  frm.showdialog(); 
      72:  } 
      73:  private void menuitem32_click(object sender, system.eventargs e) //菜单按钮事件,在新窗口中控制图层的显示比例等, 
      74:  { 
      75:  #region 新窗口中控制图层的显示比例,此处是省略代码 
      76:  //***********此处省略,主要使用到的是 mapunit 和mapzoom ******************* 
      77:  //此处是伪代码,是mapx5.0的示例程式的vb代码,和上面的大同小异 
      78:  // 
      79:  // zoomtext.text = fmainform.map1.zoom 
      80:   
      81:  // set the unit combo box to the current unit 
      82:   
      83:  // take a short cut: units # 0 through 13 correspond to combo list number 
      84:   
      85:  // if fmainform.map1.mapunit < 14 then 
      86:   
      87:  // unitcombo.listindex = fmainform.map1.mapunit 
      88:   
      89:  // else 
      90:   
      91:  // select case fmainform.map1.mapunit 
      92:   
      93:  // case miunitlink 
      94:   
      95:  // unitcombo.listindex = 14 
      96:   
      97:  // case miunitchain 
      98:   
      99:  // unitcombo.listindex = 15 
     100:   
     101:  // case miunitrod 
     102:   
     103:  // unitcombo.listindex = 16 
     104:   
     105:  // end select 
     106:   
     107:  // end if 
     108:   
     109:   
     110:   
     111:  // save the current parameters so that the view can be 
     112:   
     113:  // restored if "cancel" is pressed 
     114:   
     115:  // oldzoom = fmainform.map1.zoom 
     116:   
     117:  // oldunit = fmainform.map1.mapunit 
     118:  #endregion 
     119:   
     120:  } 
     121:  //******************************* 
     122:  private void axmap1_thememodifyrequested(object sender, axmapxlib.cmapxevents_thememodifyrequestedevent e) 
     123:  { 
     124:  //e.theme 
     125:  } 
     126:   
     127:  private void axmap1_mousedownevent(object sender, axmapxlib.cmapxevents_mousedownevent e) 
     128:  { 
     129:  //e.button= 
     130:  } 
     131:   
     132:  private void menuitem4_click(object sender, system.eventargs e) //菜单按钮事件,普通选择地图 
     133:  { 
     134:  axmap1.currenttool=mapxlib.toolconstants.miselecttool; 
     135:  menuitem4.radiocheck=true; 
     136:  } 
     137:   
     138:  private void menuitem5_click(object sender, system.eventargs e) //菜单按钮事件,长方形选择地图 
     139:  { 
     140:  axmap1.currenttool=mapxlib.toolconstants.mirectselecttool; 
     141:  menuitem5.radiocheck=true; 
     142:  } 
     143:   
     144:  private void menuitem6_click(object sender, system.eventargs e) //菜单按钮事件,圆形选择地图 
     145:  { 
     146:  axmap1.currenttool=mapxlib.toolconstants.miradiusselecttool; 
     147:  menuitem6.radiocheck=true; 
     148:  } 
     149:   
     150:  private void menuitem7_click(object sender, system.eventargs e) 
     151:  { 
     152:  axmap1.currenttool=mapxlib.toolconstants.mipolygonselecttool; //菜单按钮事件,多边形选择地图 
     153:  menuitem7.radiocheck=true; 
     154:  } 
     155:   
     156:  private void menuitem8_click(object sender, system.eventargs e) 
     157:  { 
     158:  axmap1.currenttool=mapxlib.toolconstants.milabeltool; //菜单按钮事件,直线标注地图 
     159:  } 
     160:   
     161:  private void menuitem9_click(object sender, system.eventargs e) 
     162:  { 
     163:  //axmap1.currenttool=mapxlib.toolconstants. ; //菜单按钮事件,折线标注地图 
     164:  } 
     165:   
     166:  private void menuitem11_click(object sender, system.eventargs e) 
     167:  { 
     168:  axmap1.currenttool=mapxlib.toolconstants.misymboltool; //菜单按钮事件,创建工具,能在地图上添加符号,其实是对 mapx 的 annotations 操作 
     169:  } 
     170:   
     171:  private void menuitem12_click(object sender, system.eventargs e) 
     172:  { 
     173:  axmap1.currenttool=mapxlib.toolconstants.mitexttool; //菜单按钮事件,创建工具,能在地图上添加文本,其实是对 mapx 的 annotations 操作 
     174:  } 
     175:   
     176:  private void menuitem13_click(object sender, system.eventargs e) 
     177:  { 
     178:  axmap1.annotations.removeall(); // 把注释信息全部移除, 其实是对 mapx 的 annotations 操作 
     179:  } 
     180:   
     181:  private void menuitem14_click(object sender, system.eventargs e) 
     182:  { 
     183:  gistestbymyself.frmannotation frm=new frmannotation( axmap1.defaultstyle.clone() ); 
     184:  frm.owner=this; 
     185:  frm.showdialog(); // //未完成的,参见d:\program files\mapinfo\mapx 5.0\samples50\visualbasic\vb5sample 
     186:  } 
     187:   
     188:  private void menuitem16_click(object sender, system.eventargs e) //菜单按钮事件,显示属性窗口 
     189:  { 
     190:  axmap1.propertypage(); 
     191:  } 
     192:   
     193:  private void menuitem19_click(object sender, system.eventargs e) //显示mapx的关于对话框 
     194:  { 
     195:  axmap1.aboutbox(); 
     196:  } 
     197:   
     198:  private void menuitem29_click(object sender, system.eventargs e) //菜单按钮事件,调用窗口,对地图的坐标进行改动,或叫投影 
     199:  { 
     200:  axmap1.displaycoordsys.pickcoordsys(null,null); 
     201:  axmap1.numericcoordsys=axmap1.displaycoordsys; 
     202:  } 
     203:   
     204:  private void axmap1_mouseupevent(object sender, axmapxlib.cmapxevents_mouseupevent e) //鼠标事件,点击右键,弹出属性框 
     205:  { 
     206:  if(e.button==2) 
     207:  axmap1.propertypage(); 
     208:  } 
  • 相关阅读:
    1015: C语言程序设计教程(第三版)课后习题6.5
    1014 C语言程序设计教程(第三版)课后习题6.4
    1013: C语言程序设计教程(第三版)课后习题6.3
    1012: C语言程序设计教程(第三版)课后习题6.2
    1011 C语言程序设计教程(第三版)课后习题6.1
    链表结点的交换
    int、long、long long取值范围
    windows下XAMPP安装php_memcache扩展
    在VC6.0++ 下的调试
    ubuntu 安装tomcat
  • 原文地址:https://www.cnblogs.com/googlegis/p/2978850.html
Copyright © 2020-2023  润新知