// MyMapView.cpp : implementation of the CMyMapView class
//
#include "stdafx.h"
#include "MyMap.h"
#include "MainFrm.h"
#include "MyMapDoc.h"
#include "MyMapView.h"
#include "HawkView.h"
#include "MapControlView1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define Arrow 1000
#define Pan 1001
#define Center 1002
#define ZoomIn 1003
#define ZoomOut 1004
#define Symbol 1005
#define Text 1006
#define Select 1007
#define RadiusSelect 1008
#define RectSelect 1009
#define PolygonSelect 1010
#define Label 1011
#define AddLine 1012
#define AddPolyLine 1013
#define AddRegion 1014
#define AddPoint 1015
#define Ruler 100
#define POLY_RULER 101
#define TOOL_INFO 102
/////////////////////////////////////////////////////////////////////////////
// CMyMapView
IMPLEMENT_DYNCREATE(CMyMapView, CFormView)
BEGIN_MESSAGE_MAP(CMyMapView, CFormView)
//{{AFX_MSG_MAP(CMyMapView)
ON_WM_SIZE()
ON_COMMAND(ID_ADDLAYERS, OnAddlayers)
ON_COMMAND(IDD_REMOVE, OnRemove)
ON_COMMAND(ID_ZOOMIN, OnZoomin)
ON_UPDATE_COMMAND_UI(ID_ZOOMIN, OnUpdateZoomin)
ON_COMMAND(ID_ZOOMOUT, OnZoomout)
ON_UPDATE_COMMAND_UI(ID_ZOOMOUT, OnUpdateZoomout)
ON_COMMAND(ID_FULLSCREEN, OnFullscreen)
ON_UPDATE_COMMAND_UI(ID_FULLSCREEN, OnUpdateFullscreen)
ON_COMMAND(ID_PAN, OnPan)
ON_UPDATE_COMMAND_UI(ID_PAN, OnUpdatePan)
ON_COMMAND(ID_ARROW, OnArrow)
ON_UPDATE_COMMAND_UI(ID_ARROW, OnUpdateArrow)
ON_COMMAND(ID_OPEN_GST, OnOpenGst)
ON_COMMAND(ID_RULER, OnRuler)
ON_COMMAND(ID_GST_MANAGER, OnGstManager)
ON_COMMAND(ID_ADD_LABEL, OnAddLabel)
ON_COMMAND(ID_AUTO_LABEL, OnAutoLabel)
ON_COMMAND(ID_REFRESH, OnRefresh)
ON_COMMAND(ID_CLEAR_LABELS, OnClearLabels)
ON_COMMAND(ID_EXPORT_MAP, OnExportMap)
ON_COMMAND(ID_THEME_MAP, OnThemeMap)
ON_COMMAND(ID_POINT_FIND, OnPointFind)
ON_COMMAND(ID_POLYGON_FIND, OnPolygonFind)
ON_COMMAND(ID_RECT_FIND, OnRectFind)
ON_COMMAND(ID_CIRCLE_FIND, OnCircleFind)
ON_UPDATE_COMMAND_UI(ID_POINT_FIND, OnUpdatePointFind)
ON_UPDATE_COMMAND_UI(ID_POLYGON_FIND, OnUpdatePolygonFind)
ON_UPDATE_COMMAND_UI(ID_RECT_FIND, OnUpdateRectFind)
ON_UPDATE_COMMAND_UI(ID_CIRCLE_FIND, OnUpdateCircleFind)
ON_COMMAND(ID_MOVE_DOWN, OnMoveDown)
ON_UPDATE_COMMAND_UI(ID_MOVE_DOWN, OnUpdateMoveDown)
ON_COMMAND(ID_MOVE_LEFT, OnMoveLeft)
ON_UPDATE_COMMAND_UI(ID_MOVE_LEFT, OnUpdateMoveLeft)
ON_COMMAND(ID_MOVE_RIGHT, OnMoveRight)
ON_UPDATE_COMMAND_UI(ID_MOVE_RIGHT, OnUpdateMoveRight)
ON_COMMAND(ID_MOVE_UP, OnMoveUp)
ON_UPDATE_COMMAND_UI(ID_MOVE_UP, OnUpdateMoveUp)
ON_WM_CHAR()
ON_COMMAND(ID_PRE_VIEW, OnPreView)
ON_COMMAND(ID_POLY_DISTANCE_RULER, OnPolyDistanceRuler)
ON_UPDATE_COMMAND_UI(ID_POLY_DISTANCE_RULER, OnUpdatePolyDistanceRuler)
ON_UPDATE_COMMAND_UI(ID_RULER, OnUpdateRuler)
ON_COMMAND(ID_GET_INFO, OnGetInfo)
ON_UPDATE_COMMAND_UI(ID_GET_INFO, OnUpdateGetInfo)
ON_COMMAND(ID_AREA, OnArea)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyMapView construction/destruction
CMyMapView::CMyMapView()
: CFormView(CMyMapView::IDD)
{
// CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
//m_pHawkView = (CHawkView*) (pMainWnd->m_wndSplitter2.GetPane(1,0));
//m_phawkmap = &m_pHawkView->m_maphawk;
m_bIsOK = 0;
m_curtool = Arrow;
m_dPrevZoom = 0;
m_dCurZoom = 0;
//m_phawkmap->PropertyPage();
//{{AFX_DATA_INIT(CMyMapView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CMyMapView::~CMyMapView()
{
}
void CMyMapView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyMapView)
DDX_Control(pDX, IDC_MAP1, m_map);
//}}AFX_DATA_MAP
}
BOOL CMyMapView::PreCreateWindow(CREATESTRUCT& cs)
{
/* CRect rc;
AfxGetApp()->m_pMainWnd->GetWindowRect(&rc);
// CString str;
//str.Format("cx = %d , cy = %d ",rc.Width(),rc.Height());
// MessageBox(str);
//cs.cx = rc.Width;
int cx,cy;
cx = 750 / 1002 * rc.Width();
cy = 460 / 776 *rc.Height();
// cs.cx = rc.Width();
// cs.cy = rc.Height();
*/
/* CMainFrame *pMainFrm;
pMainFrm= (CMainFrame *)AfxGetApp()->m_pMainWnd;
pMainFrm->m_width = rc.Width();*
pMainFrm->m_height = rc.Height();*/
return CFormView::PreCreateWindow(cs);
}
void CMyMapView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CMyMapView printing
BOOL CMyMapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyMapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyMapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CMyMapView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CMyMapView diagnostics
#ifdef _DEBUG
void CMyMapView::AssertValid() const
{
CFormView::AssertValid();
}
void CMyMapView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CMyMapDoc* CMyMapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyMapDoc)));
return (CMyMapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyMapView message handlers
void CMyMapView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if(m_map.m_hWnd )
{
//CMapX m_map;
//m_map.MoveWindow(0,0,cx,cy,TRUE);
m_map.SetWindowPos(0,0,0,cx,cy,SWP_NOZORDER);
m_pHawkView =(CHawkView*)this->GetView(RUNTIME_CLASS(CHawkView));
CMapXLayers layers;
layers = m_map.GetLayers();
m_map.SetBounds(layers.GetBounds());
m_map.SetCurrentTool(Arrow);
// m_bIsOK = 1;
}
}
void CMyMapView::OnAddlayers()
{
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CHawkView *pHawkView = (CHawkView*) (pMainWnd->m_wndSplitter2.GetPane(1,0));
m_phawkmap = &pHawkView->m_maphawk;
CMapXLayers layers;
layers = m_map.GetLayers();
//layers.LayersDlg();
//CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CMapControlView *pCV = (CMapControlView*) (pMainWnd->m_wndSplitter2.GetPane(0,0));
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrTitle = "Select Layers to Add";
dlg.m_ofn.lpstrFilter = "TAB files(*.TAB)/0*TAB/0All files(*.*)/0*.*/0/0";
if(dlg.DoModal() == IDOK)
{
CString str;
str = dlg.GetPathName();
layers.Add(str);
CMapXLayers layers1;
layers1 = m_phawkmap->GetLayers(); //同时改变鹰眼视图中的数据
layers1.Add(str);
/*CMapXLayer layer;
layer = layers.Item(str);
layer.Refresh();*/
pCV->PostMessage(WM_REFRESH_MESSAGE,0,0); //向控制视图发送自定义消
pCV->PostMessage(WM_REFRESH_TREE,0,0);
}
}
void CMyMapView::OnRemove()
{
/* CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CHawkView *pHawkView = (CHawkView*) (pMainWnd->m_wndSplitter2.GetPane(1,0));
m_phawkmap = &pHawkView->m_maphawk;
*/
CMapXLayers layers;
layers = m_map.GetLayers();
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CMapControlView *pCV = (CMapControlView*) (pMainWnd->m_wndSplitter2.GetPane(0,0));
layers.LayersDlg();
pCV->PostMessage(WM_REFRESH_MESSAGE,0,0); //向控制视图发送自定义消
pCV->PostMessage(WM_REFRESH_TREE,0,0);
m_bIsOK = 1;
}
BEGIN_EVENTSINK_MAP(CMyMapView, CFormView)
//{{AFX_EVENTSINK_MAP(CMyMapView)
ON_EVENT(CMyMapView, IDC_MAP1, 6 /* MapViewChanged */, OnMapViewChanged, VTS_NONE)
ON_EVENT(CMyMapView, IDC_MAP1, 3 /* ToolUsed */, OnToolUsedMap1, VTS_I2 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_BOOL VTS_BOOL VTS_PBOOL)
ON_EVENT(CMyMapView, IDC_MAP1, -606 /* MouseMove */, OnMouseMoveMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CMyMapView, IDC_MAP1, -605 /* MouseDown */, OnMouseDownMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CMyMapView, IDC_MAP1, 1 /* SelectionChanged */, OnSelectionChangedMap1, VTS_NONE)
ON_EVENT(CMyMapView, IDC_MAP1, 9 /* ThemeModifyRequested */, OnThemeModifyRequestedMap1, VTS_DISPATCH)
ON_EVENT(CMyMapView, IDC_MAP1, 11 /* PolyToolUsed */, OnPolyToolUsedMap1, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
CView *CMyMapView::GetView(CRuntimeClass *pClass)
{
CMyMapDoc* pDoc=(CMyMapDoc*)GetDocument();
CView* pView;
POSITION pos=pDoc->GetFirstViewPosition();
while(pos!=NULL){
pView=pDoc->GetNextView(pos);
if(pView->IsKindOf(pClass))
break;
}
if(!pView->IsKindOf(pClass)){
AfxMessageBox("Connt Locate the View.");
return NULL;
}
return pView;
}
////////////////////////
void CMyMapView::OnArea()
{
}
/////////////鹰眼的实现
void CMyMapView::OnMapViewChanged()
{
if(m_bIsOK && m_map.m_hWnd)
{
m_dPrevZoom = m_dCurZoom;
m_dPrevX = m_dCurX;
m_dPrevY = m_dCurY;
m_dCurZoom = m_map.GetZoom();
m_dCurX = m_map.GetCenterX();
m_dCurY = m_map.GetCenterY();
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CHawkView *pHawkView = (CHawkView*) (pMainWnd->m_wndSplitter2.GetPane(1,0));
CMapX *phawkmap ;
phawkmap = &pHawkView->m_maphawk;
double X1,Y1,X2,Y2; //声明坐标变量
double x2,y2,x4,y4; //声明坐标变量
VARIANT scx, scy, scx1, scy1; //声明屏幕坐标变量
VARIANT mapx1,mapy1,mapx2,mapy2; //声明地图坐标变量
//声明FeatureFactory变量并获取缺省值
CMapXFeatureFactory cFactory=phawkmap->GetFeatureFactory();
CMapXLayer layer; //声明图层变量
CMapXFeature feature; //声明Feature变量
CMapXFeatures features; //声明Features变量
CMapXPoints points; //声明Points变量
points.CreateDispatch(points.GetClsid());
CMapXRectangle rect; //声明矩形变量
rect.CreateDispatch(rect.GetClsid());
//获取主图的边界,根据这个边界值,在鹰眼图上添加一个矩形Feature
rect = m_map.GetBounds();
X1 = rect.GetXMin(); //获得矩形左上顶点x坐标
Y1 = rect.GetYMin(); //获得矩形左上顶点y坐标
X2 = rect.GetXMax(); //获得矩形右下顶点x坐标
Y2 = rect.GetYMax(); //获得矩形右下顶点y坐标
//进行坐标变换
phawkmap->ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
phawkmap->ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
phawkmap->ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
phawkmap->ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
//获得矩形框顶点坐标
x2= mapx1.dblVal;
y2=mapy1.dblVal;
x4=mapx2.dblVal;
y4=mapy2.dblVal;
//得到添加矩形Feature的图层
layer=phawkmap->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(2); //设置矩形边框宽度
feature.SetStyle(style.m_lpDispatch);
//添加已经创建的矩形Feature
pHawkView->m_eaglefeature = layer.AddFeature(feature);
}
else //否则更新Feature的矩形大小与位置
{
pHawkView->m_eaglefeature.GetParts().Item(1).RemoveAll(); //除去已有的顶点
pHawkView->m_eaglefeature.GetParts().Item(1).AddXY(X1,Y1); //添加顶点1
pHawkView->m_eaglefeature.GetParts().Item(1).AddXY(x2,y2); //添加顶点2
pHawkView->m_eaglefeature.GetParts().Item(1).AddXY(X2,Y2); //添加顶点3
pHawkView->m_eaglefeature.GetParts().Item(1).AddXY(x4,y4); //添加顶点4
pHawkView->m_eaglefeature.Update(); //更新Feature属性
}
//更新显示图层
layer.Refresh();
}
}
void CMyMapView::OnZoomin()
{
m_curtool = ZoomIn;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdateZoomin(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == ZoomIn);
}
void CMyMapView::OnZoomout()
{
m_curtool = ZoomOut;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdateZoomout(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == ZoomOut);
}
void CMyMapView::OnFullscreen()
{
m_map.SetBounds(m_map.GetLayers().GetBounds());
}
void CMyMapView::OnUpdateFullscreen(CCmdUI* pCmdUI)
{
}
void CMyMapView::OnPan()
{
m_curtool = Pan;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdatePan(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == Pan);
}
void CMyMapView::OnArrow()
{
m_curtool = Arrow;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdateArrow(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == Arrow);
}
void CMyMapView::OnOpenGst()
{
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CHawkView *pHawkView = (CHawkView*) (pMainWnd->m_wndSplitter2.GetPane(1,0));
m_phawkmap = &pHawkView->m_maphawk;
//CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CMapControlView *pCV = (CMapControlView*) (pMainWnd->m_wndSplitter2.GetPane(0,0));
CWnd* pFrame = AfxGetMainWnd();
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrTitle = "Select .gst Files to Open";
dlg.m_ofn.lpstrFilter = "gst files(*.gst)/0*gst/0All files(*.*)/0*.*/0/0";
if(dlg.DoModal() == IDOK)
{
BeginWaitCursor();
//////////////进度条
/* for (int pct=10; pct<=100; pct+=10)
{
//Sleep(150);
if (pFrame)
pFrame->SendMessage(MYWM_PROGRESS, pct);
}
if (pFrame)
pFrame->SendMessage(MYWM_PROGRESS, 0);*/
CString str;
str = dlg.GetPathName();
m_map.SetGeoSet(str);
//m_map.SetTitleText("");
pCV->PostMessage(WM_REFRESH_MESSAGE,0,0); //向控制视图发送自定义消
pCV->PostMessage(WM_REFRESH_TREE,0,0);
CMapXLayers layers;
m_phawkmap->SetGeoSet(str);
layers = m_phawkmap->GetLayers();
m_phawkmap->SetBounds(layers.GetBounds());
//不加下面一句,重新打开GST时在鹰眼视图中看不到红框
m_phawkmap->GetLayers().CreateLayer("RectLayer");
//在鹰眼视图中不显示地图标题
m_phawkmap->SetTitleText("");
m_map.SetBounds(m_map.GetLayers().GetBounds());
EndWaitCursor();
}
//m_bIsOK = TRUE;
}
void CMyMapView::OnRuler()
{
m_map.CreateCustomTool(Ruler,miToolTypeLine,miCrossCursor);
m_curtool = Ruler;
m_map.SetCurrentTool(Ruler);
}
void CMyMapView::OnUpdateRuler(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == Ruler);
}
void CMyMapView::OnGstManager()
{
CWnd hwnd;
ShellExecute(hwnd,NULL,"GeosetManager50",NULL,NULL,SW_SHOWNORMAL);
}
void CMyMapView::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)
{
if(ToolNum == Ruler)
{
CString str;
str.Format("你所目前所量测得总距离为: %.4f 千米",Distance);
((CMainFrame *)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0,str);
}
if(ToolNum == TOOL_INFO)
{
try
{
if(m_map.GetDatasets().GetCount() ==0)
{
MessageBox("该信息工具要求必须有一个Dataset加入地图");
return ;
}
CMapXPoint pt;
CMapXFeatures fs;
CMapXFeature f;
CMapXDataset ds;
pt.CreateDispatch(pt.GetClsid());
pt.Set(X1,Y1);
fs = m_map.GetLayers().Item(1).SearchAtPoint(pt);
if(fs.GetCount() != 1)
{
return;
}
f = fs.Item(1);
ds = m_map.GetDatasets().Item(1);
}
catch(COleException * e)
{
e->ReportError();
e->Delete();
}
}
}
void CMyMapView::OnAddLabel()
{
m_map.SetCurrentTool(miLabelTool);
}
void CMyMapView::OnMouseMoveMap1(short Button, short Shift, float X, float Y)
{
double mapx,mapy;
CString str;
CMainFrame *pFrame1 = (CMainFrame *)AfxGetApp()->m_pMainWnd;
CStatusBar *pStatus1 = &pFrame1->m_wndStatusBar;
m_map.ConvertCoord(&X,&Y,&mapx,&mapy,miScreenToMap);
CString str1,str2;
if(mapx >= 0 )
str1 = "东经:";
else
str1 = "西经:";
if(mapy >= 0 )
str2 = "北纬:";
else
str2 = "南纬:";
str.Format(" %s %f %s %f", str1,mapx,str2,mapy);
pStatus1->SetPaneStyle(1,SBPS_NORMAL);
pStatus1->SetPaneText(1,str);
double dzoom;
dzoom = m_map.GetZoom();
str.Format("比例尺: %.0f",dzoom);
pStatus1->SetPaneStyle(2,SBPS_NORMAL);
pStatus1->SetPaneText(2,str);
/*
//状态栏中显示信息
BYTE *pImage;
int nByteWidth = pDib->m_dwSizeImage / sizey;
CString str1,str2,str3;
CMainFrame *pFrame1 = (CMainFrame *)AfxGetApp()->m_pMainWnd;
CStatusBar *pStatus1 = &pFrame1->m_wndStatusBar;
BOOL m_bDis = pFrame1->m_bDisplayxy;
BOOL m_bDisp = pFrame1->m_bDisplayrgb;
pStatus1->SetPaneStyle(1,SBPS_NORMAL);
str3.Format("当前图象的显示比例: %.0f",m_fScale * 100);
pStatus1->SetPaneText(1,str3 + "%");
if(!m_bDis)
pStatus1->SetPaneStyle(3,SBPS_DISABLED);
else
pStatus1->SetPaneStyle(3,SBPS_NORMAL);
if(!m_bDisp)
pStatus1->SetPaneStyle(2,SBPS_DISABLED);
else
pStatus1->SetPaneStyle(2,SBPS_NORMAL);
//若状态蓝指针不为空
if(pStatus1)
{
str2.Format("坐标信息: X=%d,Y=%d",point.x,point.y);
pStatus1->SetPaneText(3,str2);
//若光标不在图象范围内
if(point.x >sizex || point.y > sizey)
{
str1 = "光标在图像范围之外!";
pStatus1 ->SetPaneText(2,str1);
}
//光标在图象范围内
else
{
SetCursor(LoadCursor(NULL,IDC_CROSS));
//若是单色图象
if(pDoc->m_pDibInit->m_lpBMIH->biBitCount == 8)
{
RGBQUAD CurRGB;
CurRGB = pDib->GetPixel(point.x,point.y);
//在信息面板中显示信息代码(三原色分量)
m_pDlgInfor->m_nR =CurRGB.rgbRed;
m_pDlgInfor->m_nG = CurRGB.rgbGreen;
m_pDlgInfor->m_nB = CurRGB.rgbBlue;
if(m_pDlgInfor->IsOpen())
m_pDlgInfor->SendMessage(WM_INITDIALOG);
//在状态栏中显示信息
str1.Format("象素信息: R=%d,G=%d,B=%d",CurRGB.rgbRed,CurRGB.rgbGreen,CurRGB.rgbBlue);
pStatus1->SetPaneText(2,str1);
}
//若是彩色图象
else
{
pImage = (BYTE *) pDib->m_lpImage + nByteWidth * point.y + point.x * 3 ;
int r = *(pImage + 2);
int g = *(pImage + 1);
int b = *(pImage + 0);
//在信息面板中显示信息代码(三原色分量)
m_pDlgInfor->m_nR =r;
m_pDlgInfor->m_nG = g;
m_pDlgInfor->m_nB = b;
if(m_pDlgInfor->IsOpen())
m_pDlgInfor->SendMessage(WM_INITDIALOG);
//在状态栏中显示信息
str1.Format("象素信息: R=%d,G=%d,B=%d",r,g,b);
pStatus1->SetPaneText(2,str1);
}
*/
}
void CMyMapView::OnRefresh()
{
m_map.Refresh();
}
void CMyMapView::OnAutoLabel()
{
CMapXLayers layers;
layers = m_map.GetLayers();
int count;
count = layers.GetCount();
for(int i = 0;i< count;i++)
layers.Item(i+1).SetAutoLabel(1);
}
void CMyMapView::OnClearLabels()
{
CMapXLayers layers;
layers = m_map.GetLayers();
int count;
count = layers.GetCount();
for(int i = 0;i< count;i++)
{
layers.Item(i+1).SetAutoLabel(0);
layers.Item(i+1).ClearCustomLabels();
}
}
void CMyMapView::OnExportMap()
{
//CMapX m_map;
CFileDialog dlg(FALSE);
dlg.m_ofn.lpstrTitle = "保存地图文件";
//dlg.m_ofn.lpstrFilter = "gst files(*.gst)/0*gst/0All files(*.*)/0*.*/0/0";
if(dlg.DoModal() == IDOK)
{
CString str;
str = dlg.GetPathName();
m_map.SetExportSelection(1);
m_map.ExportMap(str,miFormatBMP);
}
}
//miThemeRanged 0 范围专题地图
//miThemeBarChart 1 饼图
// miThemePieChart 2 直方图
// miThemeGradSymbol 3 等级符号专题
//miThemeDotDensity 4 点密度专题
//miThemeIndividualValue 5 独立值专题地图
//miThemeAuto 6 自动设置
void CMyMapView::OnThemeMap()
{
CMapXLayers layers;
layers = m_map.GetLayers();
CMapXDatasets Datasets = m_map.GetDatasets();
COleVariant rsVariant;
rsVariant.vt = VT_DISPATCH;
rsVariant.pdispVal = layers.Item("WORLD");
//数据绑定, 将要制作专题图的图层加入Datasets对象中
Datasets.Add (miDataSetLayer,rsVariant);//将WORLD图层绑定数据
CMapXDataset Dataset = Datasets.Item(1);
CMapXThemes Themes = Dataset.GetThemes();
if(Themes.GetCount()!=0)
Themes.RemoveAll();
Themes.Add(miThemePieChart,3,"MyDot");
CMapXTheme Theme = Themes.Item("MyDot");
Theme.ThemeDlg();
}
void CMyMapView::OnPointFind()
{
m_curtool = miSelectTool;
m_map.SetCurrentTool(m_curtool);
//CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
// CMapControlView *pCV = (CMapControlView*) (pMainWnd->m_wndSplitter2.GetPane(0,0));
}
void CMyMapView::OnPolygonFind()
{
m_curtool = miPolygonSelectTool;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnRectFind()
{
m_curtool = miRectSelectTool;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnCircleFind()
{
m_curtool = miRadiusSelectTool;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdatePointFind(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == miSelectTool);
}
void CMyMapView::OnUpdatePolygonFind(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == miPolygonSelectTool);
}
void CMyMapView::OnUpdateRectFind(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == miRectSelectTool);
}
void CMyMapView::OnUpdateCircleFind(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == miRadiusSelectTool);
}
void CMyMapView::OnMouseDownMap1(short Button, short Shift, float X, float Y)
{
m_bIsOK = 1;
}
//////////////////////////////////////////
void CMyMapView::OnSelectionChangedMap1()
{
BeginWaitCursor();
//CMapX m_map;
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
CMapControlView *pCV = (CMapControlView*) (pMainWnd->m_wndSplitter2.GetPane(0,0));
pCV->m_OperaTab.SetCurFocus(2);
// pCV->m_ResultListBox.ShowWindow(SW_HIDE);
pCV->m_ResultListBox.DeleteAllItems(); //清除上次选择的纪录
CMapXLayers layers;
CMapXLayer layer;
CMapXFeatures fs;
CMapXFeature f;
CMapXSelection sel;
layers = m_map.GetLayers();
CWnd* pFrame = AfxGetMainWnd();
int layercount;
layercount = layers.GetCount();
for(int i = 0 ;i < layercount ;i ++)
{
sel = layers.Item(i + 1).GetSelection(); //得到的是CMapXSelection 对象
if(sel.GetCount() > 0)
{
for(int j = 0 ; j < sel.GetCount() ;j ++)
{
//进度条
if (pFrame)
pFrame->SendMessage(MYWM_PROGRESS, j/2 );
if (pFrame)
pFrame->SendMessage(MYWM_PROGRESS, 0);
f = sel.Item( j + 1 ); //得到的是CMapXFeature 对象
CString strid;
int id = f.GetFeatureID();
strid.Format("%d",id);
// pCV->m_ResultListBox.InsertItem(j,strid);
// pCV->m_ResultListBox.SetItemText(j,1,f.GetName());
CString strArea;
double area = f.GetArea();
strArea.Format("%5.0f",area);
// pCV->m_ResultListBox.SetItemText(j,2,strArea);
CString strPerimeter;
double per = f.GetPerimeter();
strPerimeter.Format("%5.0f",per);
// pCV->m_ResultListBox.SetItemText(j,3,strPerimeter);
CString strX;
double cx = f.GetCenterX();
strX.Format("%.2f",cx);
// pCV->m_ResultListBox.SetItemText(j,4,strX);
CString strY;
double cy = f.GetCenterY();
strY.Format("%.2f",cy);
// pCV->m_ResultListBox.SetItemText(j,5,strY);
(void)pCV->m_ResultListBox.AddItem( strid, f.GetName(), strArea,strPerimeter,strX, strY);
}
}
}
//pCV->m_ResultListBox.ShowWindow(SW_SHOW);
EndWaitCursor();
}
void CMyMapView::OnMoveDown()
{
double mapx,mapy;
float scx, scy;
mapx = m_map.GetCenterX();
mapy = m_map.GetCenterY();
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miMapToScreen);
//scx = scx - 50;
scy = scy - 50;
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miScreenToMap);
// m_map.SetCenterX(mapx);
m_map.SetCenterY(mapy);
}
void CMyMapView::OnUpdateMoveDown(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMyMapView::OnMoveLeft()
{
double mapx,mapy;
float scx, scy;
mapx = m_map.GetCenterX();
mapy = m_map.GetCenterY();
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miMapToScreen);
scx = scx + 50;
// scy = scy + 50;
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miScreenToMap);
m_map.SetCenterX(mapx);
// m_map.SetCenterY(mapy);
}
void CMyMapView::OnUpdateMoveLeft(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMyMapView::OnMoveRight()
{
double mapx,mapy;
float scx, scy;
mapx = m_map.GetCenterX();
mapy = m_map.GetCenterY();
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miMapToScreen);
scx = scx - 50;
// scy = scy + 50;
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miScreenToMap);
m_map.SetCenterX(mapx);
// m_map.SetCenterY(mapy);
}
void CMyMapView::OnUpdateMoveRight(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMyMapView::OnMoveUp()
{
double mapx,mapy;
float scx, scy;
mapx = m_map.GetCenterX();
mapy = m_map.GetCenterY();
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miMapToScreen);
//scx = scx - 50;
scy = scy + 50;
m_map.ConvertCoord(&scx,&scy,&mapx,&mapy,miScreenToMap);
// m_map.SetCenterX(mapx);
m_map.SetCenterY(mapy);
}
void CMyMapView::OnUpdateMoveUp(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
//通过移动方向键来移动地图
void CMyMapView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// if(nChar == )
MessageBox("char");
CFormView::OnChar(nChar, nRepCnt, nFlags);
}
void CMyMapView::OnThemeModifyRequestedMap1(LPDISPATCH Theme)
{
CMapXDatasets dsets;
CMapXDataset dset;
dsets = m_map.GetDatasets();
dset = dsets.Item(1);
CMapXTheme theme;
theme = dset.GetThemes().Item(1);
theme.ThemeDlg();
}
void CMyMapView::OnPreView()
{
//实现上一视图的显示
m_map.SetZoom(m_dPrevZoom);
m_map.SetCenterX(m_dPrevX);
m_map.SetCenterY(m_dPrevY);
}
void CMyMapView::OnPolyDistanceRuler()
{
m_map.CreateCustomTool(POLY_RULER,miToolTypePoly,miCrossCursor);
m_curtool = POLY_RULER;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdatePolyDistanceRuler(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == POLY_RULER);
}
void CMyMapView::OnPolyToolUsedMap1(short ToolNum, long Flags, LPDISPATCH Points, BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault)
{
if(ToolNum == POLY_RULER)
{
CMapXPoints pts;
long n;
long i;
try{
pts.AttachDispatch(Points,FALSE);
double dDistanceTot = 0.0;
n = pts.GetCount();
for(i= 1;i< n;i++)
{
CMapXPoint pt1 = pts.Item(i);
CMapXPoint pt2 = pts.Item(i + 1);
double d = m_map.Distance(pt1.GetX(),pt1.GetY(),pt2.GetX(),pt2.GetY());
dDistanceTot = dDistanceTot + d;
}
CString str;
str.Format("你所目前所量测得总距离为: %.4f 千米",dDistanceTot);
((CMainFrame *)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0,str);
}
catch (COleDispatchException * e)
{
e->ReportError();
e->Delete();
}
}
}
void CMyMapView::OnGetInfo()
{
m_map.CreateCustomTool(TOOL_INFO,miToolTypePoint,miCrossCursor);
m_curtool = TOOL_INFO;
m_map.SetCurrentTool(m_curtool);
}
void CMyMapView::OnUpdateGetInfo(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_curtool == TOOL_INFO);
}
//CListCtrl