www.pudn.com > GEOMAP.rar > GEOMAPView.cpp


// GEOMAPView.cpp : implementation of the CGEOMAPView class 
// 
 
#include "stdafx.h" 
#include "GEOMAP.h" 
#include "cmapx.h" 
#include "GEOMAPDoc.h" 
#include "GEOMAPView.h" 
 
#include "MainFrm.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CGEOMAPView 
 
IMPLEMENT_DYNCREATE(CGEOMAPView, CFormView) 
 
BEGIN_MESSAGE_MAP(CGEOMAPView, CFormView) 
	//{{AFX_MSG_MAP(CGEOMAPView) 
	ON_WM_SIZE() 
	ON_COMMAND(IDC_OPEN__MAP, OnOpenMap) 
	ON_COMMAND(IDC_PAN__MAP, OnPanMap) 
	ON_COMMAND(IDC_ZOOMIN__MAP, OnZoominMap) 
	ON_COMMAND(IDC_ZOOMOUT__MAP, OnZoomoutMap) 
	ON_COMMAND(ID_FULLEVENT_MAP, OnFulleventMap) 
	ON_COMMAND(ID_DISTANCE_MAP, OnDistanceMap) 
	ON_COMMAND(ID_SIZE_MAP, OnSizeMap) 
	ON_COMMAND(ID_LAYER_EDIT, OnLayerEdit) 
	ON_COMMAND(ID_LAYER_INFOR, OnLayerInfor) 
	ON_COMMAND(ID_ADD_LABEL, OnAddLabel) 
	ON_COMMAND(ID_OPEN_GEOM, OnOpenGeom) 
	ON_MESSAGE(WM_MSG,OnTreeMouseDown) 
    ON_MESSAGE(WM_MSGCHANGE,OnTreeMouseDown1) 
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1) 
	ON_NOTIFY(TCN_SELCHANGING, IDC_TAB1, OnSelchangingTab1) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CGEOMAPView construction/destruction 
 
CGEOMAPView::CGEOMAPView() 
	: CFormView(CGEOMAPView::IDD) 
{ 
	//{{AFX_DATA_INIT(CGEOMAPView) 
	m_str1 = _T(""); 
	//}}AFX_DATA_INIT 
	// TODO: add construction code here 
 
} 
 
CGEOMAPView::~CGEOMAPView() 
{ 
} 
 
void CGEOMAPView::DoDataExchange(CDataExchange* pDX) 
{ 
	CFormView::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CGEOMAPView) 
	DDX_Control(pDX, IDC_TAB1, m_tab); 
	DDX_Control(pDX, IDC_EDIT1, m_Edit); 
	DDX_Control(pDX, IDC_STATIC2, m_Static2); 
	DDX_Control(pDX, ID_STATIC, m_Static); 
	DDX_Control(pDX, IDC_TREEVIEW1, m_Tree1); 
	DDX_Control(pDX, IDC_STATIC1, m_Static1); 
	DDX_Control(pDX, IDC_MAP1, m_Map1); 
	DDX_Control(pDX, IDC_MAP2, m_Map2); 
	DDX_Text(pDX, IDC_EDIT1, m_str1); 
	//}}AFX_DATA_MAP 
} 
 
BOOL CGEOMAPView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CFormView::PreCreateWindow(cs); 
} 
 
void CGEOMAPView::OnInitialUpdate() 
{ 
	CFormView::OnInitialUpdate(); 
	GetParentFrame()->RecalcLayout(); 
	ResizeParentToFit(); 
    m_str1="请打开gst文件"; 
    UpdateData(FALSE); 
   if(!page1.m_hWnd||!page2.m_hWnd)  //第一次初始化m_tab 控件和page页的建立 
   { 
    //初始化m_tab控件 
    m_tab.InsertItem(1,"图层信息"); 
    m_tab.InsertItem(2,"属性查询"); 
    //建立属性页各页 
    page1.Create(IDD_DIALOG1,GetDlgItem(IDC_TAB1)); 
    page2.Create(IDD_DIALOG2,GetDlgItem(IDC_TAB1)); 
 
    //设置页面的位置在m_tab控件范围内 
    CRect rs; 
    m_tab.GetClientRect(rs); 
    rs.bottom+=20; 
    rs.top-=4; 
    rs.left+=4; 
    rs.right-=4; 
     
    page1.MoveWindow(rs); 
    page2.MoveWindow(rs); 
    page1.ShowWindow(TRUE); 
// m_tab.MoveWindow(500,0,300,400,TRUE); 
    m_tab.SetCurSel(0); 
   } 
} 
///////////////////////////////////////////////////////////////////////////// 
// CGEOMAPView printing 
 
BOOL CGEOMAPView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CGEOMAPView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CGEOMAPView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
void CGEOMAPView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add customized printing code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CGEOMAPView diagnostics 
 
#ifdef _DEBUG 
void CGEOMAPView::AssertValid() const 
{ 
	CFormView::AssertValid(); 
} 
 
void CGEOMAPView::Dump(CDumpContext& dc) const 
{ 
	CFormView::Dump(dc); 
} 
 
CGEOMAPDoc* CGEOMAPView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGEOMAPDoc))); 
	return (CGEOMAPDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CGEOMAPView message handlers 
 
 
void CGEOMAPView::OnSize(UINT nType, int cx, int cy)  
{ 
	CFormView::OnSize(nType, cx, cy); 
	if(m_Map1.m_hWnd) 
	{ 
		m_Map1.MoveWindow(0,0,cx*25/32,cy,TRUE); 
	    m_Map2.MoveWindow(cx*26/32,cy*3/4,cx*5/32,cy*7/32,TRUE); 
		m_Static.MoveWindow(cx*51/64,cy*23/32,cx*6/32,cy*17/64,TRUE); 
       
        m_Static1.MoveWindow(cx*25/32,0,cx*11/50,cy,TRUE); 
        m_Static2.MoveWindow(cx*51/64,cy/35,cx*6/32,cy/6,TRUE); 
		m_Edit.MoveWindow(cx*51/64,cy/20,cx*6/32,cy/7,TRUE); 
	//	m_Tree1.MoveWindow(cx*51/64,cy*21/100,cx*6/32,cy/2,TRUE); 
       m_tab.MoveWindow(cx*51/64,cy*21/100,cx*6/32,cy/2,TRUE); 
	} 
	// TODO: Add your message handler code here 
	 
} 
 
void CGEOMAPView::OnOpenMap()  
{ 
    char FileFilter[] = "Gst File(*.gst)|*.gst|"; 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,FileFilter); 
	CString strGeoSet; 
	if(dlg.DoModal()==IDOK) 
	{ 
	strGeoSet = dlg.GetPathName(); 
	m_Map1.SetGeoSet(strGeoSet); 
	m_Map2.SetGeoSet(strGeoSet); 
	m_str1="打开文件:\r\n"+strGeoSet; 
    UpdateData(FALSE); 
    CMapXLayers layers = m_Map1.GetLayers(); 
	long layercount = layers.GetCount();    //获得图层数 
	 
	CMutiTreeCtrl* pTree = (CMutiTreeCtrl*) GetDlgItem(IDC_TREEVIEW1); 
 
	m_imgState.Create(IDB_BITMAP_STATE,13, 1, RGB(255,255,255)); 
	m_Tree1.SetImageList(&m_imgState,TVSIL_STATE); 
 
    
   TV_INSERTSTRUCT tvinsert; 
   tvinsert.hInsertAfter = TVI_LAST; 
   tvinsert.item.mask=TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT|TVIF_STATE; 
   tvinsert.item.hItem = NULL;  
   tvinsert.item.state = 0; 
   tvinsert.item.stateMask = 0; 
   tvinsert.item.cchTextMax = 6; 
   tvinsert.item.iSelectedImage = 1; 
   tvinsert.item.cChildren = 0; 
   tvinsert.item.lParam = 0; 
 
    
// top level 
 
  char a[100];  
  HTREEITEM hMom= pTree->InsertItem(&tvinsert); 
    
 
  for(int i=0;iInsertItem(&tvinsert); 
 
    tvinsert.hParent = hDad; 
    CMapXLayer layer=layers.Item(i+1); 
    CMapXFeatures features=layer.AllFeatures(); 
    long featuresCount = features.GetCount();     //获得图元数 
    for(int j=0;j< featuresCount;j++) 
	{ 
     strGeoSet=features.Item(j+1).GetName(); 
     strncpy(a,(LPCTSTR)strGeoSet,sizeof(a)); 
     tvinsert.item.pszText = a; 
     pTree->InsertItem(&tvinsert); 
	} 
   m_Tree1.SetItemState( hMom, INDEXTOSTATEIMAGEMASK(3), TVIS_STATEIMAGEMASK );//初始时都被选中 
  } 
 
} 
 
	else 
	{ 
	} 
	// TODO: Add your command handler code here 
	 
} 
 
void CGEOMAPView::OnPanMap()  
{ 
m_Map1.SetCurrentTool(miPanTool);	// TODO: Add your command handler code here 
	 
} 
 
void CGEOMAPView::OnZoominMap()  
{ 
	// TODO: Add your command handler code here 
m_Map1.SetCurrentTool(miZoomInTool);	 
} 
 
void CGEOMAPView::OnZoomoutMap()  
{ 
	// TODO: Add your command handler code here 
m_Map1.SetCurrentTool(miZoomOutTool);	 
} 
 
void CGEOMAPView::OnFulleventMap()  
{ 
	// TODO: Add your command handler code here 
m_Map1.SetBounds(m_Map1.GetLayers().GetBounds());	 
} 
 
void CGEOMAPView::OnDistanceMap()  
{ 
	// TODO: Add your command handler code here 
    m_Map1.CreateCustomTool(199,miToolTypeLine, miSizeCursor); 
    m_Map1.SetCurrentTool(199);	 
} 
void CGEOMAPView::OnSizeMap()  
{ 
	// TODO: Add your command handler code here 
	m_Map1.SetCurrentTool(miRectSelectTool); 
} 
BEGIN_EVENTSINK_MAP(CGEOMAPView, CFormView) 
    //{{AFX_EVENTSINK_MAP(CGEOMAPView) 
	ON_EVENT(CGEOMAPView, 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(CGEOMAPView, IDC_MAP1, -606 /* MouseMove */, OnMouseMoveMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4) 
	ON_EVENT(CGEOMAPView, IDC_MAP2, -605 /* MouseDown */, OnMouseDownMap2, VTS_I2 VTS_I2 VTS_R4 VTS_R4) 
	//}}AFX_EVENTSINK_MAP 
END_EVENTSINK_MAP() 
 
void CGEOMAPView::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)  
{ 
	// TODO: Add your control notification handler code here 
	if(ToolNum == 199)              //测距离 
	{   
       CString m_strStart; 
	   CString m_strEnd; 
 
	   m_strStart.Format("起点:%d,%d\r\n",X1,Y1); 
       m_strEnd.Format("终点:%d,%d\r\n",X2,Y2); 
       m_str1.Format("距离:%lf MILES\r\n",m_Map1.Distance(X1,Y1,X2,Y2)); 
       m_str1=m_strStart+m_strEnd+m_str1; 
	   UpdateData(FALSE); 
	} 
    	else if(ToolNum ==miRectSelectTool)         //测面积 
	{ 
		double area; 
	    CString str; 
		CMapXLayers layers = m_Map1.GetLayers(); 
    	CMapXLayer layer = layers.Item(5); 
	    layers.SetAnimationLayer(layer);//设置当前多边形图层为动态图层,以便于框选 
 
		CMapXRectangle rectangle; 
        rectangle.CreateDispatch(rectangle.GetClsid()); 
        rectangle.Set(X1,Y1,X2,Y2); 
		CMapXFeatures features = layer.SearchWithinRectangle(rectangle,miSearchTypePartiallyWithin); 
	    CMapXFeature feature = features.Item(1); 
	    area = feature.GetArea(); 
        m_str1.Format("area=%lf square miles",area); 
	    UpdateData(FALSE); 
 
	} 
		else 
			m_Map1.GetLayers().SetAnimationLayer(NULL); 
} 
 
 
 
void CGEOMAPView::OnMouseMoveMap1(short Button, short Shift, float X, float Y)  
{    
	CString m_str; 
    CString m_str2; 
    	  
	double MapX,MapY; 
 
    m_Map2.ConvertCoord(&X,&Y,&MapX,&MapY, miScreenToMap); 
 
    m_str.Format("X=%.2f,Y=%.2f",X,Y); 
	 
     
    m_str2.Format("X=%.2d,Y=%.2d",MapX,MapY); 
    m_str="   屏幕坐标:"+m_str+"   地图坐标:"+m_str2; 
	CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd; 
	CStatusBar* pStatus=&pFrame->m_wndStatusBar; 
	if(pStatus) 
	{   
	   pStatus->SetPaneText(0,m_str); 
       pStatus->SetPaneText(2,"GIS"); 
	} 
    UpdateData(FALSE);	// TODO: Add your control notification handler code here 
	 
} 
 
void CGEOMAPView::OnMouseDownMap2(short Button, short Shift, float X, float Y)  
{ 
	// TODO: Add your control notification handler code here 
	 double ScreenX,ScreenY; 
 
     // Convert the screen center to map coordinates 
     m_Map2.ConvertCoord(&X,&Y,&ScreenX,&ScreenY, miScreenToMap); 
 
     m_Map1.SetCenterX(ScreenX); 
	 m_Map1.SetCenterY(ScreenY); 
} 
 
void CGEOMAPView::OnLayerEdit()  
{ 
	// TODO: Add your command handler code here 
    CMapXLayers layers = m_Map1.GetLayers(); 
    layers.LayersDlg();	 
} 
 
void CGEOMAPView::OnLayerInfor()  
{ 
	// TODO: Add your command handler code here 
m_Map1.PropertyPage();	 
} 
 
void CGEOMAPView::OnAddLabel()  
{ 
	// TODO: Add your command handler code here 
m_Map1.SetCurrentTool(miLabelTool);	 
} 
 
void CGEOMAPView::OnOpenGeom()  
{ 
	// TODO: Add your command handler code here 
 ShellExecute(NULL,NULL,_T("GeosetManager50"),NULL,_T("E:\\vc\\GEOMAP1\\res"),SW_SHOW); 
 m_str1 = "您打开的是工具GeosetManager50\r\n该工具可以对gst文件进行管理与\r\n编辑"; 
 UpdateData(FALSE); 
} 
 
LONG CGEOMAPView::OnTreeMouseDown(WPARAM wP,LPARAM lP) 
{   
	//AfxMessageBox("You have selected "); 
    m_str1.Format("%s",wP);  
    UpdateData(FALSE); 
 
	return 0; 
} 
 
LONG CGEOMAPView::OnTreeMouseDown1(WPARAM wP,LPARAM lP) 
{   
    m_str1.Format("%s",wP);  
    UpdateData(FALSE); 
	return 0; 
} 
	// TODO: Add your message handler code here and/or call default 
 
/*	CMapXLayers layers=m_map.GetLayers(); 
	char     m_lay[15],featurename[15]; 
	m_layer.GetWindowText(m_lay,15); 
    m_feature.GetWindowText(featurename,15); 
    CMapXLayer layer=layers.Item(m_lay); 
    CMapXFindFeature feature=layer.GetFind().Search(featurename);   
//  layer.GetSelection().SelectByPoint(feature.GetCenterX(),feature.GetCenterY(),miSelectionRemove); 
	if(flag==0) 
	{ 
		AfxMessageBox("please select a feature!"); 
	} 
    else if(flag==1) 
	{ 
	layers.SetAnimationLayer(layer);//设置所选图层为动态图层,以便于显示 
    layer.GetSelection().SelectByPoint(feature.GetCenterX(),feature.GetCenterY(),miSelectionNew); 
    m_map.GetAutoRedraw();        //自动重绘MAP1图形   
	m_map.SetCenterX(feature.GetCenterX());   //将MAP1图形以查找区域为中心显示 
    m_map.SetCenterY(feature.GetCenterY()); 
	}*/ 
 
void CGEOMAPView::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	int CurSel; 
	CurSel=m_tab.GetCurSel(); 
	switch(CurSel) 
	{ 
	case 0: 
		page1.ShowWindow(TRUE); 
		break; 
	case 1: 
		page2.ShowWindow(TRUE); 
		break; 
	default: ; 
	} 
 
	*pResult = 0; 
} 
 
void CGEOMAPView::OnSelchangingTab1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
int CurSel; 
	CurSel=m_tab.GetCurSel(); 
	switch(CurSel) 
	{ 
	case 0: 
		page1.ShowWindow(FALSE); 
		break; 
	case 1: 
		page2.ShowWindow(FALSE); 
		break; 
	default: ; 
	} 
	 
	*pResult = 0; 
}