📄 firstmapview.cpp
字号:
// FirstMapView.cpp : implementation of the CFirstMapView class
//
#include "stdafx.h"
#include "FirstMap.h"
#include "_scalebar.h"
#include "_sbextent.h"
#include "FirstMapDoc.h"
#include "FirstMapView.h"
#include "MainFrm.h"
#include "modataconnection.h"
#include "molayers.h"
#include "momaplayer.h"
#include "mogeodataset.h"
#include "mosymbol.h"
#include "morectangle.h"
#include "mopoint.h"
#include "mostandardizer.h"
#include "MoGroupRenderer.h"
#include "moline.h"
#include "mopolygon.h"
#include "molabelplacer.h"
#include "motabledesc.h"
#include "mofields.h"
#include "mofield.h"
#include "mostrings.h"
#include "mostatistics.h"
#include "movaluemaprenderer.h"
#include "motrackinglayer.h"
#include "motextsymbol.h"
#include "molabelrenderer.h"
#include "moellipse.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFirstMapView
IMPLEMENT_DYNCREATE(CFirstMapView, CFormView)
BEGIN_MESSAGE_MAP(CFirstMapView, CFormView)
//{{AFX_MSG_MAP(CFirstMapView)
ON_WM_SIZE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND_RANGE(ID_MAP_ZOOMIN, ID_SELECT_FEATURE , OnMapTool)
ON_UPDATE_COMMAND_UI_RANGE(ID_MAP_ZOOMIN, ID_SELECT_FEATURE , OnUpdateMapTool)
ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
ON_NOTIFY(NM_RCLICK, IDC_LIST2, OnRclickList2)
ON_COMMAND(ID_MENU_REMOVEALL, OnMenuRemoveall)
ON_COMMAND(ID_MENU_REMOVE, OnMenuRemove)
ON_COMMAND(ID_TURN_ON, OnTurnOn)
ON_COMMAND(ID_TURN_OFF, OnTurnOff)
ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST2, OnBegindragList2)
ON_COMMAND(ID_BUTTON_UP, OnButtonUp)
ON_COMMAND(ID_BUTTON_DOWN, OnButtonDown)
ON_COMMAND(ID_UP_TOP, OnUpTop)
ON_COMMAND(ID_DOWN_BOTTOM, OnDownBottom)
ON_COMMAND(ID_SCALE_WIND, OnScaleWind)
ON_COMMAND(ID_QUERY_POINT, OnQueryPoint)
ON_COMMAND(ID_QUERY_ELLIPSE, OnQueryEllipse)
ON_COMMAND(ID_QUERY_POLYGON, OnQueryPolygon)
ON_COMMAND(ID_QUERY_RECTANGLE, OnQueryRectangle)
ON_BN_CLICKED(IDC_SEARCH, OnMapSearch)
ON_CBN_CLOSEUP(IDC_COMBO_CURRENTLAYER, OnCloseupCombo)
ON_BN_CLICKED(IDC_BTN_SCALE, OnBtnScale)
ON_COMMAND(ID_MAP_FULLEXTENT, OnMapFullextent)
ON_COMMAND(ID_SHOW_PROPERY, OnShowPropery)
ON_COMMAND(ID_DELETE_LABAL, OnDeleteLabal)
ON_COMMAND(ID_PRO_TABLE, OnProTable)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CFirstMapView construction/destruction
CFirstMapView::CFirstMapView()
: CFormView(CFirstMapView::IDD)
{
//{{AFX_DATA_INIT(CFirstMapView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
this->m_nCurTool = ID_MAP_FULLEXTENT;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
this->index = 0;
for(int i=0;i<20;i++)
this->PathName[i] = "";
index_seled = -1;
this->m_firstStart = TRUE;
this->m_RefreshOriginalRect = FALSE;
// this->tLayer = m_map.GetTrackingLayer();
scale_index = -1;
this->m_multList = new CDlgMultList;
m_dlglist=new CDlgList;
}
CFirstMapView::~CFirstMapView()
{
}
void CFirstMapView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFirstMapView)
DDX_Control(pDX, IDC_LIST2, m_list);
DDX_Control(pDX, IDC_MAP1, m_map);
DDX_Control(pDX, IDC_MAP2, m_map2);
DDX_Control(pDX, IDC_SCALEBAR, m_scaleBar);
//}}AFX_DATA_MAP
}
BOOL CFirstMapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CFirstMapView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
DWORD dwStyle;
dwStyle = this->m_list.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES ;
m_list.SetExtendedStyle(dwStyle);
}
/////////////////////////////////////////////////////////////////////////////
// CFirstMapView printing
BOOL CFirstMapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFirstMapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFirstMapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CFirstMapView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CFirstMapView diagnostics
#ifdef _DEBUG
void CFirstMapView::AssertValid() const
{
CFormView::AssertValid();
}
void CFirstMapView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFirstMapDoc* CFirstMapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFirstMapDoc)));
return (CFirstMapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFirstMapView message handlers
void CFirstMapView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
this->width = cx;
this->height = cy;
if(this->m_map.m_hWnd)
{
m_list.SetWindowPos(0,0,0,175,475,SWP_NOZORDER);
m_map.SetWindowPos(0,178,0,cx-178,cy,SWP_NOZORDER);
m_scaleBar.SetWindowPos(0,cx-270,cy-73,250,70,SWP_NOZORDER);
m_map2.SetWindowPos(0,0,478,175,cy-478,SWP_NOZORDER);
}
}
CString CFirstMapView::AddShpLayer(const CString &path, COLORREF color, short symbolSize, short symbolStyle)
{
CMoMapLayer layer;
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection"))) return "";
conn.SetDatabase(GetFileDirectory(path));
if (!conn.Connect()) return "";
// Add layer specified by path
layers=m_map.GetLayers();
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer"))) return "";
CString LayerName = GetFileTitle(path);
CMoGeoDataset geoDataset=conn.FindGeoDataset(LayerName);
if(!geoDataset) return "";
layer.SetGeoDataset(geoDataset);
CMoSymbol layerSymbol(layer.GetSymbol());
if (color != -1) layerSymbol.SetColor(color); // Set color if specified
layerSymbol.SetSize(symbolSize);
layerSymbol.SetStyle(symbolStyle);
layers.Add(layer);
OnSetNavigationViewMapLayer();
this->m_firstStart = FALSE;
return(layer.GetName());
}
CString CFirstMapView::GetFileDirectory(const CString &path)
{
int pos = path.ReverseFind('\\');
if(pos>=0) return path.Left(pos);
return "";
}
CString CFirstMapView::GetFileTitle(const CString &path)
{
CString strResult = GetFileName(path);
int pos = strResult.ReverseFind('.');
if(pos>=0)
return strResult.Left(pos);
return strResult;
}
CString CFirstMapView::GetFileName(const CString &path)
{
int pos = path.ReverseFind('\\');
if(pos>=0)
return path.Right(path.GetLength()-pos-1);
return path;
}
void CFirstMapView::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrTitle = "Add Data";
dlg.m_ofn.lpstrFilter = "Shape Filse (*.shp)\0*.shp\0Datasets and Layers (*.lyr)\0*.lyr\0All Files (*.*)\0*.*\0\0";
dlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT; //可以同时添加多个数据层
if(dlg.DoModal()==IDOK)
{
POSITION pos;
pos = dlg.GetStartPosition();
while(pos)
{
PathName[index] = dlg.GetNextPathName(pos);
this->AddShpLayer(PathName[index],RGB(0,255,0), 0, 0);
PathName[index] = GetFileTitle(PathName[index]);
index++;
}
//得到框架窗口中CCOMBOX控件指针
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
ASSERT_VALID(pMainFrame);
CComboBox *pComboBox = (CComboBox*)pMainFrame->m_wndSearch.GetDlgItem(IDC_COMBO_CURRENTLAYER);
ASSERT_VALID(pComboBox);
int j =index-1;
m_list.DeleteAllItems();
while(pComboBox->GetCount()!=0)
pComboBox->DeleteString(0);
for(int i=0;j>=0;i++)
{
lvitem.iItem = i;
m_list.InsertItem(&lvitem);
m_list.SetItemState (i,0x2000, LVIS_STATEIMAGEMASK);
m_list.SetItemText(i,0,PathName[j]);
//在工具栏的Combox中动态添加图层名
pComboBox->AddString(PathName[j]);
pComboBox->SetCurSel(0);
j--;
}
}
}
void CFirstMapView::OnMapTool(UINT nID)
{
// TODO: Add your command handler code here
this->m_nCurTool = nID;
}
void CFirstMapView::OnUpdateMapTool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurTool);
}
BEGIN_EVENTSINK_MAP(CFirstMapView, CFormView)
//{{AFX_EVENTSINK_MAP(CFirstMapView)
ON_EVENT(CFirstMapView, IDC_MAP1, -605 /* MouseDown */, OnMouseDownMap1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
ON_EVENT(CFirstMapView, IDC_MAP2, -605 /* MouseDown */, OnMouseDownMap2, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
ON_EVENT(CFirstMapView, IDC_MAP2, -606 /* MouseMove */, OnMouseMoveMap2, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
ON_EVENT(CFirstMapView, IDC_MAP2, -607 /* MouseUp */, OnMouseUpMap2, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
ON_EVENT(CFirstMapView, IDC_MAP2, 4 /* AfterTrackingLayerDraw */, OnAfterTrackingLayerDrawMap2, VTS_I4)
ON_EVENT(CFirstMapView, IDC_MAP1, 4 /* AfterTrackingLayerDraw */, OnAfterTrackingLayerDrawMap1, VTS_I4)
ON_EVENT(CFirstMapView, IDC_SCALEBAR, 3 /* DblClick */, OnDblClickScalebar, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CFirstMapView::OnMouseDownMap1(short Button, short Shift, long X, long Y)
{
// TODO: Add your control notification handler code here
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
ASSERT_VALID(pMainFrame);
CComboBox *pComboBox1 = (CComboBox*)pMainFrame->m_wndSearch.GetDlgItem(IDC_COMBO_CURRENTLAYER);
ASSERT_VALID(pComboBox1);
pComboBox1->GetWindowText(m_comboxEdit);
switch (this->m_nCurTool)
{
case ID_MAP_ZOOMIN:
{
m_map.SetMousePointer(51);
CMoRectangle r1(m_map.GetExtent());
r1.ScaleRectangle(0.5);
m_map.SetExtent(r1);
CMoRectangle r2(m_map.TrackRectangle());
if(LPDISPATCH(r2))
m_map.SetExtent(r2);
OnRefreshNavigationWindow();
break;
}
case ID_MAP_ZOOMOUT:
{
m_map.SetMousePointer(52);
CMoRectangle r1(m_map.GetExtent());
r1.ScaleRectangle(1.5);
m_map.SetExtent(r1);
CMoRectangle r2(m_map.TrackRectangle());
r2 = m_map.GetExtent();
m_map.SetExtent(r2);
OnRefreshNavigationWindow();
break;
}
case ID_MAP_PAN:
{
m_map.SetMousePointer(54);
// m_map.SetMousePointer(13); 漏斗型
// m_map.SetMousePointer(3); 光标型
// m_map.SetMousePointer(2); 十字
// m_map.SetMousePointer(4); 箭头
// m_map.SetMousePointer(14); 问号
m_map.Pan();
OnRefreshNavigationWindow();
break;
}
case ID_NOMAL:
{
m_map.SetMousePointer(0);
OnRefreshNavigationWindow();
break;
}
case ID_QUERY_POINT:
{
m_map.SetMousePointer(55);
if(m_comboxEdit !="")
{
m_CurrentOperation = Query_Point;
if(m_CurrentOperation == Query_Point && Button ==1)
{
//* * 1 获得查询范围
CMoPoint pt(m_map.ToMapPoint((float)X,(float)Y));
CMoRectangle select_Rect;
if(! select_Rect.CreateDispatch("MapObjects2.Rectangle"))
return;
double x = pt.GetX();
double y = pt.GetY();
CMoRectangle rect_Extent(m_map.GetExtent());
double X_Scale;
double Y_Scale;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -