?? 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 + -