📄 eagleviewview.cpp
字号:
// EagleViewView.cpp : implementation of the CEagleViewView class
//
#include "stdafx.h"
#include "EagleView.h"
#include "EagleViewDoc.h"
#include "EagleViewView.h"
#include "EagleWnd.h"
#include "MainFrm.h"
#include "DialogMain.h"
#include "DialogNormalCity.h"
#include "DialogRout.h"
#include "DemoDialog.h"
#include "InfoWnd.h"
#include "DialogDisplay.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEagleWnd* CEagleMap;
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView
IMPLEMENT_DYNCREATE(CEagleViewView, CView)
BEGIN_MESSAGE_MAP(CEagleViewView, CView)
//{{AFX_MSG_MAP(CEagleViewView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_COMMAND(IDC_ENTIRE_MAP, OnEntireMap)
ON_COMMAND(IDC_MAP_TOOL_ARROW, OnMapToolArrow)
ON_COMMAND(IDC_ZOOMIN, OnZoomin)
ON_COMMAND(IDC_ZOOMOUT, OnZoomout)
ON_COMMAND(IDC_PAN, OnPan)
ON_COMMAND(IDC_MAP_TOOL_CENTER, OnMapToolCenter)
ON_COMMAND(IDC_MAP_TOOL_SELECT, OnMapToolSelect)
ON_COMMAND(IDC_MAP_TOOL_RADIUSSELECT, OnMapToolRadiusselect)
ON_COMMAND(IDC_MAP_TOOL_RECTANGLESELECT, OnMapToolRectangleselect)
ON_COMMAND(IDC_MAP_PROPERTIES, OnMapProperties)
ON_COMMAND(IDC_MAP_LAYERCONTROL, OnMapLayercontrol)
ON_COMMAND(IDC_INFO, OnInfo)
ON_COMMAND(IDC_LONGTHTEST, OnLongthtest)
ON_COMMAND(IDC_DATA_MAINCITY, OnDataMaincity)
ON_COMMAND(IDC_DATA_NORMALCITY, OnDataNormalcity)
ON_COMMAND(IDC_DATA_ROUT, OnDataRout)
ON_COMMAND(IDC_DEMO, OnDemo)
ON_COMMAND(IDC_START, OnStart)
ON_COMMAND(IDC_STOP, OnStop)
ON_WM_TIMER()
ON_COMMAND(IDC_DISPLAY, OnDisplay)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView construction/destruction
CEagleViewView::CEagleViewView()
{
// TODO: add construction code here
TNum=0;
count=0;
FlashOn=FALSE;
m_PolyLongth=FALSE;
m_Num=0;
}
CEagleViewView::~CEagleViewView()
{
_ConnectionPtr m_pConnect0;
HRESULT hr;
try
{
hr = m_pConnect0.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = m_pConnect0->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
}
}catch(_com_error e)
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
for(int i=0;i<TNum;i++)
{
CString strNum;
strNum.Format("%d",i);
_bstr_t strSQL="drop table 轨迹"+strNum;
m_pConnect0->Execute(strSQL,NULL,adCmdText);
}
_bstr_t strSQL1="delete 轨迹";
_bstr_t strSQL2="delete 短信";
m_pConnect0->Execute(strSQL1,NULL,adCmdText);
m_pConnect0->Execute(strSQL2,NULL,adCmdText);
m_pConnect0->Close();
}
BOOL CEagleViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView drawing
void CEagleViewView::OnDraw(CDC* pDC)
{
CEagleViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView printing
BOOL CEagleViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEagleViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEagleViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView diagnostics
#ifdef _DEBUG
void CEagleViewView::AssertValid() const
{
CView::AssertValid();
}
void CEagleViewView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEagleViewDoc* CEagleViewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEagleViewDoc)));
return (CEagleViewDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView message handlers
BEGIN_EVENTSINK_MAP(CEagleViewView, CView)
//{{AFX_EVENTSINK_MAP(CXXXView)
ON_EVENT(CEagleViewView, IDC_MAINMAP, 6 /* MapViewChanged */, OnMapViewChangedMap, VTS_NONE)
ON_EVENT(CEagleViewView, IDC_MAINMAP, DISPID_MOUSEMOVE, OnMouseMoveInMap,VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
ON_EVENT(CEagleViewView, IDC_MAINMAP, MAPX_DISPID_POLYTOOLUSED, OnPolyToolUsedMap, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CEagleViewView::OnMapViewChangedMap()
{
//My Sample On_Event_Function
count++;
if(count>5)
{
CMapXRectangle rect;
rect.CreateDispatch(rect.GetClsid());
//m_mainmap.GetClientRect(rect);
rect=m_mainmap.GetBounds();
double X1=rect.GetXMin();
double X2=rect.GetXMax();
double Y1=rect.GetYMin();
double Y2=rect.GetYMax();
double x2,y2,x4,y4;
VARIANT scx, scy, scx1, scy1;
VARIANT mapx1,mapy1,mapx2,mapy2;
CMapXFeatureFactory cFactory=CEagleMap->m_eaglemap.GetFeatureFactory();
CMapXLayer layer;
CMapXFeature feature;
CMapXFeatures features;
CMapXPoints points;
points.CreateDispatch(points.GetClsid());
CEagleMap->m_eaglemap.ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
CEagleMap->m_eaglemap.ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
CEagleMap->m_eaglemap.ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
CEagleMap->m_eaglemap.ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
x2=mapx1.dblVal;
y2=mapy1.dblVal;
x4=mapx2.dblVal;
y4=mapy2.dblVal;
layer=CEagleMap->m_eaglemap.GetLayers().Item("RectLayer");
features=layer.AllFeatures();
if(features.GetCount()==0)
{
points.AddXY(X1,Y1);
points.AddXY(x2,y2);
points.AddXY(X2,Y2);
points.AddXY(x4,y4);
COleVariant vtPoints;
vtPoints.vt = VT_DISPATCH;
vtPoints.pdispVal = points.m_lpDispatch;
vtPoints.pdispVal->AddRef();
feature=cFactory.CreateRegion(vtPoints);
CMapXStyle style=feature.GetStyle();
style.SetRegionPattern(miPatternNoFill);
style.SetRegionBorderColor(miColorRed);
style.SetRegionBorderWidth(2);
feature.SetStyle(style.m_lpDispatch);
CEagleMap->m_eaglefeature=layer.AddFeature(feature);
}
else
{
feature=features.Item(1);
CMapXParts parts=feature.GetParts();
CMapXPoints points=parts.Item(1);
points.RemoveAll();
points.AddXY(X1,Y1);
points.AddXY(x2,y2);
points.AddXY(X2,Y2);
points.AddXY(x4,y4);
feature.Update();
}
layer.Refresh();
}
}
int CEagleViewView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//short Type;
//VARIANT SourceData,Name,GeoField,SecondaryGeoField,BindLayerName,Fields;
// GetDlgItem(IDC_START)->EnableWindow(TRUE);
// GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
if(!m_mainmap.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAINMAP))
return -1;
m_mainmap.SetGeoSet("ChinaTrianMap.gst");
m_mainmap.SetTitleText("");
m_mainmap.CreateCustomTool(MYTOOL_DISTANCE,miToolTypePoly,miCrossCursor);
m_DataPoint1="";
m_DataPoint2="";
m_DataPoint="";
m_T=FALSE;
return 0;
}
void CEagleViewView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(cx!=0&&cy!=0)
{
m_mainmap.MoveWindow(0,0,cx,cy,TRUE);
}
// TODO: Add your message handler code here
}
void CEagleViewView::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
m_mainmap.SetFocus();
// TODO: Add your message handler code here
}
void CEagleViewView::OnEntireMap()
{
// TODO: Add your command handler code here
CString mapname=m_mainmap.GetGeoSet();
this->m_mainmap.SetGeoSet(mapname);
this->m_mainmap.SetTitleText("");
}
void CEagleViewView::OnMapToolArrow()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miArrowTool);
}
void CEagleViewView::OnZoomin()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miZoomInTool);
}
void CEagleViewView::OnZoomout()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miZoomOutTool);
}
void CEagleViewView::OnPan()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miPanTool);
}
void CEagleViewView::OnMapToolCenter()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miCenterTool);
}
void CEagleViewView::OnMapToolSelect()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miSelectTool);
}
void CEagleViewView::OnMapToolRadiusselect()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miRadiusSelectTool);
}
void CEagleViewView::OnMapToolRectangleselect()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miRectSelectTool);
}
void CEagleViewView::OnMapProperties()
{
// TODO: Add your command handler code here
this->m_mainmap.PropertyPage();
}
void CEagleViewView::OnMapLayercontrol()
{
// TODO: Add your command handler code here
this->m_mainmap.GetLayers().LayersDlg();
}
void CEagleViewView::OnInfo()
{
// TODO: Add your command handler code here
this->m_mainmap.SetCurrentTool(miLabelTool);
}
BOOL CEagleViewView::OnMouseMoveInMap(short button,short shift,OLE_XPOS_PIXELS x,OLE_YPOS_PIXELS y)
{
double mapx;
double mapy;
float screenX = (float)x;
float screenY = (float)y;
CMainFrame* pfram=(CMainFrame*)AfxGetApp()->m_pMainWnd;
m_mainmap.ConvertCoord(&screenX,&screenY,&mapx,&mapy,miScreenToMap);
CString str1,str2;
str1.Format("经度:%5f",mapx);
str2.Format("纬度:%5f",mapy);
CClientDC dc(this);
CSize sz=dc.GetTextExtent(str1);
pfram->m_wndStatusBar.SetPaneInfo(1,IDS_JINGDU,SBPS_NORMAL,sz.cx);
pfram->m_wndStatusBar.SetPaneText(1,str1);
pfram->m_wndStatusBar.SetPaneInfo(2,IDS_WEIDU,SBPS_NORMAL,sz.cx);
pfram->m_wndStatusBar.SetPaneText(2,str2);
return TRUE;
}
void CEagleViewView::OnLongthtest()
{
// TODO: Add your command handler code here
m_mainmap.SetCurrentTool(MYTOOL_DISTANCE);
}
void CEagleViewView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points, BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault)
{
if(Flags==miPolyToolInProgress)
{
if(ToolNum==MYTOOL_DISTANCE)
{
CMapXPoints pts;
long n;
long i;
try{
pts.AttachDispatch (Points, FALSE);
double dDistanceTot=0.0;
n=pts.GetCount ();
for (i=1; i<n;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -