📄 mohelp.cpp
字号:
#include "stdafx.h"
#include <math.h>
#include <afxctl.h>
#include "maphelper.h"
CDataDir::CDataDir()
: m_path("")
{
char szPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,szPath);
CString currentDir(szPath);
int pos = currentDir.Find("MFC");
if (pos >= 0)
m_path = (currentDir.Left(pos-1)) + TEXT("\\Data");
else
m_path = "";
}
CString CDataDir::GetPath()
{
return m_path;
}
void CDataDir::SetPath(LPCTSTR newPath)
{
m_path = newPath;
}
///////////////////////////////////////////////////////////////////////////
// File name handling
// get file path
CString GetFileDirectory(const CString& path)
{
ASSERT(path.GetLength());
int pos = path.ReverseFind('\\');
if (pos >= 0)
return path.Left(pos);
return "";
}
//Get file name
CString GetFileName(const CString& path)
{
ASSERT(path.GetLength());
int pos = path.ReverseFind('\\');
if (pos >= 0)
return path.Right(path.GetLength() - pos - 1);
return "";
}
CString GetFileExt(const CString& path)
{
ASSERT(path.GetLength());
int pos = path.ReverseFind('.');
if (pos >= 0)
return path.Right(path.GetLength() - pos - 1);
return "";
}
//get file title
CString GetFileTitle(const CString& path)
{
ASSERT(path.GetLength());
CString strResult = GetFileName(path);
int pos = strResult.ReverseFind('.');
if (pos >= 0)
return strResult.Left(pos);
return strResult;
}
///////////////////////////////////////////////////////////////////////////
// Layer Management
//
void AddLayer(CMap1& map, const CString& path, COLORREF color, LPDISPATCH renderer)
{
// Establish connection to data...........................
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
throw "unable to create MapObjects2.DataConnection";
//设置要连接的数据所在的路径
conn.SetDatabase(GetFileDirectory(path));
if (!conn.Connect())
throw "unable to connect to database";
//......................................................
// Add layer specified by path
//连接相应的矢量数据集
CMoLayers layers(map.GetLayers());//CMoLayers是map控件中所有矢量数据与栅格数据的集合
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
throw "unable to create MapObjects2.MapLayer";
//创建一个空间数据集对象
CMoGeoDataset geoDataset(conn.FindGeoDataset(GetFileTitle(path)));
//挂接,将矢量数据集对象与创建的空间数据集对象进行连接
layer.SetGeoDataset(geoDataset);
if (color != -1) // Set color if specified
{
//确定地图上要素层或几何图形的显示
CMoSymbol layerSymbol(layer.GetSymbol());
layerSymbol.SetColor(color);
}
if (renderer)
layer.SetRenderer(renderer);
layers.Add(layer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -