MapXViewView.cpp
资源名称:MapXView.rar [点击查看]
上传用户:gulin912
上传日期:2022-08-10
资源大小:330k
文件大小:24k
源码类别:
GIS编程
开发平台:
Visual C++
- // MapXViewView.cpp : implementation of the CMapXViewView class
- //
- #include "stdafx.h"
- #include "MapXView.h"
- #include "MapXViewDoc.h"
- #include "MapXViewView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMapXViewView
- IMPLEMENT_DYNCREATE(CMapXViewView, CFormView)
- BEGIN_MESSAGE_MAP(CMapXViewView, CFormView)
- //{{AFX_MSG_MAP(CMapXViewView)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
- ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
- ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
- ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
- ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
- ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
- ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
- ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
- ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
- ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
- ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
- ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
- ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
- ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
- ON_BN_CLICKED(IDC_BUTTON18, OnButton18)
- ON_BN_CLICKED(IDC_BUTTON19, OnButton19)
- ON_BN_CLICKED(IDC_BUTTON20, OnButton20)
- ON_BN_CLICKED(IDC_BUTTON21, OnButton21)
- ON_WM_TIMER()
- ON_BN_CLICKED(IDC_BUTTON22, OnButton22)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CMapXViewView construction/destruction
- CMapXViewView::CMapXViewView()
- : CFormView(CMapXViewView::IDD)
- {
- //{{AFX_DATA_INIT(CMapXViewView)
- m_XY = _T("");
- m_strQuery = _T("");
- m_PtLayer = NULL;
- m_LineLayer = NULL;
- m_PolyLayer = NULL;
- m_eaglefeature=NULL;
- m_bHasMap = FALSE;
- bEvent = FALSE;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- }
- CMapXViewView::~CMapXViewView()
- {
- }
- void CMapXViewView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMapXViewView)
- DDX_Control(pDX, IDC_LIST1, m_ListFs);
- DDX_Control(pDX, IDC_COMBO1, m_Layers);
- DDX_Control(pDX, IDC_MAP1, m_Map);
- DDX_Text(pDX, IDC_EDIT1, m_XY);
- DDX_Text(pDX, IDC_EDIT2, m_strQuery);
- DDX_Control(pDX, IDC_MAP2, m_EyeMap);
- //}}AFX_DATA_MAP
- }
- BOOL CMapXViewView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFormView::PreCreateWindow(cs);
- }
- void CMapXViewView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMapXViewView printing
- BOOL CMapXViewView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMapXViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMapXViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- void CMapXViewView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
- {
- // TODO: add customized printing code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMapXViewView diagnostics
- #ifdef _DEBUG
- void CMapXViewView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CMapXViewView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CMapXViewDoc* CMapXViewView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapXViewDoc)));
- return (CMapXViewDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMapXViewView message handlers
- void CMapXViewView::OnButton1()
- {
- // TODO: Add your control notification handler code here
- //选择一个GeoSet文件,包含多个图层自己定制的
- CFileDialog dlg(TRUE,NULL);
- CString strGeoset;
- if(dlg.DoModal()==IDOK)
- {
- strGeoset = dlg.GetPathName();
- }
- //加载Geoset的方法,为Map的方法
- m_Map.SetGeoSet(strGeoset);
- m_EyeMap.SetGeoSet(strGeoset);
- m_EyeMap.GetLayers().CreateLayer("Rectangle");
- m_bHasMap = TRUE;
- }
- void CMapXViewView::OnButton2()
- {
- // TODO: Add your control notification handler code here
- //方式2:调用Layer 管理对话框
- CMapXLayers layers;
- layers = m_Map.GetLayers();
- layers.LayersDlg();
- for(int i=0;i<layers.GetCount();i++)
- {
- m_EyeMap.GetLayers().Add(layers.Item(i+1).GetFilespec(),1);
- }
- //
- m_EyeMap.GetLayers().CreateLayer("Rectangle");
- m_bHasMap = TRUE;
- }
- void CMapXViewView::OnButton3()
- {
- // TODO: Add your control notification handler code here
- //方式3:添加单个图层
- CMapXLayers layers = m_Map.GetLayers();
- CFileDialog dlg(TRUE,NULL);
- CString str;
- if(dlg.DoModal()==IDOK)
- {
- str = dlg.GetPathName();
- }
- layers.Add(str,1);
- m_EyeMap.GetLayers().Add(str,1);
- m_EyeMap.GetLayers().CreateLayer("Rectangle");
- m_bHasMap = TRUE;
- }
- void CMapXViewView::OnButton4()
- {
- // TODO: Add your control notification handler code here
- m_Map.SetCurrentTool(1003);
- }
- void CMapXViewView::OnButton5()
- {
- // TODO: Add your control notification handler code here
- m_Map.SetCurrentTool(1004);
- }
- void CMapXViewView::OnButton6()
- {
- // TODO: Add your control notification handler code here
- m_Map.SetCurrentTool(miPanTool);
- }
- void CMapXViewView::OnButton7()
- {
- // TODO: Add your control notification handler code here
- CMapXLayers layers = m_Map.GetLayers();
- CMapXRectangle rect = layers.GetBounds();
- m_Map.SetBounds(rect);
- }
- void CMapXViewView::OnButton8()
- {
- // TODO: Add your control notification handler code here
- //1、图层数量
- CMapXLayers layers = m_Map.GetLayers();
- CMapXLayer layer;
- int nLayerCount = layers.GetCount();
- ///2、遍历图层
- for(int i=0;i<nLayerCount;i++)
- {
- layer = layers.Item(i+1);
- m_Layers.AddString(layer.GetName());
- // AfxMessageBox(layer.GetName());
- }
- m_Layers.SetCurSel(0);
- // 遍历图层可以得到每一个图层对象Layer,并对每一个图层对象可以遍历图层对象的属性、操作图层。如设置图层的可见性:
- //layer.SetVisible(FALSE);
- CMapXFeatures fs;
- layer = layers.Item(1);
- fs=layer.AllFeatures();
- m_ListFs.ResetContent();
- //遍历层对象
- for(i=0;i<fs.GetCount();i++)
- {
- m_ListFs.AddString(fs.Item(i+1).GetName());//m_ListInfo为定义的ListBox控件
- }
- }
- void CMapXViewView::OnSelchangeCombo1()
- {
- // TODO: Add your control notification handler code here
- CMapXLayers layers = m_Map.GetLayers();
- CMapXLayer layer;
- int nCurSel = m_Layers.GetCurSel();
- CMapXFeatures fs;
- layer = layers.Item(nCurSel+1);
- fs=layer.AllFeatures();
- m_ListFs.ResetContent();
- //遍历层对象
- for(int i=0;i<fs.GetCount();i++)
- {
- m_ListFs.AddString(fs.Item(i+1).GetName());//m_ListInfo为定义的ListBox控件
- }
- }
- BEGIN_EVENTSINK_MAP(CMapXViewView, CFormView)
- //{{AFX_EVENTSINK_MAP(CMapXViewView)
- ON_EVENT(CMapXViewView, IDC_MAP1, -606 /* MouseMove */, OnMouseMoveMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
- ON_EVENT(CMapXViewView, IDC_MAP1, -605 /* MouseDown */, OnMouseDownMap1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
- ON_EVENT(CMapXViewView, IDC_MAP1, 3 /* ToolUsed */, OnToolUsedMap1, VTS_I2 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_BOOL VTS_BOOL VTS_PBOOL)
- ON_EVENT(CMapXViewView, IDC_MAP1, 11 /* PolyToolUsed */, OnPolyToolUsedMap1, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
- ON_EVENT(CMapXViewView, IDC_MAP2, 15 /* MapDraw */, OnMapDrawMap2, VTS_I2)
- ON_EVENT(CMapXViewView, IDC_MAP1, 6 /* MapViewChanged */, OnMapViewChangedMap1, VTS_NONE)
- ON_EVENT(CMapXViewView, IDC_MAP2, -605 /* MouseDown */, OnMouseDownMap2, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CMapXViewView::OnMouseMoveMap1(short Button, short Shift, float X, float Y)
- {
- // TODO: Add your control notification handler code here
- double dX,dY;
- m_Map.ConvertCoord(&X,&Y,&dX,&dY,miScreenToMap );
- m_XY.Format("X:%.3f Y:%.3f",dX,dY);
- UpdateData(FALSE);
- }
- void CMapXViewView::OnButton9()
- {
- // TODO: Add your control notification handler code here
- nPtNum = 0;
- m_Map.SetMousePointer(miCrossCursor);
- }
- #include <cmath>
- void CMapXViewView::OnMouseDownMap1(short Button, short Shift, float X, float Y)
- {
- // TODO: Add your control notification handler code here
- double dX,dY;
- m_Map.ConvertCoord(&X,&Y,&dX,&dY,miScreenToMap );
- if(nPtNum==0)
- {
- XX[0] = dX;
- YY[0] = dY;
- nPtNum++;
- }
- else if(nPtNum>0)
- {
- XX[1] = dX;
- YY[1] = dY;
- double dDist = sqrt((XX[1]-XX[0])*(XX[1]-XX[0])+(YY[1]-YY[0])*(YY[1]-YY[0]));
- CString str;
- str.Format("Distance = %.3f",dDist);
- AfxMessageBox(str);
- nPtNum = 0;
- }
- }
- void CMapXViewView::OnButton11()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(102,miToolTypeLine,miSizeCursor);
- m_Map.SetCurrentTool(102);
- m_Map.SetMousePointer(miCrossCursor);
- }
- void CMapXViewView::OnButton10()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(302,miToolTypePolygon, miSizeCursor);
- m_Map.SetCurrentTool(302);
- m_Map.SetMousePointer(miCrossCursor);
- }
- void CMapXViewView::OnToolUsedMap1(short ToolNum, double X1, double Y1,
- double X2, double Y2,
- double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)
- {
- // TODO: Add your control notification handler code here
- if(ToolNum==102)
- {
- CString str;
- str.Format("Distance = %.2f",Distance);
- AfxMessageBox(str);
- }
- //点空间查询
- else if(ToolNum==202)
- {
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- CMapXPoint point;
- CMapXFeatures fs;
- CString str;
- if(!point.CreateDispatch(point.GetClsid()))
- {
- return;
- }
- point.Set((double)X1,(double)Y1);
- //查询语句
- fs=layer.SearchAtPoint(point,miSearchResultAll);
- for(int n=0;n<fs.GetCount();n++)
- {
- if(fs.Item(n+1).GetType()==0)/////判断获得的地物的形状是否为多边形
- str.Format(" The Aera of %s is:%lfrn",fs.Item(n+1).GetName(),fs.Item(n+1).GetArea());
- else
- str.Format(" the ID of %s is:%srn ",fs.Item(n+1).GetName(),fs.Item(n+1).GetFeatureID());
- }
- str="the result searched by Point is:rn"+str;
- AfxMessageBox(str);
- m_Map.SetCenterX(X1);
- m_Map.SetCenterY(Y1);
- //把查询结果放入选择集中显示
- CMapXSelection Selection=layer.GetSelection();
- Selection.SelectByPoint(X1,Y1,0);
- }
- //园查询
- else if(ToolNum==203)
- {
- CMapXFeatures fs;
- CMapXPoint point;
- if(!point.CreateDispatch(point.GetClsid()))
- {
- TRACE0("Failed to Create Circle Pobject");
- return;
- }
- point.Set(X1,Y1);
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- fs=layer.SearchWithinDistance(point,Distance,0,miSearchResultAll);/////圆查询的范围
- m_Map.SetCenterX(X1);
- m_Map.SetCenterY(Y1);
- CMapXSelection Selection =layer.GetSelection();
- Selection.SelectByRadius(X1,Y1,Distance, 0);
- Invalidate();
- }
- else if(ToolNum==204)
- {
- CMapXFeatures fs;
- CMapXRectangle rec;
- if(!rec.CreateDispatch(rec.GetClsid()))
- {
- TRACE0("Failed to Create Rectangle Pobject");
- return;
- }
- rec.Set(X1,Y1,X2,Y2);
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- fs=layer.SearchWithinRectangle(rec,miSearchResultAll);/////矩形查询的范围
- m_Map.SetCenterX(X1);
- m_Map.SetCenterY(Y1);
- CMapXSelection Selection =layer.GetSelection();
- Selection.SelectByRectangle(X1,Y1,X2,Y2, 0);
- Invalidate();
- }
- else if(ToolNum==205)
- {
- CMapXLayers layers=m_Map.GetLayers();
- CMapXFeature feature; //声明Feature变量
- if(!feature.CreateDispatch(feature.GetClsid())) {
- TRACE0("Failed to Create Feature object");
- return;
- }
- //创建图层
- if(m_PtLayer==NULL)
- {
- m_PtLayer = layers.CreateLayer("PointLayer");
- }
- else
- {
- m_PtLayer = layers.Item("PointLayer");
- }
- //创建特征对象
- feature.Attach(m_Map.GetDispatch());
- //设置类型
- feature.SetType(miFeatureTypeSymbol);
- feature.SetStyle(m_Map.GetDefaultStyle());
- CMapXStyle style=feature.GetStyle();
- style.SetSymbolType(miSymbolTypeBitmap);
- style.SetSymbolBitmapSize(12);
- style.SetSymbolBitmapTransparent(TRUE);
- style.SetSymbolBitmapName("D:\Program Files\MapInfo\MapX 5.0\CUSTSYMB\CAR1-32.BMP");
- feature.SetStyle(style);/**/
- feature.GetPoint().Set(X1,Y1);
- //将结果添加到图层里面
- m_PtLayer.AddFeature(feature);
- Invalidate();
- }
- //添加线对象
- else if(ToolNum==206)
- {
- CMapXLayers layers=m_Map.GetLayers();
- CMapXFeature feature; //声明Feature变量
- if(!feature.CreateDispatch(feature.GetClsid())) {
- TRACE0("Failed to Create Feature object");
- return;
- }
- //创建图层
- if(m_LineLayer==NULL)
- {
- m_LineLayer = layers.CreateLayer("LineLayer");
- }
- else
- {
- m_LineLayer = layers.Item("LineLayer");
- }
- CMapXPoints points; //声明Points变量
- //设置类型
- points.CreateDispatch(points.GetClsid());
- points.AddXY(X1,Y1); //添加顶点1
- points.AddXY(X2,Y2); //添加顶点2
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = points.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- CMapXFeatureFactory cFactory= m_Map.GetFeatureFactory();
- //创建特征对象
- feature = cFactory.CreateLine(vtPoints);
- feature.SetType(miFeatureTypeLine);
- //设置线型
- CMapXStyle style=feature.GetStyle();
- style.SetLineColor(miColorRed);
- style.SetLineStyle(93);
- feature.SetStyle(style.m_lpDispatch);
- //将结果添加到图层里面
- m_LineLayer.AddFeature(feature);
- Invalidate();
- }
- else if(ToolNum==309)
- {
- CMapXLayers layers=m_Map.GetLayers();
- CMapXFeature feature; //声明Feature变量
- if(!feature.CreateDispatch(feature.GetClsid())) {
- TRACE0("Failed to Create Feature object");
- return;
- }
- //创建图层
- if(m_TrLayer==NULL)
- {
- m_TrLayer = layers.CreateLayer("TrackLayer");
- }
- else
- {
- m_TrLayer = layers.Item("TrackLayer");
- }
- //创建特征对象
- feature.Attach(m_Map.GetDispatch());
- //设置类型
- feature.SetType(miFeatureTypeSymbol);
- feature.SetStyle(m_Map.GetDefaultStyle());
- CMapXStyle style=feature.GetStyle();
- feature.GetPoint().Set(X1,Y1);
- //将结果添加到图层里面
- m_TrLayer.AddFeature(feature);
- bEvent = TRUE;
- Invalidate();
- }
- }
- void CMapXViewView::OnPolyToolUsedMap1(short ToolNum, long Flags,
- LPDISPATCH Points,
- BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault)
- {
- // TODO: Add your control notification handler code here
- if(Flags==miPolyToolEnd)
- if(ToolNum==302)
- {
- CMapXFeatureFactory cFactory=m_Map.GetFeatureFactory();
- CMapXFeature feature; //声明Feature变量
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = Points;
- vtPoints.pdispVal->AddRef();
- feature=cFactory.CreateRegion(vtPoints);
- CString str;
- str.Format("Area = %.2f",feature.GetArea());
- AfxMessageBox(str);
- }
- //添加多边形
- else if(ToolNum==303)
- {
- CMapXLayers layers=m_Map.GetLayers();
- CMapXFeature feature; //声明Feature变量
- if(!feature.CreateDispatch(feature.GetClsid())) {
- TRACE0("Failed to Create Feature object");
- return;
- }
- //创建图层
- if(m_PolyLayer==NULL)
- {
- m_PolyLayer = layers.CreateLayer("PolyLayer");
- }
- else
- {
- m_PolyLayer = layers.Item("PolyLayer");
- }
- CMapXPoints pts;
- pts.AttachDispatch(Points,FALSE);
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = pts.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- CMapXFeatureFactory cFactory= m_Map.GetFeatureFactory();
- //创建特征对象
- feature = cFactory.CreateRegion(vtPoints);
- //设置线型
- CMapXStyle style=feature.GetStyle();
- style.SetRegionPattern(miPatternCross); //设置填充方式
- style.SetRegionBorderColor(miColorRed); //设置边框颜色
- style.SetRegionBorderWidth(2); //设置边框宽度
- feature.SetStyle(style.m_lpDispatch);
- //将结果添加到图层里面
- m_PolyLayer.AddFeature(feature);
- Invalidate();
- }
- }
- void CMapXViewView::OnButton12()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- //定义查询对象
- CMapXLayerFind find = layer.GetFind();
- //得到查询对象
- CMapXFindFeature FoundObject;
- FoundObject = find.Search(m_strQuery);
- //获取查询对象信息
- CString str;
- if( FoundObject.GetType()==0)///判断地物是否为多边形
- {
- str.Format("Area = %.2f",FoundObject.GetArea());
- }
- str=FoundObject.GetName()+"'s Area is: "+str;
- AfxMessageBox(str);
- //将地图定位至查询对象的中心
- double dX,dY;
- dX = FoundObject.GetCenterX();
- dY = FoundObject.GetCenterY();
- m_Map.SetCenterX(dX);
- m_Map.SetCenterY(dY);
- //将查询对象放至选择集
- CMapXSelection Selection = layer.GetSelection();
- Selection.SelectByPoint(dX,dY, miSelectionNew);
- }
- void CMapXViewView::OnButton13()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(202,miToolTypePoint,miCrossCursor);
- m_Map.SetCurrentTool(202);
- }
- void CMapXViewView::OnButton14()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(203,miToolTypeCircle,miCrossCursor);
- m_Map.SetCurrentTool(203);
- }
- void CMapXViewView::OnButton15()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(204,miToolTypeMarquee,miCrossCursor);
- m_Map.SetCurrentTool(204);
- }
- void CMapXViewView::OnButton16()
- {
- // TODO: Add your control notification handler code here
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- COleVariant rsVariant;
- rsVariant.vt = VT_DISPATCH;
- rsVariant.pdispVal = layer;
- CMapXDatasets datasets = m_Map.GetDatasets();
- //////
- datasets.Add(miDataSetLayer,rsVariant);
- CMapXDataset dataset = datasets.Item(1);
- CMapXFields fields = dataset.GetFields();
- for(int i=0;i<fields.GetCount();i++)
- {
- CMapXField field = fields.Item(i+1);
- // AfxMessageBox(fields.Item(i+1).GetName());
- }
- //得到具体的字段值
- COleVariant valueVt;
- for(i=0;i<fields.GetCount();i++)
- {
- valueVt = dataset.GetValue(1,i+1);
- valueVt.ChangeType(VT_BSTR);
- CString str = valueVt.bstrVal;
- AfxMessageBox(str);
- }/**/
- }
- void CMapXViewView::OnButton17()
- {
- // TODO: Add your control notification handler code here
- CMapXLayers layers=m_Map.GetLayers();
- CMapXLayer layer = layers.Item(1);
- COleVariant rsVariant;
- rsVariant.vt = VT_DISPATCH;
- rsVariant.pdispVal = layer;
- //绑定层的属性数据表
- CMapXDatasets datasets = m_Map.GetDatasets();
- datasets.Add(miDataSetLayer,rsVariant);
- CMapXDataset dataset = datasets.Item(1);
- CMapXThemes themes = dataset.GetThemes();
- if(themes.GetCount!=0)
- {
- themes.RemoveAll();
- }
- themes.Add(miThemeDotDensity, 5,"AAA");
- CMapXTheme theme = themes.Item("AAA");
- theme.ThemeDlg();
- }
- void CMapXViewView::OnButton18()
- {
- // TODO: Add your control notification handler code here
- CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"BMP File(*.bmp)|*.bmp|");
- CString str;
- if(dlg.DoModal()==IDOK)
- {
- str=dlg.GetPathName();
- m_Map.ExportMap(str,miFormatBMP);
- }
- }
- void CMapXViewView::OnButton19()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(205,miToolTypePoint,miCrossCursor);
- m_Map.SetCurrentTool(205);
- }
- void CMapXViewView::OnButton20()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(206,miToolTypeLine,miCrossCursor);
- m_Map.SetCurrentTool(206);
- }
- void CMapXViewView::OnButton21()
- {
- // TODO: Add your control notification handler code here
- m_Map.CreateCustomTool(303,miToolTypePolygon, miSizeCursor);
- m_Map.SetCurrentTool(303);
- }
- void CMapXViewView::OnMapDrawMap2(short Flag)
- {
- // TODO: Add your control notification handler code here
- double X1,Y1,X2,Y2; //声明坐标变量
- //声明FeatureFactory变量并获取缺省值
- CMapXFeatureFactory cFactory=m_EyeMap.GetFeatureFactory();
- CMapXLayer layer; //声明图层变量
- CMapXFeature feature; //声明Feature变量
- CMapXFeatures features; //声明Features变量
- CMapXPoints points; //声明Points变量
- points.CreateDispatch(points.GetClsid());
- CMapXRectangle rect; //声明矩形变量
- rect.CreateDispatch(rect.GetClsid());
- //获取主图的边界,根据这个边界值,在鹰眼图上添加一个矩形Feature
- rect = m_Map.GetBounds();
- X1 = rect.GetXMin(); //获得矩形左上顶点x坐标
- Y1 = rect.GetYMin(); //获得矩形左上顶点y坐标
- X2 = rect.GetXMax(); //获得矩形右下顶点x坐标
- Y2 = rect.GetYMax(); //获得矩形右下顶点y坐标
- //得到添加矩形Feature的图层
- layer=m_EyeMap.GetLayers().Item("Rectangle");
- features=layer.AllFeatures();
- //没有添加矩形Feature的图层,则新建
- if(features.GetCount() == 0)
- {
- //添加四个顶点构成一个矩形框
- points.AddXY(X1,Y1); //添加顶点1
- points.AddXY(X1,Y2); //添加顶点2
- points.AddXY(X2,Y2); //添加顶点3
- points.AddXY(X2,Y1); //添加顶点4
- //创建矩形Feature
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = points.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- feature=cFactory.CreateRegion(vtPoints);
- //设置矩形Feature的属性
- CMapXStyle style=feature.GetStyle();
- style.SetRegionPattern(miPatternNoFill); //设置矩形的填充方式
- style.SetRegionBorderColor(miColorRed); //设置矩形边框颜色
- style.SetRegionBorderWidth(2); //设置矩形边框宽度
- feature.SetStyle(style.m_lpDispatch);
- //添加已经创建的矩形Feature
- m_eaglefeature = layer.AddFeature(feature);
- }
- }
- void CMapXViewView::OnMapViewChangedMap1()
- {
- // TODO: Add your control notification handler code here
- if(!m_bHasMap)
- return;
- double X1,Y1,X2,Y2; //声明坐标变量
- CMapXRectangle rect; //声明矩形变量
- rect.CreateDispatch(rect.GetClsid());
- //获取主图的边界,根据这个边界值,在鹰眼图上添加一个矩形Feature
- rect = m_Map.GetBounds();
- X1 = rect.GetXMin(); //获得矩形左上顶点x坐标
- Y1 = rect.GetYMin(); //获得矩形左上顶点y坐标
- X2 = rect.GetXMax(); //获得矩形右下顶点x坐标
- Y2 = rect.GetYMax(); //获得矩形右下顶点y坐标
- CMapXLayer layer=m_EyeMap.GetLayers().Item("Rectangle");
- if(m_eaglefeature==NULL)
- {
- }
- else
- {
- m_eaglefeature.GetParts().Item(1).RemoveAll(); //除去已有的顶点
- m_eaglefeature.GetParts().Item(1).AddXY(X1,Y1); //添加顶点1
- m_eaglefeature.GetParts().Item(1).AddXY(X1,Y2); //添加顶点2
- m_eaglefeature.GetParts().Item(1).AddXY(X2,Y2); //添加顶点3
- m_eaglefeature.GetParts().Item(1).AddXY(X2,Y1); //添加顶点4
- m_eaglefeature.Update(); //更新Feature属性
- }
- //更新显示图层
- layer.Refresh();
- }
- void CMapXViewView::OnMouseDownMap2(short Button, short Shift, float X, float Y)
- {
- // TODO: Add your control notification handler code here
- double m_x,m_y;
- m_EyeMap.ConvertCoord(&X,&Y,&m_x,&m_y,1);
- m_Map.SetCenterX(m_x);
- m_Map.SetCenterY(m_y);
- }
- void CMapXViewView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(nIDEvent==1&&bEvent)
- {
- CMapXLayer layer=m_Map.GetLayers().Item("TrackLayer");
- CMapXFeatures fs = layer.AllFeatures();
- CMapXFeature f;
- int fsCount = fs.GetCount();
- for(int i=0;i<fsCount;i++)
- {
- f = fs.Item(i+1);
- f.Offset(0.5,0.5);
- f.Update();
- }
- layer.Refresh();
- }
- CFormView::OnTimer(nIDEvent);
- }
- void CMapXViewView::OnButton22()
- {
- // TODO: Add your control notification handler code here
- SetTimer(1,500,NULL);
- m_Map.CreateCustomTool(309,miToolTypePoint,miCrossCursor);
- m_Map.SetCurrentTool(309);
- }