📄 public_tgisview.cpp
字号:
// Public_TGISView.cpp : implementation of the CPublic_TGISView class
//
#include "stdafx.h"
#include "Public_TGIS.h"
#include "Environment.h"
#include "MainFrm.h"
#include "AppApi.h"
#include "HawkView.h"
#include "Crack.h"
#include "Public_TGISDoc.h"
#include "Public_TGISView.h"
#include "MapControlView.h"
#include "NameQuryDlg.h"
#include "NameIndexDlg.h"
#include "BusQueryDlg.h"
#include "mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPublic_TGISView
IMPLEMENT_DYNCREATE(CPublic_TGISView, CFormView)
BEGIN_MESSAGE_MAP(CPublic_TGISView, CFormView)
//{{AFX_MSG_MAP(CPublic_TGISView)
ON_WM_SIZE()
ON_UPDATE_COMMAND_UI(ID_FEATURE_ALL, OnUpdateAllFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_GOV, OnUpdateGovFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_SHOP, OnUpdateShopFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_TOUR, OnUpdateTourFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_SCHOOL, OnUpdateSchoolFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_HOSPITAL, OnUpdateHospitalFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_HOTEL, OnUpdateHotelFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_BANK, OnUpdateBankFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_POST, OnUpdatePostFtr)
ON_UPDATE_COMMAND_UI(ID_FEATURE_BUS, OnUpdateBusStaFtr)
ON_COMMAND(ID_FEATURE_ALL, OnShowAllFeature)
ON_COMMAND(ID_FEATURE_SHOP, OnShowShopFeature)
ON_COMMAND(ID_FEATURE_TOUR, OnShowTourFeature)
ON_COMMAND(ID_FEATURE_SCHOOL, OnShowSchoolFeature)
ON_COMMAND(ID_FEATURE_HOSPITAL, OnShowHospitalFeature)
ON_COMMAND(ID_FEATURE_HOTEL, OnShowHotelFeature)
ON_COMMAND(ID_FEATURE_BANK, OnShowBankFeature)
ON_COMMAND(ID_FEATURE_GOV, OnShowGovFeature)
ON_COMMAND(ID_FEATURE_POST, OnShowPostFeature)
ON_COMMAND(ID_FEATURE_BUS, OnShowBusStationFeature)
ON_COMMAND(ID_MAP_LINEMEASURE, OnMapLinemearsure)
ON_COMMAND(ID_MAP_ZOOMIN, OnZoomIn)
ON_COMMAND(ID_MAP_ZOOMOUT, OnZoomOut)
ON_COMMAND(ID_MAP_FULLEXTENT, OnFullExtent)
ON_COMMAND(ID_MAP_PAN, OnPanMap)
ON_UPDATE_COMMAND_UI(ID_MAP_ZOOMIN, OnUpdateZoomIn)
ON_UPDATE_COMMAND_UI(ID_MAP_ZOOMOUT, OnUpdateZoomOut)
ON_UPDATE_COMMAND_UI(ID_MAP_PAN, OnUpdatePanMap)
ON_COMMAND(ID_MAP_POINTSEL, OnPointSelect)
ON_COMMAND(ID_MAP_RECTSEL, OnRectSelect)
ON_COMMAND(ID_MAP_POLYSEL, OnPolySelect)
ON_UPDATE_COMMAND_UI(ID_MAP_POINTSEL, OnUpdatePointSel)
ON_UPDATE_COMMAND_UI(ID_MAP_RECTSEL, OnUpdateRectSel)
ON_UPDATE_COMMAND_UI(ID_MAP_POLYSEL, OnUpdatePolySel)
ON_COMMAND(ID_MAP_INFO, OnMapInfo)
ON_UPDATE_COMMAND_UI(ID_MAP_INFO, OnUpdateMapInfo)
ON_COMMAND(ID_MAP_NAMEQUERY, OnNameQuery)
ON_COMMAND(ID_MAP_NEARESTNAME, OnNearestName)
ON_COMMAND(ID_MAP_NAMEINDEX, OnMapNameindex)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_UPDATE_COMMAND_UI(ID_MAP_LINEMEASURE, OnUpdateMapLinemearsure)
ON_COMMAND(ID_MAP_AREAMEASURE, OnMapAreameasure)
ON_UPDATE_COMMAND_UI(ID_MAP_AREAMEASURE, OnUpdateMapAreameasure)
ON_COMMAND(ID_MAP_OUTPUT, OnMapOutput)
ON_COMMAND(ID_MAP_PRINT, OnMapPrint)
ON_COMMAND(ID_MAP_HELP, OnMapHelp)
ON_WM_MOUSEWHEEL()
ON_COMMAND(ID_BUTTON32805, OnButton32805)
ON_COMMAND(ID_BUTTON32806, OnButton32806)
ON_COMMAND(ID_MAP_MUSIC, OnMapMusic)
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPublic_TGISView construction/destruction
CPublic_TGISView::CPublic_TGISView()
: CFormView(CPublic_TGISView::IDD)
{
//{{AFX_DATA_INIT(CPublic_TGISView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
m_nCurTool = ID_MAP_PAN;
m_pInfoDlg = NULL;
m_pNearestDlg = NULL;
}
CPublic_TGISView::~CPublic_TGISView()
{
if(m_pInfoDlg)
{
delete m_pInfoDlg;
m_pInfoDlg = NULL;
}
}
void CPublic_TGISView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPublic_TGISView)
DDX_Control(pDX, IDC_MAPTIP_STATIC, m_NameLabel);
DDX_Control(pDX, IDC_MAP1, m_map);
//}}AFX_DATA_MAP
}
BOOL CPublic_TGISView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
OnMapMusic();
return CFormView::PreCreateWindow(cs);
}
void CPublic_TGISView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CPublic_TGISView printing
BOOL CPublic_TGISView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPublic_TGISView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPublic_TGISView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CPublic_TGISView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CPublic_TGISView diagnostics
#ifdef _DEBUG
void CPublic_TGISView::AssertValid() const
{
CFormView::AssertValid();
}
void CPublic_TGISView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CPublic_TGISDoc* CPublic_TGISView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPublic_TGISDoc)));
return (CPublic_TGISDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPublic_TGISView message handlers
void CPublic_TGISView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_map.m_hWnd)
{
m_map.SetWindowPos(0,0,0,cx,cy,SWP_NOZORDER);
}
}
///////////////////////////////////////////////////////////////////////////////
//function: load layers
//para: none
//return: void
void CPublic_TGISView::LoadLayers()
{
CEnvironment* environment = &(((CMainFrame*)AfxGetMainWnd())->m_environment);
// 得到地图包含的图层集
CMoLayers layers(m_map.GetLayers());
// 清空图层集
layers.Clear();
m_map.SetScrollBars(false);
if(!environment->m_db.CreateDispatch(TEXT("MapObjects2.DataConnection")))
throw "unable to create MapObjects2.DataConnection";
environment->m_db.SetDatabase(environment->m_szSDBPath);
if (!environment->m_db.Connect())
throw "unable to connect to database";
// 分点、线、多边形3类图层分别依次加入
for (int m = 0; m < 3; m ++)
{
for (int i = 0; i < environment->m_nLayerNum; i ++)
{
CMoMapLayer layer;
// 创建图层对象接口
layer.CreateDispatch(TEXT("MapObjects2.MapLayer"));
CMoGeoDataset gds;
// 通过FindGeoDataset方法得到指定名称的数据集
gds = environment->m_db.FindGeoDataset(environment->m_layerInfos[i].szFileName);
// 设置图层的数据集
layer.SetGeoDataset(gds);
if (layer.GetValid())
{
switch (m)
{
case 0:
if (layer.GetShapeType() != 23) //moShapeTypePolygon
continue;
break;
case 1:
if (layer.GetShapeType() != 22) //moShapeTypeLine)
continue;
break;
case 2:
if (layer.GetShapeType() != 21) //moShapeTypePoint
continue;
break;
default:
continue;
}
environment->m_layerInfos[i].layer = layer;
// 在图层集(即地图)中加入该图层
layers.Add(environment->m_layerInfos[i].layer);
//设置图层是否显示
if (!environment->m_layerInfos[i].bVisible)
environment->m_layerInfos[i].layer.SetVisible(false);
//设置注记
if (environment->m_layerInfos[i].bLable
&& (environment->CalcScale(&m_map) < environment->m_layerInfos[i].dScale))
{
CMoLabelPlacer myRD;
myRD.CreateDispatch(TEXT("MapObjects2.LabelPlacer"));
myRD.SetField("名称");
myRD.SetDrawBackground(environment->m_layerInfos[i].bBackground);
myRD.SetAllowDuplicates(false);
myRD.SetMaskLabels(false);
if (environment->m_layerInfos[i].layer.GetShapeType() == 22) //moShapeTypeLine
myRD.SetPlaceAbove(true);
else
myRD.SetPlaceAbove(false);
myRD.SetPlaceOn(true);
CMoFont fnt;
// 类似于CreateDispatch
fnt.InitializeFont();
fnt.SetName(TEXT(((CMainFrame*)AfxGetMainWnd())->FONTNAME));
fnt.SetSize(environment->m_layerInfos[i].nFontSize);
// 设置默认的符号
myRD.GetDefaultSymbol().SetFont(fnt);
environment->m_layerInfos[i].layer.SetRenderer(myRD);
}
//设置符号
switch (environment->m_layerInfos[i].layer.GetShapeType())
{
case 21: // moShapeTypePoint
//点符号
if (environment->m_layerInfos[i].nCharacterIndex >= 0 )
{
CMoFont fnt;
fnt.InitializeFont();
fnt.SetName(environment->m_layerInfos[i].szFontName);
environment->m_layerInfos[i].layer.GetSymbol().SetFont(fnt);
environment->m_layerInfos[i].layer.GetSymbol().SetCharacterIndex(
(short)environment->m_layerInfos[i].nCharacterIndex);
environment->m_layerInfos[i].layer.GetSymbol().SetStyle(4);
environment->m_layerInfos[i].layer.GetSymbol().SetSymbolType(0); // moPointSymbol;
environment->m_layerInfos[i].layer.GetSymbol().SetSize(
(short)environment->m_layerInfos[i].nSymSize);
}
else
{
environment->m_layerInfos[i].layer.GetSymbol().SetSize(
(short)environment->m_layerInfos[i].nSymSize);
}
break;
case 22: // moShapeTypeLine
//线符号
if (environment->m_layerInfos[i].nCharacterIndex >= 0
&& environment->m_layerInfos[i].nCharacterIndex < 5)
{
environment->m_layerInfos[i].layer.GetSymbol().SetStyle(
(short)environment->m_layerInfos[i].nCharacterIndex);
}
environment->m_layerInfos[i].layer.GetSymbol().SetSize(
(short)environment->m_layerInfos[i].nSymSize);
break;
case 23: // moShapeTypePolygon
environment->m_layerInfos[i].layer.GetSymbol().SetOutline(false);
if (environment->m_layerInfos[i].nCharacterIndex >= 0
&& environment->m_layerInfos[i].nCharacterIndex <= 10)
{
environment->m_layerInfos[i].layer.GetSymbol().SetStyle(
(short)environment->m_layerInfos[i].nCharacterIndex);
}
else if (100 == environment->m_layerInfos[i].nCharacterIndex)
{
SetPolygonLayerColor(environment->m_layerInfos[i].layer,
"名称","颜色",false);
}
break;
}
//设置颜色
if (environment->m_layerInfos[i].nSymColor != environment->SYMBOL_COLOR_NONE)
{
environment->m_layerInfos[i].layer.GetSymbol().SetColor(
environment->m_layerInfos[i].nSymColor);
}
}
}
}
m_map.SetMousePointer(moPan);
/* // 装载额外图层
// 关于最短路经的图层
m_netLayer.CreateDispatch(_T("MapObjects2.MapLayer"));
m_netLayer.SetGeoDataset(environment->m_db.FindGeoDataset("street"));
m_netLayer.SetVisible(FALSE);
m_map.GetLayers().Add(m_netLayer);
*/
}
/////////////////////////////////////////////////////////////////////////////////
///
// 功能:根据每个图层的显示比例而设置图层是否显示
void CPublic_TGISView::ReShowLayers()
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CEnvironment* environment = &(pMainWnd->m_environment);
double dScale = environment->CalcScale(&m_map); //地图显示比例
for (int i = 0; i < environment->m_nLayerNum; i ++)
{
if (!environment->m_layerInfos[i].bVisible)
continue;
if (dScale < environment->m_layerInfos[i].dShowScale)
{
environment->m_layerInfos[i].layer.SetVisible(true);
}
else
{
environment->m_layerInfos[i].layer.SetVisible(false);
}
}
}
//----------------------------------------------------------------------
//调整地物控制工具栏按钮的状态
void CPublic_TGISView::OnUpdateAllFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CEnvironment* environment = &(pMainWnd->m_environment);
if (environment->GetLayerVisible(MO_HOSPITAL ) &&
environment->GetLayerVisible(MO_HOTEL ) &&
environment->GetLayerVisible(MO_POST ) &&
environment->GetLayerVisible(MO_SCHOOL ) &&
environment->GetLayerVisible(MO_BUSSTATION ) &&
environment->GetLayerVisible(MO_SHOP ) &&
environment->GetLayerVisible(MO_TOUR ) &&
environment->GetLayerVisible(MO_GOV ) &&
environment->GetLayerVisible(MO_BANK ))
{
// 如果所有地物类型都可见,则设置为按下状态
pCmdUI->SetCheck(TRUE);
}
else
{
pCmdUI->SetCheck(FALSE);
}
}
//------------------------------------------------------------------------------
void CPublic_TGISView::OnUpdateShopFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (pMainWnd->m_environment.GetLayerVisible(MO_SHOP))
// 如果商店地物可见,则设置按钮为按下状态
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
//--------------------------------------------------------------------------
void CPublic_TGISView::OnUpdateTourFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (pMainWnd->m_environment.GetLayerVisible(MO_TOUR))
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
//----------------------------------------------------------------------------
void CPublic_TGISView::OnUpdateSchoolFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (pMainWnd->m_environment.GetLayerVisible(MO_SCHOOL))
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
//--------------------------------------------------------------------------
void CPublic_TGISView::OnUpdateHospitalFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (pMainWnd->m_environment.GetLayerVisible(MO_HOSPITAL))
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}
//------------------------------------------------------------------------
void CPublic_TGISView::OnUpdateHotelFtr(CCmdUI* pCmdUI)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (pMainWnd->m_environment.GetLayerVisible(MO_HOTEL))
pCmdUI->SetCheck(TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -