www.pudn.com > Geotest.rar > EagleDlg.cpp
// EagleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "geotest.h"
#include "EagleDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEagleDlg dialog
CEagleDlg::CEagleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEagleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEagleDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CEagleDlg::CEagleDlg(CMapX* pMapX,CWnd* pParent /*=NULL*/)
: CDialog(CEagleDlg::IDD, pParent)
{
m_pMapX=pMapX;
}
void CEagleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEagleDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
void CEagleDlg::ViewChanged()
{
m_pMapX->GetLayers().CreateLayer("RectLayer");
try {
double X1,Y1,X2,Y2; //声明坐标变量
double x2,y2,x4,y4; //声明坐标变量
VARIANT scx, scy, scx1, scy1; //声明屏幕坐标变量
VARIANT mapx1,mapy1,mapx2,mapy2; //声明地图坐标变量
//声明FeatureFactory变量并获取缺省值
CMapXFeatureFactory cFactory=m_pMapX->GetFeatureFactory();
CMapXLayer layer; //声明图层变量
CMapXFeature feature,m_eaglefeature; //声明Feature变量
CMapXFeatures features; //声明Features变量
CMapXPoints points; //声明Points变量
points.CreateDispatch(points.GetClsid());
CMapXRectangle rect; //声明矩形变量
rect.CreateDispatch(rect.GetClsid());
//获取主图的边界,根据这个边界值,在鹰眼图上添加一个矩形Feature
rect = m_pMapX->GetBounds();
X1 = rect.GetXMin(); //获得矩形左上顶点x坐标
Y1 = rect.GetYMin(); //获得矩形左上顶点y坐标
X2 = rect.GetXMax(); //获得矩形右下顶点x坐标
Y2 = rect.GetYMax(); //获得矩形右下顶点y坐标
//进行坐标变换
m_pMapX->ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
m_pMapX->ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
m_pMapX->ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
m_pMapX->ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
//获得矩形框顶点坐标
x2= mapx1.dblVal;
y2= mapy1.dblVal;
x4= mapx2.dblVal;
y4= mapy2.dblVal;
//得到添加矩形Feature的图层
layer=m_pMapX->GetLayers().Item("RectLayer");
features=layer.AllFeatures();
//没有添加矩形Feature的图层,则新建
if(features.GetCount()==0)
{
//添加四个顶点构成一个矩形框
points.AddXY(X1,Y1); //添加顶点1
points.AddXY(x2,y2); //添加顶点2
points.AddXY(X2,Y2); //添加顶点3
points.AddXY(x4,y4); //添加顶点4
//创建矩形Feature
COleVariant vtPoints;
vtPoints.vt = VT_DISPATCH;
vtPoints.pdispVal = points.m_lpDispatch;
vtPoints.pdispVal->AddRef();
feature=cFactory.CreateRegion(vtPoints);
//设置矩形Feature的属性
CMapXStyle style=feature.GetStyle();
style.SetRegionPattern(miPatternNoFill); //设置矩形的填充方式
style.SetRegionBorderColor(miColorRed); //设置矩形边框颜色
style.SetRegionBorderWidth(3); //设置矩形边框宽度
feature.SetStyle(style.m_lpDispatch);
//添加已经创建的矩形Feature
m_eaglefeature = layer.AddFeature(feature);
}
else //否则更新Feature的矩形大小与位置
{
m_eaglefeature.GetParts().Item(1).RemoveAll(); //除去已有的顶点
m_eaglefeature.GetParts().Item(1).AddXY(X1,Y1); //添加顶点1
m_eaglefeature.GetParts().Item(1).AddXY(x2,y2); //添加顶点2
m_eaglefeature.GetParts().Item(1).AddXY(X2,Y2); //添加顶点3
m_eaglefeature.GetParts().Item(1).AddXY(x4,y4); //添加顶点4
m_eaglefeature.Update(); //更新Feature属性
}
//更新显示图层
layer.Refresh();
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
}
BEGIN_MESSAGE_MAP(CEagleDlg, CDialog)
//{{AFX_MSG_MAP(CEagleDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEagleDlg message handlers