|
在同一个View窗口下家两个CMapX控件,一个称为主图,一个称为鹰眼图。
CMapX m_ctrlMapX; ///主图
CMapX m_eagleMapX; ///鹰眼图
注意事项:在View里的OnCreate函数一定要想创建m_eagleMapX,这样才能看见鹰眼图。既如此:
m_eagleMapX.Create(NULL, WS_VISIBLE, CRect(0, 0, 120, 120), this, IDC_MAP_EAGLE);
m_eagleMapX.SetGeoSet(NULL);
m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0, 0, 100, 100), this, IDC_MAP);
m_ctrlMapX.SetGeoSet(NULL);
接下来,可以在主图里挑几层加到鹰眼图中(区域图层)
再在消息中映射几个消息:
ON_EVENT(CMTRSView, IDC_MAP_EAGLE, DISPID_MOUSEMOVE /* MouseMove */, onMouseMoveEagleMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CMTRSView, IDC_MAP_EAGLE, DISPID_MOUSEDOWN /* MouseDown */, onMouseDownEagleMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CMTRSView, IDC_MAP_EAGLE, DISPID_MOUSEUP /* MouseUp */, onMouseUpEagleMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
最后实现这几个函数:
void CMTRSView:nMouseUpEagleMap(short Button, short Shift, float X, float Y)
{
///用户单击导航图上某点的处理
if(strMouseState == "Begin")
{
double dblMapX1, dblMapY1;
///求出该点的地理坐标
m_eagleMapX.ConvertCoord(&X, &Y, &dblMapX1, &dblMapY1, miScreenToMap);
///设置主图的地理坐标
m_ctrlMapX.SetCenterX(dblMapX1);
m_ctrlMapX.SetCenterY(dblMapY1);
}
///用户在导航图上框出矩形区域时的处理
if(strMouseState == "Move")
{
Single sngXMax, sngXMin, sngYMax, sngYMin;
if(PreX < X)
{
sngXMax = X;
sngXMin = PreX;
}
else
{
sngXMax = PreX;
sngXMin = X;
}
if(PreX < Y)
{
sngYMax = Y;
sngYMin = PreY;
}
else
{
sngYMax = PreY;
sngYMin = Y;
}
double dblXMax, dblXMin, dblYMax, dblYMin;
m_eagleMapX.ConvertCoord(&sngXMin, &sngYMin, &dblXMin, &dblYMin, miScreenToMap);
m_eagleMapX.ConvertCoord(&sngXMax, &sngYMax, &dblXMax, &dblYMax, miScreenToMap);
CMapXRectangle rect;
rect.CreateDispatch(rect.GetClsid());
rect.Set(dblXMin, dblYMin, dblXMin, dblYMax);
m_ctrlMapX.SetBounds(rect.m_lpDispatch);
}
strMouseState = "Stop";
}
void CMTRSView::onMouseDownEagleMap(short Button, short Shift, float X, float Y)
{
CMapXFeatures ftrs = m_eagleMapX.GetLayers().Item("EagleLayer").AllFeatures();
for(int i = 1; i <= ftrs.GetCount(); i++)
{
m_eagleMapX.GetLayers().Item("EagleLayer").DeleteFeature(ftrs.Item(i));
}
if(Button == vbLeftButton)
{
strMouseState = "Begin";
PreX = X;
PreY = Y;
}
}
void CMTRSView::onMouseMoveEagleMap(short Button, short Shift, float X, float Y)
{
if(Button != vbLeftButton) return;
CMapXRectangle rctMap;
CMapXPoints pntsMap;
CMapXPoint pntMap1, pntMap2, pntMap3, pntMap4;
CMapXStyle styLine;
CMapXFeatures ftrs;
CMapXFeature ftr;
Single sngX, sngY;
///得到鼠标单击点的地理坐标
sngX = PreX;
sngY = PreY;
double dblMapX1, dblMapY1;
m_eagleMapX.ConvertCoord(&sngX, &sngY, &dblMapX1, &dblMapY1, miScreenToMap);
///得到鼠标当前点的地理坐标
double dblMapX2, dblMapY2;
m_eagleMapX.ConvertCoord(&X, &Y, &dblMapX2, &dblMapY2, miScreenToMap);
///设置矩形的四角
pntMap1.CreateDispatch(pntMap1.GetClsid());
pntMap2.CreateDispatch(pntMap2.GetClsid());
pntMap3.CreateDispatch(pntMap3.GetClsid());
pntMap4.CreateDispatch(pntMap4.GetClsid());
pntMap1.Set(dblMapX1, dblMapY2);
pntMap2.Set(dblMapX2, dblMapY2);
pntMap3.Set(dblMapX2, dblMapY1);
pntMap4.Set(dblMapX1, dblMapY1);
///将矩形的四角加入点集中
pntsMap.CreateDispatch(pntsMap.GetClsid());
pntsMap.Add(pntMap1);
pntsMap.Add(pntMap2);
pntsMap.Add(pntMap3);
pntsMap.Add(pntMap4);
pntsMap.Add(pntMap1);
styLine.SetLineColor(miColorBlack); ///定义样式的线条颜色
styLine.SetLineWidth(1); ///定义样式的线条宽度
styLine.SetLineStyle(3); ///虚线
///将导航图鹰眼层所有对象清空
ftrs = m_eagleMapX.GetLayers().Item("EagleLayer").AllFeatures();
for(int i = 1; i <= ftrs.GetCount(); i++)
{
m_eagleMapX.GetLayers().Item("EagleLayer").DeleteFeature(ftrs.Item(i));
}
///在导航图鹰眼层画虚线矩形框,框出用户预选择的范围
CMapXFeature ftrMap;
COleVariant pntsVt, styVt;
pntsVt.vt = VT_DISPATCH;
pntsVt.pdispVal = pntsMap.m_lpDispatch;
pntsVt.pdispVal->AddRef();
styVt.vt = VT_DISPATCH;
styLine.CreateDispatch(styLine.GetClsid());
styVt.pdispVal = styLine.m_lpDispatch;
styVt.pdispVal->AddRef();
ftrMap = m_eagleMapX.GetFeatureFactory().CreateLine(pntsVt, styVt);
m_eagleMapX.GetLayers().Item("EagleLayer").AddFeature(ftrMap);
///设置鼠标状态为"Move"
strMouseState = "Move";
}
还有,可以在OnSize里面设置一下鹰眼图的大小. |
|