VC++开发GIS系统(111)放大地图之函数实现
发布时间: 2016-01-07
所属分类: VC++开发GIS系统
前文《VC++开发GIS系统(110)放大地图之简析橡皮筋绘图》已经介绍并解决放大地图的橡皮筋问题,剩下的就是实现地图放大的模块功能了。
LButtonDown函数
表示按下鼠标左键
void malaZoonIn::LButtonDown(UINT nFlags, malaPoint point)
{
m_bDraw = TRUE;
m_PtOrigin.x = m_perPoint.x = point.x;
m_PtOrigin.y = m_perPoint.y = point.y;
}
记录下最原始的点。
MouseMove函数
鼠标移动响应
void malaZoonIn::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.x = point.x;
m_perPoint.y = point.y;
}
}
这里用到了橡皮筋绘图的方法drawRectNULLFill,详细实现参考:VC++开发GIS系统(110)放大地图之简析橡皮筋绘图
LButtonUp函数
void malaZoonIn::LButtonUp(UINT nFlags, malaPoint point)
{
m_bDraw = FALSE;
//如果是点击放大
if ((m_PtOrigin.x == point.x) && (m_PtOrigin.y == point.y))
{
//中心点坐标
long xmid = m_Screen->wScreen / 2;
long ymid = m_Screen->hScreen / 2;
malaPoint tmpPoint;
ScreenToCoord(xmid, ymid, *m_Screen, &tmpPoint.x, &tmpPoint.y);
//先把图形移到中心
m_Screen->lbx = m_Screen->lbx + (point.x - tmpPoint.x);
m_Screen->lby = m_Screen->lby + (point.y - tmpPoint.y);
//再将图形放大
m_Screen->lbx = m_Screen->lbx + xmid * m_Screen->scale * 0.1;
m_Screen->lby = m_Screen->lby + ymid * m_Screen->scale * 0.1;
m_Screen->scale = m_Screen->scale*0.9;
}
else
{
//如果是拉框放大
double x1 = min(m_PtOrigin.x, point.x);
double y1 = min(m_PtOrigin.y, point.y);
double x2 = max(m_PtOrigin.x, point.x);
double y2 = max(m_PtOrigin.y, point.y);
m_Screen->lbx = x1;
m_Screen->lby = y1;
double blc1 = (x2 - x1) / (double)m_Screen->wScreen;
double blc2 = (y2 - y1) / (double)m_Screen->hScreen;
m_Screen->scale = (blc1 > blc2) ? blc1 : blc2;
}
mBaseView->Invalidate(TRUE);
}
详细代码可以参考:GitHub
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子