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

📄 supermap exampleview.cpp

📁 基于SUPERMAP、VC++的二次开发
💻 CPP
字号:
// SuperMap ExampleView.cpp : implementation of the CSuperMapExampleView class
//

#include "stdafx.h"
#include "SuperMap Example.h"

#include "SuperMap ExampleDoc.h"
#include "SuperMap ExampleView.h"

#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView

IMPLEMENT_DYNCREATE(CSuperMapExampleView, CView)

BEGIN_MESSAGE_MAP(CSuperMapExampleView, CView)
	//{{AFX_MSG_MAP(CSuperMapExampleView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_DESTROY()
	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)
	ON_COMMAND(ID_MAP_REFRESH, OnMapRefresh)
	ON_COMMAND(ID_DT_ADD2MAP, OnDtAdd2map)
	ON_COMMAND(ID_DT_SNGOPEN, OnDtSngopen)
	ON_COMMAND(ID_DT_TOPO, OnDtTopo)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView construction/destruction

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

}

CSuperMapExampleView::~CSuperMapExampleView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSuperMapExampleView message handlers

int CSuperMapExampleView::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,
				1, NULL, false);
	
	return 0;
}

void CSuperMapExampleView::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 CSuperMapExampleView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	CSuperMapExampleDoc *pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->SetTitle("Topo功能演示");
	
	//如果当前有数据源,就将其中的数据集添加到地图窗口中
	if(pDoc->m_bHasDatasource == false)
	{
		return;
	}

	//连接SuperMap和SuperWorkspace
	LPDISPATCH lpWorkspace = pDoc->m_pSuperWorkspace->GetHandle();
	m_SuperMap.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_SuperMap.Refresh();
	*/
}

void CSuperMapExampleView::OnDestroy() 
{
	//关闭地图窗口和断开连接
	m_SuperMap.Close();
	m_SuperMap.Disconnect();

	CView::OnDestroy();
}

void CSuperMapExampleView::OnMapSelect() 
{
	//设置地图操作:选择
	if(m_SuperMap.GetLayers().GetCount() == 0) return;
	m_SuperMap.SetAction(scaSelect);	
}

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

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

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

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

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

void CSuperMapExampleView::OnDtAdd2map() 
{
	// 将数据集添加到地图窗口
	CMainFrame *pFrame = (CMainFrame *)::AfxGetMainWnd();
	CsoDataSource	objDs;
	CsoDataset		objDt;	
	CsoDatasets		objDts;
	COleVariant		var;
	var=pFrame->m_MyDlgBar.strDs;
	objDs=pFrame->m_SuperWorkspace.GetDatasources().GetItem(var);
	var=pFrame->m_MyDlgBar.strDt;
	objDts=objDs.GetDatasets();
	objDt=objDts.GetItem(var);
	m_SuperMap.GetLayers().AddDataset(objDt,true);
	m_SuperMap.Refresh();
}

void CSuperMapExampleView::OnDtSngopen() 
{
	//单独打开该数据集
	CMainFrame *pFrame = (CMainFrame *)::AfxGetMainWnd();
	CsoDataSource	objDs;
	CsoDataset		objDt;	
	CsoDatasets		objDts;
	COleVariant		var;
	var=pFrame->m_MyDlgBar.strDs;
	objDs=pFrame->m_SuperWorkspace.GetDatasources().GetItem(var);
	var=pFrame->m_MyDlgBar.strDt;
	objDts=objDs.GetDatasets();
	objDt=objDts.GetItem(var);
	m_SuperMap.GetLayers().RemoveAll();
	m_SuperMap.GetLayers().AddDataset(objDt,true);
	m_SuperMap.Refresh();
}

void CSuperMapExampleView::OnDtTopo() 
{
	//调用拓扑处理窗口
	CMainFrame *pFrame = (CMainFrame *)::AfxGetMainWnd();
	CsoDataSource	objDs;
	CsoDataset		objDt;	
	CsoLayer		objLy;
	COleVariant		var;
	CString			strTmp;
	strTmp=pFrame->m_MyDlgBar.strDt + "@" +pFrame->m_MyDlgBar.strDs;
	var=strTmp;
	objLy=m_SuperMap.GetLayers().GetItem(var);
	if(objLy==NULL)
	{
		m_SuperMap.GetLayers().RemoveAt(var);
	}
	m_MyTopoDlg.DoModal();
}

⌨️ 快捷键说明

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