【功能】:mapx之vc自定义测距工具(PolyToolUsed事件)
【环境】:VC6+mapx4.5+win2000
【原创】: www.51gis.com
//1.定义常量
#define MYTOOL_DISTANCE 100 //1~999
//2.创建工具
m_ctrlMap.CreateCustomTool(MYTOOL_DISTANCE,miToolTypePoly,miCrossCursor);
//3.响应事件
void CMapXSampleView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points,
BOOL bShift,BOOL bCtrl,BOOL FAR* EnableDefault)
{
//计算距离
if(Flags==miPolyToolInProgress) {//这句可有可无
if(ToolNum==MYTOOL_DISTANCE)
{
CMapXPoints pts;
long n;
long i;
try{
pts.AttachDispatch (Points, FALSE); // Get points Object
double dDistanceTot=0.0;
n=pts.GetCount ();
for (i=1; i<n;i++)
{
CMapXPoint pt1=pts.Item(i);
CMapXPoint pt2=pts.Item(i+1);
double d=m_ctrlMapX.Distance (pt1.GetX(),pt1.GetY(),pt2.GetX (),
pt2.GetY ());
dDistanceTot+=d;
}
CString str;
str.Format ("总距离为:%f",dDistanceTot);
//在状态栏输出距离
((CMainFrame*)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0,str);
}
catch (COleDispatchException *e){
e->ReportError ();
e->Delete ();
}
catch (COleException *e){
e->ReportError ();
e->Delete ();
}
}
}//if(Flags==miPolyToolInProgress)
}
//4.调用工具
void CMapXSampleView::OnMapToolDistancetool()
{
m_ctrlMapX.SetCurrentTool(MYTOOL_DISTANCE); //
}
==================MapX专家论坛(www.51gis.com)===================
本文地址:http://com.8s8s.com/it/it985.htm