📄 hawkview.cpp
字号:
// HawkView.cpp : implementation file
//
#include "stdafx.h"
#include "Public_TGIS.h"
#include "HawkView.h"
#include "mainfrm.h"
#include "Environment.h"
#include "AppApi.h"
#include "Public_TGISView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHawkView
IMPLEMENT_DYNCREATE(CHawkView, CFormView)
CHawkView::CHawkView()
: CFormView(CHawkView::IDD)
{
//{{AFX_DATA_INIT(CHawkView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CHawkView::~CHawkView()
{
}
void CHawkView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHawkView)
DDX_Control(pDX, IDC_HAWKMAP, m_HawkMap);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHawkView, CFormView)
//{{AFX_MSG_MAP(CHawkView)
ON_WM_SIZE()
ON_WM_SETFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHawkView diagnostics
#ifdef _DEBUG
void CHawkView::AssertValid() const
{
CFormView::AssertValid();
}
void CHawkView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHawkView message handlers
void CHawkView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_HawkMap.m_hWnd)
{
m_HawkMap.SetWindowPos(0,0,0,cx,cy,SWP_NOZORDER);
}
}
//-----------------------------------------------------------------------------------------
void CHawkView::LoadLayersForEagleEye()
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CEnvironment* environment = &(pMainWnd->m_environment);
// 得到地图中的图层集合
CMoLayers layers(m_HawkMap.GetLayers());
// 清空图层集合,也即删除地图中的所有图层
layers.Clear();
m_HawkMap.SetScrollBars(false);
// 分点、线、多边形3类图层依次加入
for (int i = 0; i < environment->m_nLayerNum; i ++)
{
CMoMapLayer layer;
layer.CreateDispatch(TEXT("MapObjects2.MapLayer"));
// 只加入大类属于北京纵览的图层
if (environment->m_layerInfos[i].szType == "武汉纵览")
{
CMoGeoDataset gds;
gds = environment->m_db.FindGeoDataset(
environment->m_layerInfos[i].szFileName);
layer.SetGeoDataset(gds);
if (layer.GetValid() )
{
if (layer.GetShapeType() == moShapeTypePoint)
continue;
if (layer.GetShapeType() == moShapeTypeLine)
continue;
// 在图层集合中加入当前图层
layers.Add(layer);
layer.GetSymbol().SetOutline(false);
if (environment->m_layerInfos[i].nCharacterIndex >= 0 &&
environment->m_layerInfos[i].nCharacterIndex <= 10)
{
layer.GetSymbol().SetStyle(
(short)environment->m_layerInfos[i].nCharacterIndex);
}
else if (100 == environment->m_layerInfos[i].nCharacterIndex)
{
// 设置多边形图层的颜色
SetPolygonLayerColor(layer, "名称","颜色",false);
}
//设置颜色
if (environment->m_layerInfos[i].nSymColor !=
environment->SYMBOL_COLOR_NONE)
{
layer.GetSymbol().SetColor(
environment->m_layerInfos[i].nSymColor);
}
}
}
}
m_HawkMap.SetExtent(m_HawkMap.GetFullExtent());
}
//--------------------------------------------------------------------------
BEGIN_EVENTSINK_MAP(CHawkView, CFormView)
//{{AFX_EVENTSINK_MAP(CHawkView)
ON_EVENT(CHawkView, IDC_HAWKMAP, 3 /* AfterLayerDraw */, OnAfterLayerDrawHawkmap, VTS_I2 VTS_BOOL VTS_I4)
ON_EVENT(CHawkView, IDC_HAWKMAP, -605 /* MouseDown */, OnMouseDownHawkmap, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
//-----------------------------------------------------------------------------------------
// 在鹰眼地图上绘制一矩形,用于表示当前在地图中显示范围
void CHawkView::OnAfterLayerDrawHawkmap(short index, BOOL canceled, long hDC)
{
// TODO: Add your control notification handler code here
if(index != 0)
return;
// 构造一符号对象
CMoSymbol sym;
sym.CreateDispatch(_T("MapObjects2.Symbol"));
sym.SetOutlineColor(moRed);
sym.SetOutline(TRUE);
sym.SetSymbolType(moFillSymbol);
sym.SetStyle(moTransparentFill);
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
// 利用构建的符号绘制表示地图显示范围的矩形
m_HawkMap.DrawShape(pMapView->m_map.GetExtent(), sym);
FocusOnMain();
}
void CHawkView::OnMouseDownHawkmap(short Button, short Shift, long X, long Y)
{
// TODO: Add your control notification handler code here
// 构建一符号对象
CMoSymbol sym;
sym.CreateDispatch(_T("MapObjects2.Symbol"));
sym.SetOutlineColor(moRed);
sym.SetOutline(TRUE);
sym.SetSymbolType(moFillSymbol);
sym.SetStyle(moTransparentFill);
CMoPoint point;
point = m_HawkMap.ToMapPoint((float)X, (float)Y);
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
// 将地图窗口中的地图的中心点设置为鼠标单击位置处
pMapView->m_map.CenterAt(point.GetX(), point.GetY());
m_HawkMap.SetExtent(m_HawkMap.GetExtent());
FocusOnMain();
}
//-----------------------------------------------------------------------
void CHawkView::FocusOnMain()
{
CMainFrame* pFrame=(CMainFrame*)GetParentFrame();
pFrame->SetActiveView((CView*)(pFrame->m_wndSplitter).GetPane(0,0));
}
void CHawkView::OnSetFocus(CWnd* pOldWnd)
{
CFormView::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
FocusOnMain();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -