📄 infodlg.cpp
字号:
// InfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NameGis.h"
#include "MainFrm.h"
#include "NameGisView.h"
#include "MapObjects2.h"
#include "Crack.h"
#include "AppApi.h"
#include "InfoDlg.h"
// CInfoDlg dialog
//----------------------------------------------------------------------------------------------
IMPLEMENT_DYNAMIC(CInfoDlg, CDialog)
CInfoDlg::CInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CInfoDlg::IDD, pParent)
, m_FeatureNum(_T(""))
, m_FeatureType(_T(""))
{
m_pItmInfos = NULL;
}
//----------------------------------------------------------------------------------------------
CInfoDlg::~CInfoDlg()
{
if(m_pItmInfos)
{
delete []m_pItmInfos;
m_pItmInfos = NULL;
}
}
//----------------------------------------------------------------------------------------------
void CInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INFO_COMBO, m_FeatureBox);
DDX_Control(pDX, IDC_INFO_INFORESULT, m_FeatureInfoList);
DDX_Text(pDX, IDC_INFO_NUM, m_FeatureNum);
DDX_Text(pDX, IDC_INFO_TYPE, m_FeatureType);
}
BEGIN_MESSAGE_MAP(CInfoDlg, CDialog)
ON_CBN_SELCHANGE(IDC_INFO_COMBO, OnCbnSelchangeInfoCombo)
END_MESSAGE_MAP()
// CInfoDlg message handlers
//----------------------------------------------------------------------------------------------
// 功能:确定指定位置的地物
// 参数:[in]long x 鼠标位置的X值(像素坐标)
// [in]long y 鼠标位置的Y值(像素坐标)
// 返回值:void
void CInfoDlg::Identify(int x, int y)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
CEnvironment* env = &(pMainWnd->m_environment);
env->ClearSelRsts();
int nFeatCount = 0; //选中地物的数目
CMoPoint pt; //鼠标的位置(地图坐标)
pt = pMapView->m_Map.ToMapPoint(x, y);
m_nIdx = -1;
//初始化控件
m_FeatureBox.ResetContent();
m_FeatureInfoList.ResetContent();
if(!m_pItmInfos)
m_pItmInfos = new ItemInfo[env->m_nLayerNum];
//动态计算查询距离
double dScale = env->CalcScale(&(pMapView->m_Map)); //地图比例尺
if (dScale > 8000)
{
dScale = dScale/10000;
dScale = dScale / 5000;
}
else
{
dScale = dScale/10000;
dScale = dScale / 2500;
}
//首先,查询点地物,其次,查询线地物,最后查询面状地物
//查询的图层只要是可见的
int aShapeType[3];
aShapeType[0] = moShapeTypePoint;
aShapeType[1] = moShapeTypeLine;
aShapeType[2] = moShapeTypePolygon;
for (int j = 0; j < 3; j ++)
{
for (int i = 0; i < env->m_nLayerNum; i ++)
{
if (env->m_layerInfos[i].layer.GetShapeType() != aShapeType[j])
continue;
m_pItmInfos[i].szName = "";
//图层可见并且可选择,才能够identify
if (env->m_layerInfos[i].layer.GetVisible()
&& env->m_layerInfos[i].bCanSelected)
{
m_pItmInfos[i].rst =
env->m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
}
else
{
//图层不可显示,则跳到下一个
m_pItmInfos[i].rst = NULL;
continue;
}
m_pItmInfos[i].szTable = env->m_layerInfos[i].szTableName;
m_pItmInfos[i].layer = env->m_layerInfos[i].layer ;
m_pItmInfos[i].szType = env->m_layerInfos[i].szType;
m_pItmInfos[i].szSubType = env->m_layerInfos[i].szSubType;
m_pItmInfos[i].szFieldName = env->m_layerInfos[i].szFieldName;
if (m_pItmInfos[i].rst)
{
if (!m_pItmInfos[i].rst.GetEof())
{
CString szTemp = m_pItmInfos[i].rst.GetFields().Item(
COleVariant("名称")).GetValueAsString();
if (szTemp != "")
{
m_pItmInfos[i].szName = szTemp;
}
else
{
m_pItmInfos[i].rst = NULL;
continue;
}
if (m_pItmInfos[i].szName != "")
{
m_FeatureBox.AddString(m_pItmInfos[i].szName);
nFeatCount ++;
}
}
}
}
}
if (nFeatCount > 0)
{
char buffer[20];
_itoa(nFeatCount, buffer, 10 );
m_FeatureNum = "总共找到" + CString(buffer) + "个地名";
m_FeatureBox.SetCurSel(0);
m_nIdx = 0;
CString str;
m_FeatureBox.GetLBText(0, str);
LoadListBox(GetIndex(str));
UpdateData(FALSE);
}
else
{
m_FeatureNum = "没有找到任何地名";
m_FeatureType = "类型:没有";
env->m_selectedSymbol = NULL;
env->m_selectedFeature = NULL;
UpdateData(FALSE);
}
}
//----------------------------------------------------------------------------------------------
// 功能:显示地名的详细信息
BOOL CInfoDlg::LoadListBox(int nIndex)
{
if ("" == m_pItmInfos[nIndex].szName)
return FALSE;
m_FeatureInfoList.ResetContent();
m_FeatureType = "类型:"+m_pItmInfos[nIndex].szSubType;
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->
m_wndSplitter.GetPane(0,0));
if (m_pItmInfos[nIndex].szTable == "")
{
m_FeatureInfoList.AddString("没有详细信息");
goto FLASH;
}
else
{
CDaoDatabase* tmpDB = new CDaoDatabase;
try
{
tmpDB->Open(pMainWnd->m_environment.m_szDBName);
}
catch (CDaoException* e)
{
DisplayDaoException(e);
delete tmpDB;
e->Delete();
return FALSE;
}
CDaoRecordset rs(tmpDB);
try
{
CString szSQL;
szSQL = "Select * From [" + m_pItmInfos[nIndex].szTable + "] Where "
+ m_pItmInfos[nIndex].szFieldName +" ='"+ m_pItmInfos[nIndex].szName+"'";
rs.Open(dbOpenDynaset, szSQL);
if (0 == rs.GetRecordCount())
{
m_FeatureInfoList.AddString("没有详细信息");
goto FLASH;
}
COleVariant var;
for (int i = 0; i < rs.GetFieldCount(); i ++)
{
CDaoFieldInfo fieldInfo;
rs.GetFieldInfo(i, fieldInfo, AFX_DAO_PRIMARY_INFO);
var = rs.GetFieldValue(i);
CString szValue = fieldInfo.m_strName + ":"
+ CCrack::strVARIANT(var);
m_FeatureInfoList.AddString(szValue);
}
}
catch (CDaoException* e)
{
// DisplayDaoException(e);
delete tmpDB;
e->Delete();
goto FLASH;
}
if(tmpDB)
{
if(tmpDB->IsOpen())
{
tmpDB->Close();
}
delete tmpDB;
tmpDB = NULL;
}
}
FLASH:
// 闪烁显示选择的地物4次
pMapView->m_Map.FlashShape(m_pItmInfos[nIndex].rst.GetFields().Item(
COleVariant("Shape")).GetValue().pdispVal, 4);
//设置选中地物的符号
if (pMainWnd->m_environment.m_layerInfos[nIndex].nCharacterIndex >= 0
&& pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetShapeType()
== moShapeTypePoint)
{
if(pMainWnd->m_environment.m_selectedSymbol)
pMainWnd->m_environment.m_selectedSymbol.ReleaseDispatch();
pMainWnd->m_environment.m_selectedSymbol.CreateDispatch(
_T("MapObjects2.Symbol"));
pMainWnd->m_environment.m_selectedSymbol.SetSymbolType(
moPointSymbol);
pMainWnd->m_environment.m_selectedSymbol.GetFont().SetName(
pMainWnd->m_environment.m_layerInfos[nIndex].szFontName);
pMainWnd->m_environment.m_selectedSymbol.SetStyle(4);
pMainWnd->m_environment.m_selectedSymbol.SetSize(pMainWnd->
m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetSize());
pMainWnd->m_environment.m_selectedSymbol.SetCharacterIndex(
pMainWnd->m_environment.m_layerInfos[nIndex].nCharacterIndex);
pMainWnd->m_environment.m_selectedSymbol.SetColor(0xff);
pMainWnd->m_environment.m_selectedSymbolSize =
pMainWnd->m_environment.m_layerInfos[nIndex].nSymSize;
}
else
{
if (pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetShapeType()
== moShapeTypePoint)
{
if(pMainWnd->m_environment.m_selectedSymbol)
pMainWnd->m_environment.m_selectedSymbol.ReleaseDispatch();
pMainWnd->m_environment.m_selectedSymbol.CreateDispatch(
_T("MapObjects2.Symbol"));
pMainWnd->m_environment.m_selectedSymbol.SetSymbolType(pMainWnd->
m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetSymbolType());
pMainWnd->m_environment.m_selectedSymbol.SetStyle(pMainWnd->
m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetStyle());
pMainWnd->m_environment.m_selectedSymbol.SetSize(pMainWnd->
m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetSize());
pMainWnd->m_environment.m_selectedSymbol.SetColor(0xff);
pMainWnd->m_environment.m_selectedSymbolSize =
pMainWnd->m_environment.m_layerInfos[nIndex].nSymSize;
}
else
pMainWnd->m_environment.m_selectedSymbol = NULL;
}
CMoFields fields = m_pItmInfos[nIndex].rst.GetFields();
pMainWnd->m_environment.m_selectedFeature =
fields.Item(COleVariant("Shape")).GetValue().pdispVal;
pMapView->m_Map.SetExtent(pMapView->m_Map.GetExtent());
return TRUE;
}
//----------------------------------------------------------------------------------------------
int CInfoDlg::GetIndex(CString szName)
{
int nIndex = -1;
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
for (int i = 0; i < pMainWnd->m_environment.m_nLayerNum; i++ )
{
if (m_pItmInfos[i].szName == szName)
{
nIndex = i;
break;
}
}
return nIndex;
}
//----------------------------------------------------------------------------------------------
void CInfoDlg::OnCbnSelchangeInfoCombo()
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
if (m_nIdx != m_FeatureBox.GetCurSel())
{
m_nIdx = m_FeatureBox.GetCurSel();
CString str;
m_FeatureBox.GetLBText(m_nIdx, str);
int nIndex = GetIndex(str);
LoadListBox(nIndex);
}
else
{
CString str;
m_FeatureBox.GetLBText(m_nIdx, str);
int nIndex = GetIndex(str);
CMoFields fields = m_pItmInfos[nIndex].rst.GetFields();
pMapView->m_Map.FlashShape(fields.Item(
COleVariant("Shape")).GetValue().pdispVal, 4);
return;
}
}
//----------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -