⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapdemoview.cpp

📁 不错的东西
💻 CPP
字号:
// MapDemoView.cpp : implementation of the CMapDemoView class
//

#include "stdafx.h"
#include "MapDemo.h"
#include "MainFrm.h"
#include "MapDemoDoc.h"
#include "morecordset.h"
#include "MapDemoView.h"
#include "mopoint.h"
#include "Mohelp.h"
#include "morectangle.h"
#include "map.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMapDemoView

IMPLEMENT_DYNCREATE(CMapDemoView, CFormView)

BEGIN_MESSAGE_MAP(CMapDemoView, CFormView)
	//{{AFX_MSG_MAP(CMapDemoView)
	ON_COMMAND(ID_ZOOMIN, OnZoomin)
	ON_COMMAND(ID_ZOOMOUT, OnZoomout)
	ON_COMMAND(ID_PAN, OnPan)
	ON_COMMAND(ID_NORMAL, OnNormal)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_WM_SIZE()
	ON_COMMAND(ID_MAP_QUERY, OnMapQuery)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMapDemoView construction/destruction

CMapDemoView::CMapDemoView()
	: CFormView(CMapDemoView::IDD)
{
	//{{AFX_DATA_INIT(CMapDemoView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMapDemoView::~CMapDemoView()
{
}

void CMapDemoView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMapDemoView)
	DDX_Control(pDX, IDC_MAP1, m_map);
	DDX_Control(pDX, IDC_MAP2, m_map1);
	//}}AFX_DATA_MAP
}

BOOL CMapDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CMapDemoView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CMapDemoView printing

BOOL CMapDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMapDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMapDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CMapDemoView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CMapDemoView diagnostics

#ifdef _DEBUG
void CMapDemoView::AssertValid() const
{
	CFormView::AssertValid();
}

void CMapDemoView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CMapDemoDoc* CMapDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapDemoDoc)));
	return (CMapDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMapDemoView message handlers

void CMapDemoView::OnZoomin() 
{
	// TODO: Add your command handler code here
	m_CurrentOperation=ZOOMIN;
	m_map.SetMousePointer(51);//设置鼠标形状
}

void CMapDemoView::OnZoomout() 
{
	// TODO: Add your command handler code here
  m_CurrentOperation=ZOOMOUT;
  m_map.SetMousePointer(52);
}

void CMapDemoView::OnPan() 
{
	// TODO: Add your command handler code here
	m_CurrentOperation=PAN;
	m_map.SetMousePointer(53);
}

void CMapDemoView::OnNormal() 
{
	// TODO: Add your command handler code here
	m_CurrentOperation=NORMAL;
    m_map.SetMousePointer(54);
}

BEGIN_EVENTSINK_MAP(CMapDemoView, CFormView)
    //{{AFX_EVENTSINK_MAP(CMapDemoView)
	ON_EVENT(CMapDemoView, IDC_MAP1, -605 /* MouseDown */, OnMouseDownMap1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMapDemoView::OnMouseDownMap1(short Button, short Shift, long X, long Y) 
{
	// TODO: Add your control notification handler code here
	 SetCapture();//俘获鼠标,一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口
	 //放大部分............
	if(m_CurrentOperation==ZOOMIN)
	{
		double m_TrackRectangle_Height;
		double m_TrackRectangle_Width;
		CMoRectangle rect(m_map.TrackRectangle());//CMoRectangle记录通过鼠标采集的矩形
		//TrackRectangle返回由鼠标生成的多边形
        m_TrackRectangle_Height=rect.GetHeight();
        m_TrackRectangle_Width=rect.GetWidth();
        if(LPDISPATCH(rect)&&m_TrackRectangle_Height!=0&&m_TrackRectangle_Width!=0)
			m_map.SetExtent(rect);//用于设置当前地图的显示范围
        else
		{
			CMoPoint m_CenterPoint;//CMoPoint用于表示地图上的一个点状几何图形的坐标
			m_CenterPoint=m_map.ToMapPoint(float(X),float(Y));//ToMapPoint用于将某点的屏幕坐标转为空间坐标
			double m_CenterPointX;
			double m_CenterPointY;
            m_CenterPointX=m_CenterPoint.GetX();
            m_CenterPointY=m_CenterPoint.GetY();
            CMoRectangle rect_Extent(m_map.GetExtent());//用于获得当前地图的显示范围
            rect_Extent.ScaleRectangle(0.5);
			m_map.SetExtent(rect_Extent);
			m_map.CenterAt(m_CenterPointX,m_CenterPointY);//将当前图幅以指定点为中间进行显示
		}
	}
	//缩小部分............
	else if(m_CurrentOperation==ZOOMOUT)
	{
        CMoPoint m_CenterPoint;
		CMoRectangle rect_Mouse(m_map.TrackRectangle());
        CMoRectangle rect_Extent;
        rect_Extent=m_map.GetExtent();
		double m_CenterPointX;
		double m_CenterPointY;
		if(LPDISPATCH(rect_Mouse)&& rect_Mouse.GetHeight!=0&&rect_Mouse.GetWidth!=0)
		{
			m_CenterPoint=rect_Mouse.GetCenter();
            m_CenterPointX=m_CenterPoint.GetX();
			m_CenterPointY=m_CenterPoint.GetY();///获得妆前定点的坐标
			double X_Scale;
			double Y_Scale;
			X_Scale=rect_Extent.GetHeight()/rect_Mouse.GetHeight();
			Y_Scale=rect_Extent.GetWidth()/rect_Mouse.GetWidth();
			double m_Scale=X_Scale;
			if(X_Scale<Y_Scale)
				m_Scale=Y_Scale;
			rect_Extent.ScaleRectangle(m_Scale);
		}
		else
		{
			m_CenterPoint=m_map.ToMapPoint(float(X),float(Y));
			m_CenterPointX=m_CenterPoint.GetX();
;			m_CenterPointY=m_CenterPoint.GetY();
			rect_Extent.ScaleRectangle(2);
		}
		m_map.SetExtent(rect_Extent);
		m_map.CenterAt(m_CenterPointX,m_CenterPointY);
	}
	else if(m_CurrentOperation==PAN)
	{
		m_map.Pan();//漫游功能
	}
	else if(m_CurrentOperation==NORMAL)
	{
		CMoRectangle r(m_map.GetFullExtent());//获得当前图幅的显示范围
	    m_map.SetExtent(r);
	}
	else
	{
	  ;
	}
     	ReleaseCapture();//
}

void CMapDemoView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CFileDialog dialog(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Chart Files (*.shp)|*.shp||",NULL);
	
	if(dialog.DoModal() == IDOK)
	{
		CString path =dialog.GetPathName();
        AddLayer(m_map,path,RGB(255,0,0),NULL);
		AddLayer(m_map1,path,RGB(0,255,0),NULL);
	}
}

void CMapDemoView::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);
}

void CMapDemoView::OnMapQuery() 
{
	// TODO: Add your command handler code here
	CString searchText="上海ds";
	CString expression;
	expression.Format("(NAME LiKe '%%%s%%')",searchText);
	CMoLayers layers(m_map.GetLayers());
	CMoMapLayer states(layers.Item(COleVariant(TEXT("bou2_4p"))));
    CMoRecordset recs(states.SearchExpression(expression));
	if(recs.GetEof())
		MessageBox("没有找到您输入的地名,请重新核对!","提示",0);
	else
	{
	    CMoFields fields(recs.GetFields());
        CMoField shapeField(fields.Item(COleVariant(TEXT("shape"))));
		CMoPolygon shape(shapeField.GetValue().pdispVal);
		CMoRectangle r(shape.GetExtent());
		r.ScaleRectangle(15);
		m_map.SetExtent(r);
		m_map.Refresh();
		m_map.FlashShape(shape,10);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -