VC++开发GIS系统(239)删除区之类的设计及实现

本文为GIS中删除区的操作设计一个类,以实现删除区的相关功能,其演示如下:

GIS系统删除区类的定义

在_malaPolygon.h中定义删除区的类,代码如下:

/*
* 删除区
*/
class malapolygondll  CmalaPolysDelete :public CmalaMouseAction
{
public:
  CmalaPolysDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath);
  ~CmalaPolysDelete();
  void LButtonDown(UINT nFlags, malaPoint point);
  void LButtonUp(UINT nFlags, malaPoint point);
  void MouseMove(UINT nFlags, malaPoint point);
private:
  bool mSelected;
  vector<malaPoint> mSPoly;//选择的区
  malaPolyPro mSPolyPro;//选择的区的属性
  CmalaPolysSelect mSelectPoly;

  CString mPath;//文件路径
  malaScreen *mScreen;
};

类的实现

在_malaPolygon.cpp中实现GIS删除区的类,代码如下:

/*
* 删除区实现
*/
CmalaPolysDelete::CmalaPolysDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
  mBaseView = mView;
  mPath = fileFullPath;
  mScreen = pScreen;
  CmalaPolysSelect obj(mView, pScreen, fileFullPath);
  mSelectPoly = obj;
  mSelected = FALSE;
}

CmalaPolysDelete::~CmalaPolysDelete()
{
  if (mSPoly.size())
    mSPoly.clear();
}

void CmalaPolysDelete::LButtonDown(UINT nFlags, malaPoint point)
{
  if (!mSelected)
    mSelectPoly.LButtonDown(nFlags, point);
}

void CmalaPolysDelete::LButtonUp(UINT nFlags, malaPoint point)
{
  if (!mSelected)
    mSelectPoly.LButtonUp(nFlags, point);

  mSelected = mSelectPoly.m_Selected;

  if (mSelected)
  {
    this->mSPoly = mSelectPoly.mSPoly;
    this->mSPolyPro = mSelectPoly.mSPolyPro;

    if (MessageBox(mBaseView->m_hWnd, L"删除后将无法恢复,确定删除吗?", L"警告", MB_YESNO | MB_ICONQUESTION) == IDYES)
    {
      CPolyIO lio;
      lio.polyDelete(mSPolyPro.polyId, mPath);
      mBaseView->Invalidate(TRUE);
    }

    mSPoly.clear();
    mSelected = FALSE;
    mSelectPoly.m_Selected = FALSE;
  }

}

void CmalaPolysDelete::MouseMove(UINT nFlags, malaPoint point)
{
  if (!mSelected)
    mSelectPoly.MouseMove(nFlags, point);
}

主要思路是选中区,并调用删除函数 polyDelete (参考:VC++开发GIS系统(238)删除区之函数定义) 从区文件中移除。

详细代码可以参考:GitHub

国信司南(北京)地理信息技术有限公司招聘GIS研发工程师 VC++开发GIS系统(240)删除区之菜单响应

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

发表评论