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

📄 singledocumentview.cpp

📁 基于SUPERMAP的二次开发
💻 CPP
字号:
// SingleDocumentView.cpp : implementation of the CSingleDocumentView class
//

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

#include "SingleDocumentDoc.h"
#include "SingleDocumentView.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)
	ON_EVENT(CSingleDocumentView, 1, 2 /* AfterMapDraw */, OnAfterMapDrawSupermap, VTS_I4)
	ON_EVENT(CSingleDocumentView, 2, -605 /* MouseDown */, OnMouseDownSupermap, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
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_IndexSuperMap.Create("SuperMap", WS_VISIBLE|WS_BORDER|WS_POPUP, CRect(0, 0, 200, 200), this, 
				2, NULL, false);
	
	m_SuperMap.Create("SuperMap", WS_CHILD|WS_VISIBLE, CRect(0, 0, 10, 10), this,
				1, NULL, false);

	
	
	
	return 0;
}

void CSingleDocumentView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	//窗口变化改变SuperMap的大小
	if(nType == SIZE_RESTORED)
	{
		CRect rc,IndexRc;
		GetClientRect(rc);
		
		if(m_SuperMap.GetSafeHwnd())
		{
			m_SuperMap.MoveWindow(rc);
		}
		if (m_IndexSuperMap.GetSafeHwnd())
		{
			IndexRc.left=0;
			IndexRc.top =0;
			IndexRc.bottom=140;
			IndexRc.right=((double)rc.Width()/rc.Height())*140;
			m_IndexSuperMap.MoveWindow(IndexRc);
		}
	}
}

void CSingleDocumentView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	CSingleDocumentDoc *pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//如果当前有数据源,就将其中的数据集添加到地图窗口中
	if(pDoc->m_bHasDatasource == false)
	{
		return;
	}

	//连接SuperMap和SuperWorkspace
	LPDISPATCH lpWorkspace = pDoc->m_pSuperWorkspace->GetHandle();
	m_SuperMap.Connect(lpWorkspace); 
	m_IndexSuperMap.Connect(lpWorkspace);
	ULONG uRefCount = lpWorkspace->Release();
	
	COleVariant var;

	m_strDatasourceAlias = pDoc->m_strDatasourceAlias;//记录当前数据源的别名
	var = m_strDatasourceAlias;
	CsoDataSource Datasource = pDoc->m_pSuperWorkspace->GetDatasources().GetItem(var);//获取数据源
	CsoDatasets Datasets = Datasource.GetDatasets();//获取当前数据源的数据集合
	CsoDataset Dataset;
	
	var.Clear();
	var.vt = VT_I4;

	//将数据集显示在地图窗口中
	int nDatasetCount = Datasets.GetCount();
	for(long i = 0; i<nDatasetCount; i++)
	{
		var.lVal = i+1;
		Dataset = Datasets.GetItem(var);
		if(Dataset != NULL)
		{
			m_SuperMap.GetLayers().AddDataset(Dataset, true);
			m_IndexSuperMap.GetLayers().AddDataset(Dataset,true);
		}
	}
	//刷新地图窗口
	m_SuperMap.Refresh();
	m_IndexSuperMap.Refresh();
}

//DEL void CSingleDocumentView::OnDestroy() 
//DEL {
//DEL 	//关闭地图窗口和断开连接
//DEL 	m_SuperMap.Close();
//DEL 	m_SuperMap.Disconnect();
//DEL 
//DEL 	m_IndexSuperMap.Close();
//DEL 	m_IndexSuperMap.Disconnect();
//DEL 
//DEL 	CView::OnDestroy();
//DEL }

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::OnAfterMapDrawSupermap(long hdc) 
{
	CsoRect objrect;
	CsoStyle objstyle;
	CsoGeoRect objgeorect;
	CsoGeoLine objgeoline;

	objstyle.CreateDispatch("supermap.sostyle");
	objstyle.SetPenColor(RGB(0,0,255));
	objstyle.SetPenWidth(10);
	objrect=m_SuperMap.GetViewBounds();
	objgeorect.CreateDispatch("supermap.sogeorect");
	objgeorect.SetLeft(objrect.GetLeft());
	objgeorect.SetRight(objrect.GetRight());
	objgeorect.SetTop(objrect.GetTop());
	objgeorect.SetBottom(objrect.GetBottom());
	
	objgeoline=objgeorect.ConvertToLine();
	m_IndexSuperMap.GetTrackingLayer().ClearEvents();
	m_IndexSuperMap.GetTrackingLayer().AddEvent(objgeoline,objstyle,"");
	m_IndexSuperMap.GetTrackingLayer().Refresh();
	objgeorect.ReleaseDispatch();
	objstyle.ReleaseDispatch();

	
}

void CSingleDocumentView::OnMouseDownSupermap(short Button, short Shift, long x, long y) 
{
	// TODO: Add your control notification handler code here
	double dx,dy;
	dx=m_IndexSuperMap.PixelToMapX(x);
	dy=m_IndexSuperMap.PixelToMapY(y);
	m_SuperMap.SetCenterX(dx);
	m_SuperMap.SetCenterY(dy);
	m_SuperMap.Refresh();
}

⌨️ 快捷键说明

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