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

📄 giskelview.cpp

📁 在Visual C++中利用mo加载图层
💻 CPP
字号:
// GisKelView.cpp : CGisKelView 类的实现
//

#include "stdafx.h"
#include "GisKel.h"

#include "GisKelDoc.h"
#include "GisKelView.h"

#include "modataconnection.h"
#include "molayers.h"
#include "momaplayer.h"
#include "mogeodataset.h"
#include "mosymbol.h"
#include ".\giskelview.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CGisKelView

IMPLEMENT_DYNCREATE(CGisKelView, CFormView)

BEGIN_MESSAGE_MAP(CGisKelView, CFormView)
	ON_WM_SIZE()
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()

// CGisKelView 构造/析构

CGisKelView::CGisKelView()
	: CFormView(CGisKelView::IDD)
{
	// TODO: 在此处添加构造代码

}

CGisKelView::~CGisKelView()
{
}

void CGisKelView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MAP1, m_map);
}

BOOL CGisKelView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
	// 样式

	return CFormView::PreCreateWindow(cs);
}

void CGisKelView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
}


// CGisKelView 诊断

#ifdef _DEBUG
void CGisKelView::AssertValid() const
{
	CFormView::AssertValid();
}

void CGisKelView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CGisKelDoc* CGisKelView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGisKelDoc)));
	return (CGisKelDoc*)m_pDocument;
}
#endif //_DEBUG


// CGisKelView 消息处理程序
void CGisKelView::OnSize(UINT nType, int cx, int cy)
{
	CFormView::OnSize(nType, cx, cy);

	if(m_map.m_hWnd)			//首先需要判断地图控件窗口是否已经创建
		//将地图控件的大小调整为视窗窗口的大小
		m_map.SetWindowPos(0, 0, 0, cx, cy, SWP_NOZORDER);
}

CString CGisKelView::AddShpLayer(const CString & path, COLORREF color, short symbolSize, short symbolStyle)
{

	CMoDataConnection conn;
	if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection"))) return "";
	conn.SetDatabase(GetFileDirectory(path));
	if (!conn.Connect()) return "";

	// Add layer specified by path
	CMoLayers layers=m_map.GetLayers();
	CMoMapLayer layer;
	if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer"))) return "";

	CString LayerName = GetFileTitle(path);
	CMoGeoDataset geoDataset=conn.FindGeoDataset(LayerName);
	if(!geoDataset) return "";

	layer.SetGeoDataset(geoDataset);
	CMoSymbol layerSymbol(layer.GetSymbol());

	if (color != -1) layerSymbol.SetColor(color); // Set color if specified

	layerSymbol.SetSize(symbolSize);
	layerSymbol.SetStyle(symbolStyle);
	layers.Add(layer);
	return(layer.GetName());
}

CString CGisKelView::GetFileDirectory(const CString& path)
{

	int pos = path.ReverseFind('\\');
	if (pos >= 0) return path.Left(pos);
	return "";

}

CString CGisKelView::GetFileTitle(const CString& path)
{

	CString strResult = GetFileName(path);
	int pos = strResult.ReverseFind('.');
	if (pos >= 0) return strResult.Left(pos);
	return strResult;

}

CString CGisKelView::GetFileName(const CString& path)
{

	int pos = path.ReverseFind('\\');
	if (pos >= 0) return path.Right(path.GetLength() - pos - 1);
	return path;
}
void CGisKelView::OnFileOpen()
{
	// TODO: Add your command handler code here
	AddShpLayer("G:\\GisKel\\example\\street.shp",RGB(125,125,125), 0, 0);
}


⌨️ 快捷键说明

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