VC++开发GIS系统(264)移动注释之类的设计及实现

本文介绍GIS系统中移动一个注释所对应类的设计及实现。功能演示如下:

移动注释类的定义

在_malaLabel.h中定义移动注释的类,代码如下:

/*
* 移动注释
*/
class malalabeldll  CmalaLabelsMove :public CmalaMouseAction
{
public:
  CmalaLabelsMove(CView* mView, malaScreen *pScreen, CString &fileFullPath);
  ~CmalaLabelsMove();
  void LButtonDown(UINT nFlags, malaPoint point);
  void LButtonUp(UINT nFlags, malaPoint point);
  void MouseMove(UINT nFlags, malaPoint point);
private:
  bool m_Selected;
  malaPoint m_Point;//选择的注释
  malaLabelPro m_LabelPro;//选择的注释的属性
  malaPointPro m_PointPro;//选择的点的属性
  CmalaLabelsSelect m_SelectPnt;

  CString mPath;//文件路径
  bool m_bDraw;
  malaPoint m_ptOrigin;//起点
  malaPoint m_perPoint;//临时点
  malaScreen *m_Screen;
};
  • @ mSelected 是否有注释被选中
  • @ m_Point 选中的注释
  • @ m_LabelPro 选中注释属性
  • @ m_LabelPro 绘制坐标点的属性
  • @ m_SelectPnt 选中的注释
  • @ mPath 注释文件路径
  • @ m_bDraw 记录是否按下鼠标左键(用于橡皮筋绘图)
  • @ m_ptOrigin 移动的起点
  • @ m_perPoint 临时的点
  • @ m_Screen 屏幕坐标

移动注释类实现

在_malaLabel.cpp中实现上述类的定义

/*
* 移动注释实现
*/
CmalaLabelsMove::CmalaLabelsMove(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
  mBaseView = mView;
  mPath = fileFullPath;
  m_Screen = pScreen;
  CmalaLabelsSelect obj(mView, pScreen, fileFullPath);
  m_SelectPnt = obj;
  m_Selected = FALSE;
  m_bDraw = FALSE;
}

CmalaLabelsMove::~CmalaLabelsMove()
{

}

void CmalaLabelsMove::LButtonDown(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.LButtonDown(nFlags, point);
  else
  {
    m_bDraw = TRUE;
    m_ptOrigin = point;
  }
}

void CmalaLabelsMove::LButtonUp(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.LButtonUp(nFlags, point);
  else
  {
    CLabelIO lio;
    lio.labelUpdate(point, m_LabelPro, mPath);
    mBaseView->Invalidate(TRUE);
    m_bDraw = FALSE;
    m_Selected = FALSE;
    m_SelectPnt.m_Selected = FALSE;

  }

  m_Selected = m_SelectPnt.m_Selected;
  if (m_Selected)
  {
    this->m_Point = m_SelectPnt.m_pnt;
    this->m_LabelPro = m_SelectPnt.mLablePro;
    m_perPoint = m_Point;
  }

}

void CmalaLabelsMove::MouseMove(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.MouseMove(nFlags, point);
  else if (m_bDraw)
  {
    malaCDC dc(mBaseView, *m_Screen);
    m_PointPro.pointColor = RGB(0, 255, 0);
    m_PointPro.pointRadio = 10;
    m_PointPro.pointStyle = 2;
    dc.pointDrawAutoX(m_perPoint, m_PointPro);
    m_perPoint.x = m_ptOrigin.x + point.x - m_ptOrigin.x;
    m_perPoint.y = m_ptOrigin.y + point.y - m_ptOrigin.y;
    dc.pointDrawAutoX(m_perPoint, m_PointPro);

  }
}

其中 labelUpdate 函数参考《VC++开发GIS系统(263)更新注释参数

详细代码可以参考:GitHub

VC++开发GIS系统(263)更新注释参数 VC++开发GIS系统(265)移动注释之菜单响应

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

发表评论