接着第一篇文章,继续,这是在frmain.cs文件中除了第一篇文章里的代码外的第二部分:
//*******************************
#region 创建自定义工具,用来测量距离(可以折线)和测量面积
//****************************888
private void mapmain_polytoolused(object sender, axmapxlib.cmapxevents_polytoolusedevent e) //在创建好自己定义的工具后,会根据工具id来选择执行
{
if(e.toolnum == 10)//测量距离,这是自定义工具,测量多点的距离
{
mapxlib.points pts = (mapxlib.points)e.points;
mapxlib.point pt1,pt2;
double d=0.0;
//计算顺序两个点距离,累计得到总距离
for(int i=1;i<pts.count;i++)
{
pt1=pts._item(i);
pt2=pts._item(i+1);
d += axmap1.distance(pt1.x,pt1.y,pt2.x,pt2.y);
}
label1.text="距离:" + d.tostring();
}
else if(e.toolnum == 11) //面积,这是自定义工具,这里借用了某位网友的文章,谢谢
{
mapxlib.points pts = (mapxlib.points)e.points;
mapxlib.featurefactory dd = axmap1.featurefactory;
mapxlib.style style = axmap1.defaultstyle;
label1.text="面积:" + dd.createregion(pts,style).area.tostring();
}
}
#endregion
//*******************************
private void axmap1_mapviewchanged(object sender, system.eventargs e) //在地图大小改变时,显示出比例
{
label1.text=axmap1.zoom.tostring();
}
//*******************************
private void mutuceng_click(object sender, system.eventargs e) //菜单按钮事件,显示图层控制面板
{
axmap1.layers.layersdlg(null,null);
}
private void menuitem31_click(object sender, system.eventargs e) //菜单按钮事件,显示图层图层选择显示窗口
{
frmviewlyr frm=new frmviewlyr();
frm.owner=this;
frm.showdialog();
}
private void menuitem32_click(object sender, system.eventargs e) //菜单按钮事件,在新窗口中控制图层的显示比例等,
{
#region 新窗口中控制图层的显示比例,此处是省略代码
//***********此处省略,主要使用到的是 mapunit 和mapzoom *******************
//此处是伪代码,是mapx5.0的示例程序的vb代码,和上面的大同小异
//
// zoomtext.text = fmainform.map1.zoom
// set the unit combo box to the current unit
// take a short cut: units # 0 through 13 correspond to combo list number
// if fmainform.map1.mapunit < 14 then
// unitcombo.listindex = fmainform.map1.mapunit
// else
// select case fmainform.map1.mapunit
// case miunitlink
// unitcombo.listindex = 14
// case miunitchain
// unitcombo.listindex = 15
// case miunitrod
// unitcombo.listindex = 16
// end select
// end if
// save the current parameters so that the view can be
// restored if "cancel" is pressed
// oldzoom = fmainform.map1.zoom
// oldunit = fmainform.map1.mapunit
#endregion
}
//*******************************
private void axmap1_thememodifyrequested(object sender, axmapxlib.cmapxevents_thememodifyrequestedevent e)
{
//e.theme
}
private void axmap1_mousedownevent(object sender, axmapxlib.cmapxevents_mousedownevent e)
{
//e.button=
}
private void menuitem4_click(object sender, system.eventargs e) //菜单按钮事件,普通选择地图
{
axmap1.currenttool=mapxlib.toolconstants.miselecttool;
menuitem4.radiocheck=true;
}
private void menuitem5_click(object sender, system.eventargs e) //菜单按钮事件,长方形选择地图
{
axmap1.currenttool=mapxlib.toolconstants.mirectselecttool;
menuitem5.radiocheck=true;
}
private void menuitem6_click(object sender, system.eventargs e) //菜单按钮事件,圆形选择地图
{
axmap1.currenttool=mapxlib.toolconstants.miradiusselecttool;
menuitem6.radiocheck=true;
}
private void menuitem7_click(object sender, system.eventargs e)
{
axmap1.currenttool=mapxlib.toolconstants.mipolygonselecttool; //菜单按钮事件,多边形选择地图
menuitem7.radiocheck=true;
}
private void menuitem8_click(object sender, system.eventargs e)
{
axmap1.currenttool=mapxlib.toolconstants.milabeltool; //菜单按钮事件,直线标注地图
}
private void menuitem9_click(object sender, system.eventargs e)
{
//axmap1.currenttool=mapxlib.toolconstants. ; //菜单按钮事件,折线标注地图
}
private void menuitem11_click(object sender, system.eventargs e)
{
axmap1.currenttool=mapxlib.toolconstants.misymboltool; //菜单按钮事件,创建工具,可以在地图上添加符号,其实是对 mapx 的 annotations 操作
}
private void menuitem12_click(object sender, system.eventargs e)
{
axmap1.currenttool=mapxlib.toolconstants.mitexttool; //菜单按钮事件,创建工具,可以在地图上添加文本,其实是对 mapx 的 annotations 操作
}
private void menuitem13_click(object sender, system.eventargs e)
{
axmap1.annotations.removeall(); // 把注释信息全部移除, 其实是对 mapx 的 annotations 操作
}
private void menuitem14_click(object sender, system.eventargs e)
{
gistestbymyself.frmannotation frm=new frmannotation( axmap1.defaultstyle.clone() );
frm.owner=this;
frm.showdialog(); // //未完成的,参见d:\program files\mapinfo\mapx 5.0\samples50\visualbasic\vb5sample
}
private void menuitem16_click(object sender, system.eventargs e) //菜单按钮事件,显示属性窗口
{
axmap1.propertypage();
}
private void menuitem19_click(object sender, system.eventargs e) //显示mapx的关于对话框
{
axmap1.aboutbox();
}
private void menuitem29_click(object sender, system.eventargs e) //菜单按钮事件,调用窗口,对地图的坐标进行改变,或叫投影
{
axmap1.displaycoordsys.pickcoordsys(null,null);
axmap1.numericcoordsys=axmap1.displaycoordsys;
}
private void axmap1_mouseupevent(object sender, axmapxlib.cmapxevents_mouseupevent e) //鼠标事件,点击右键,弹出属性框
{
if(e.button==2)
axmap1.propertypage();
}
