?? singledocumentview.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 + -