?? hawkview.cpp
字號:
// HawkView.cpp : implementation file
//
#include "stdafx.h"
#include "NameGis.h"
#include "HawkView.h"
#include "MapObjects2.h"
#include "mainfrm.h"
#include "Environment.h"
#include "MoGeoDataset.h"
#include "MoLabelPlacer.h"
#include "MapHelper.h"
#include "HawkView.h"
#include "AppApi.h"
#include "NameGisView.h"
// CHawkView
IMPLEMENT_DYNCREATE(CHawkView, CFormView)
CHawkView::CHawkView()
: CFormView(CHawkView::IDD)
{
}
CHawkView::~CHawkView()
{
}
void CHawkView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_HAWKMAP, m_HawkMap);
}
BEGIN_MESSAGE_MAP(CHawkView, CFormView)
ON_WM_SIZE()
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);
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)
ON_EVENT(CHawkView, IDC_HAWKMAP, 3, AfterLayerDrawHawkmap, VTS_I2 VTS_BOOL VTS_I4)
ON_EVENT(CHawkView, IDC_HAWKMAP, DISPID_MOUSEDOWN, MouseDownHawkmap, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
END_EVENTSINK_MAP()
//-----------------------------------------------------------------------------------------
// 在鷹眼地圖上繪制一矩形,用于表示當前在地圖中顯示范圍
void CHawkView::AfterLayerDrawHawkmap(short index, BOOL canceled, long hDC)
{
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();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
// 利用構建的符號繪制表示地圖顯示范圍的矩形
m_HawkMap.DrawShape(pMapView->m_Map.GetExtent(), sym);
}
//-----------------------------------------------------------------------------------------
void CHawkView::MouseDownHawkmap(short Button, short Shift, long X, long Y)
{
// 構建一符號對象
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(X, Y);
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
// 將地圖窗口中的地圖的中心點設置為鼠標單擊位置處
pMapView->m_Map.CenterAt(point.GetX(), point.GetY());
m_HawkMap.SetExtent(m_HawkMap.GetExtent());
}
//-----------------------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -