VC++开发GIS系统(290)自定义线段量算类的设计及实现

本文创建一个类用于实现自定义线段量算工作。功能演示如下:

GIS系统自定义量算类的定义

在 _malaAnalysis.h 中定义GIS自定义量算的类,代码如下:

/*
* 自定义线段量算
*/
class malaanalysisdll CmalaLineMeasureCustom :public CmalaMouseAction
{
public:
  CmalaLineMeasureCustom(CView* ptView, malaScreen *Screen);
  ~CmalaLineMeasureCustom();
  void LButtonDown(UINT nFlags, malaPoint point);
  void MouseMove(UINT nFlags, malaPoint point);
  void RButtonDown(UINT nFlags, malaPoint point);
private:
  bool m_bDraw;
  malaPoint m_PtOrigin;
  malaPoint m_PerPoint;
  malaLinePro m_LinePro;
  vector<malaPoint>m_Line;
  
  malaScreen *m_Screen;
};
  • @ *m_Screen 屏幕坐标
  • @ m_PtOrigin 起点
  • @ m_PerPoint 临时的点
  • @ m_bDraw 标记是否按下左键
  • @ m_linepro 线的属性
  • @ m_line 组成折线的每一个点

类的实现

在 _malaAnalysis.cpp 中实现上述类的定义,代码如下:

//自定义量算
CmalaLineMeasureCustom::CmalaLineMeasureCustom(CView* ptView, malaScreen *Screen)
{
  mBaseView = ptView;
  m_LinePro.lineColor = RGB(0, 0, 0);
  m_LinePro.lineStyle = 0;
  m_LinePro.lineWidth = 1;
  m_bDraw = FALSE;
  m_Screen = Screen;
}

CmalaLineMeasureCustom::~CmalaLineMeasureCustom()
{

}

void CmalaLineMeasureCustom::LButtonDown(UINT nFlags, malaPoint point)
{
  m_bDraw = TRUE;
  m_PerPoint = m_PtOrigin = point;
  m_Line.push_back(point);
}


void CmalaLineMeasureCustom::MouseMove(UINT nFlags, malaPoint point)
{
  //橡皮线
  malaCDC dc(mBaseView, *m_Screen);
  if (m_bDraw)
  {
    dc.lineDrawX(m_PtOrigin, m_PerPoint, m_LinePro);
    dc.lineDrawX(m_PtOrigin, point, m_LinePro);
    m_PerPoint = point;
  }

}
void CmalaLineMeasureCustom::RButtonDown(UINT nFlags, malaPoint point)
{
  m_bDraw = FALSE;
  malaLogic tMath;
  double dis = tMath.distanceLine(m_Line);
  CString str;
  str.Format(L"%f ", dis);
  MessageBox(mBaseView->m_hWnd, str, L"坐标长度", MB_OK);
  mBaseView->Invalidate(TRUE);
  m_Line.clear();
}

其中 distanceLine 的实现参考文章《VC++开发GIS系统(287)计算一条折线的长度

详细代码可以参考:GitHub

VC++开发GIS系统(289)已知线段量算之菜单响应 VC++开发GIS系统(291)自定义线段量算之菜单响应

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论