麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

VC++开发GIS系统(260)选择注释之类的定义及实现

本文介绍GIS系统中如何选中一个区,并为此设计了一个类来完成相关操作。功能演示如下:

类的定义

在_malaLabel.h中定义下面的类

/*
* 选择注释
*/
class malalabeldll CmalaLabelsSelect :public CmalaMouseAction
{
public:
    CmalaLabelsSelect();
    CmalaLabelsSelect(CView* mView, malaScreen *pScreen, CString &fileFullPath);
    ~CmalaLabelsSelect();
    void LButtonDown(UINT nFlags, malaPoint point);
    void LButtonUp(UINT nFlags, malaPoint point);
    void MouseMove(UINT nFlags, malaPoint point);

public:
    malaRect m_rect;
    malaPoint m_ptOrigin;
    malaPoint m_perPoint;
    malaLabelPro mLablePro;//存放注释的属性
    static malaPoint m_pnt;//存放当前编辑的注释;
    static malaPointPro m_PntPro;//默认点属性
    static malaScreen *m_Screen;
    static CView* m_StaticView;

    CString mPath;//文件路径
    bool m_bDraw;
    bool m_Selected;
public:

    inline static void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
    {
        malaCDC dc(m_StaticView, *m_Screen);
        dc.pointDrawAutoX(m_pnt, m_PntPro);
    }
};

其中这里和文章《VC++开发GIS系统(127)选择点类的设计》《VC++开发GIS系统(128)选择点类的实现》实现的机理很相似,在这里就不做过多的介绍了,如有什么问题可以在本文留言。其中这里也用到了一个回调函数,可以参考:VC++开发GIS系统(125)选择点之CALLBACK回调函数

类的实现

在_malaLabel.cpp中实现上述代码,如下:

/*
* 选择注释实现
*/
malaPoint CmalaLabelsSelect::m_pnt;
malaPointPro CmalaLabelsSelect::m_PntPro;
CView* CmalaLabelsSelect::m_StaticView = NULL;
malaScreen* CmalaLabelsSelect::m_Screen = NULL;

CmalaLabelsSelect::CmalaLabelsSelect()
{

}

CmalaLabelsSelect::CmalaLabelsSelect(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
    mBaseView = mView;
    m_StaticView = mView;
    mPath = fileFullPath;

    m_bDraw = FALSE;
    m_Selected = FALSE;
    m_Screen = pScreen;
}

CmalaLabelsSelect::~CmalaLabelsSelect()
{

}

void CmalaLabelsSelect::LButtonDown(UINT nFlags, malaPoint point)
{
    m_bDraw = TRUE;
    m_ptOrigin = m_perPoint = point;
}

void CmalaLabelsSelect::LButtonUp(UINT nFlags, malaPoint point)
{
    m_bDraw = FALSE;
    malaCDC dc(mBaseView, *m_Screen);
    dc.drawRectNULLFill(m_ptOrigin, point);
    if (m_ptOrigin.x > point.x)
    {
        m_rect.xmax = m_ptOrigin.x;
        m_rect.xmin = point.x;
    }
    else
    {
        m_rect.xmin = m_ptOrigin.x;
        m_rect.xmax = point.x;
    }

    if (m_ptOrigin.y > point.y)
    {
        m_rect.ymax = m_ptOrigin.y;
        m_rect.ymin = point.y;
    }
    else
    {
        m_rect.ymin = m_ptOrigin.y;
        m_rect.ymax = point.y;
    }
    //先获取所有符合条件的点
    CLabelIO pio;
    vector<malaLabelFile>allLabels;
    pio.getAllLabel(*m_Screen, allLabels, mPath);
    //再查找是否被选中
    malaLogic tlog;
    for (size_t j = 0; j < allLabels.size(); j++)
    {
        if (tlog.isPntInRect(allLabels[j].mLabel, m_rect))
        {
            m_pnt = allLabels[j].mLabel;
            mLablePro = allLabels[j].mLabelPro;
            CPoint A, B;
            m_PntPro.pointColor = RGB(0, 255, 0);
            m_PntPro.pointRadio = 10;
            m_PntPro.pointStyle = 2;
            A.x = long(m_pnt.x - m_PntPro.pointRadio);
            A.y = long(m_pnt.y - m_PntPro.pointRadio);
            B.x = long(m_pnt.x + m_PntPro.pointRadio);
            B.y = long(m_pnt.y + m_PntPro.pointRadio);
            SetTimer(mBaseView->m_hWnd, 1, 500, TimerProc);
            if (MessageBox(mBaseView->m_hWnd, L"选择该注释吗?", L"提示", MB_YESNO | MB_ICONQUESTION) == IDYES)
            {
                KillTimer(mBaseView->m_hWnd, 1);
                mBaseView->InvalidateRect(CRect(A, B), TRUE);
                malaCDC dc(mBaseView, *m_Screen);
                dc.drawSelectCirclePoint(m_pnt, m_PntPro);
                dc.pointDrawAuto(m_pnt, m_PntPro);
                m_Selected = TRUE;
                break;
            }
            KillTimer(mBaseView->m_hWnd, 1);
            mBaseView->InvalidateRect(CRect(A, B), TRUE);
        }
    }
}

void CmalaLabelsSelect::MouseMove(UINT nFlags, malaPoint point)
{
    if (m_bDraw)
    {
        malaCDC dc(mBaseView, *m_Screen);
        dc.drawRectNULLFill(m_ptOrigin, m_perPoint);
        dc.drawRectNULLFill(m_ptOrigin, point);
        m_perPoint = point;
    }

}

这里主要实现的功能还是选中的注释闪烁,实现机理可以参考文章《VC++开发GIS系统(126)选择点之闪烁原理及实现

详细代码可以参考:GitHub

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)