⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singledocumentview.cpp

📁 SuperMap中VC开发环境下投影转换示范源码
💻 CPP
字号:
// SingleDocumentView.cpp : implementation of the CSingleDocumentView class
//

#include "stdafx.h"
#include "SingleDocument.h"

#include "SingleDocumentDoc.h"
#include "SingleDocumentView.h"
#include "mainfrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView

IMPLEMENT_DYNCREATE(CSingleDocumentView, CView)

BEGIN_MESSAGE_MAP(CSingleDocumentView, CView)
	//{{AFX_MSG_MAP(CSingleDocumentView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_COMMAND(ID_MAP_SELECT, OnMapSelect)
	ON_COMMAND(ID_MAP_ZOOMIN, OnMapZoomin)
	ON_COMMAND(ID_MAP_ZOOMOUT, OnMapZoomout)
	ON_COMMAND(ID_MAP_ZOOMFREE, OnMapZoomfree)
	ON_COMMAND(ID_MAP_PAN, OnMapPan)
	ON_COMMAND(ID_MAP_ENTIRE, OnMapEntire)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()


BEGIN_EVENTSINK_MAP(CSingleDocumentView, CView)
    //{{AFX_EVENTSINK_MAP(CDlgDlg)
	ON_EVENT(CSingleDocumentView, 1001, -606 /* MouseMove */, OnMouseMoveSupermapctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView construction/destruction

CSingleDocumentView::CSingleDocumentView()
{
	// TODO: add construction code here

}

CSingleDocumentView::~CSingleDocumentView()
{
}

BOOL CSingleDocumentView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView drawing

void CSingleDocumentView::OnDraw(CDC* pDC)
{
	CSingleDocumentDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView printing

BOOL CSingleDocumentView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSingleDocumentView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSingleDocumentView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView diagnostics

#ifdef _DEBUG
void CSingleDocumentView::AssertValid() const
{
	CView::AssertValid();
}

void CSingleDocumentView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSingleDocumentDoc* CSingleDocumentView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSingleDocumentDoc)));
	return (CSingleDocumentDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSingleDocumentView message handlers

int CSingleDocumentView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	//创建SuperMap实例
	m_SuperMap.Create("SuperMap", WS_CHILD|WS_VISIBLE, CRect(0, 0, 10, 10), this,
				1001, NULL, false);
	
	EnableToolTips(true); 
	m_tt.Create(this); 
	m_tt.Activate(false); 
	m_tt.AddTool(GetDlgItem(1001),"x:y:"); 
	m_tt.EnableToolTips(false); 	
	m_tt.SetDelayTime(10);

	return 0;
}

void CSingleDocumentView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	//窗口变化改变SuperMap的大小
	if(nType == SIZE_RESTORED)
	{
		CRect rc;
		GetClientRect(rc);
		
		if(m_SuperMap.GetSafeHwnd())
		{
			m_SuperMap.MoveWindow(rc);
		}
	}
}

void CSingleDocumentView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	CMainFrame *pFrame = (CMainFrame *)::AfxGetMainWnd();


	//连接SuperMap和SuperWorkspace
	LPDISPATCH lpWorkspace = pFrame->m_SuperWorkspace.GetHandle();
	m_SuperMap.Connect(lpWorkspace); 
	ULONG uRefCount = lpWorkspace->Release();
	BOOL	bOpen;
	bOpen=m_SuperMap.OpenMap("beijing");
	/*CsoError	objEr;
	objEr.CreateDispatch("SuperMap.soError");
	if (bOpen)
	{
		MessageBox("OpenMap Success");
	}
	else
	{
		MessageBox(objEr.GetLastErrorMsg());
	}*/
	//刷新地图窗口
	m_SuperMap.Refresh();
}
void CSingleDocumentView::OnMapSelect() 
{
	//设置地图操作:选择
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaSelect);	
}

void CSingleDocumentView::OnMapZoomin() 
{
	//设置地图操作:放大
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaZoomIn);
}

void CSingleDocumentView::OnMapZoomout() 
{
	//设置地图操作:缩小
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaZoomOut);
}

void CSingleDocumentView::OnMapZoomfree() 
{
	//设置地图操作:自由缩放
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaZoomFree);
}

void CSingleDocumentView::OnMapPan() 
{
	//设置地图操作:平移
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaPan);
}

void CSingleDocumentView::OnMapEntire() 
{
	//全幅显示
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.ViewEntire();	
}


void CSingleDocumentView::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CView::PostNcDestroy();
}

BOOL CSingleDocumentView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_tt.RelayEvent(pMsg);
	return CView::PreTranslateMessage(pMsg);
}


void CSingleDocumentView::OnMouseMoveSupermapctrl1(short Button, short Shift, long x, long y) 
{
	// TODO: Add your control notification handler code here
	if(m_SuperMap.GetLayers().GetCount() == 0) 
	{
		m_tt.EnableToolTips(false);
		return;
	}
	CString strTmp;
	double dX;
	double dY;
	dX=m_SuperMap.PixelToMapX(x);
	dY=m_SuperMap.PixelToMapY(y);
	strTmp.Format("X=%f米 Y=%f米",dX,dY);
	ChangeTY2JWD(dX,dY);
	strTmp=strTmp+strJWD;
	m_tt.DelTool(this); 
	m_tt.Activate(true); 
	m_tt.AddTool(GetDlgItem(1001),strTmp); 
	m_tt.EnableToolTips(true); 
}


void CSingleDocumentView::ChangeTY2JWD(double dx,double dy)
{
	//将当前显示投影下鼠标位置数据,转换为经纬度
	CsoPJCoordSys	objPJC;
	CsoPoint		objPt;
	objPt.CreateDispatch("SuperMap.soPoint");
	objPt.SetX(dx);
	objPt.SetY(dy);
	objPJC=m_SuperMap.GetPJCoordSys();
	objPJC.Inverse(objPt);
	strJWD.Format("||X=%f度,Y=%f度",objPt.GetX(),objPt.GetY());
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -