欢迎来到天天文库
浏览记录
ID:11780906
大小:693.50 KB
页数:31页
时间:2018-07-14
《mapobjects二次开发实习讲义》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MapObjects二次开发实习讲义一、创建一个MapObjects工程1、新建VC工程Step1:新建工程Step2:选择SingleDocumentStep3:选择CFormView1、添加MapObjects组件Step1:选择Project->AddtoProject->ComponentStep2:选择MapObjects组件Step3:选择只添加一个MapObjects对象(全部选中)Step4:将MapObjects组件添加到Form,并定义变量Step5:为MapObjects控件定义变
2、量1、工程整理Step1:将MapObjects2.h、MapHelper.h、MapHelper.cpp、pedef.h拷贝至工程目录Step2:选择Project->AddtoProject->Files将MapObjects2.h、MapHelper.h、MapHelper.cpp添加到工程中Step3:在Stdafx.h中添加#Include“MapObjects.h”和“Maphelper.h”Step4:编译工程,成功,一个标准的MapObjects工程创建成功。一、加载图层1、添加矢量图层
3、//添加图层voidCMoLectureView::OnButton1(){//TODO:Addyourcontrolnotificationhandlercodehere//选择图层文件CFileDialogdlg(true,".shp","*.shp",OFN_HIDEREADONLY,"Shape文件(*.shp)
4、*.shp",NULL);CStringstr;if(dlg.DoModal()==IDOK){str=dlg.GetPathName();}elsereturn;//封装在MapHe
5、lper.h中的全局函数AddLayer(m_Map,str);}2、添加栅格图层//添加栅格影像图层voidCMoLectureView::OnButton2(){//TODO:Addyourcontrolnotificationhandlercodehere//选择图层文件CFileDialogdlg(true,".bmp","*.bmp",OFN_HIDEREADONLY,"栅格文件(*.bmp)
6、*.bmp",NULL);CStringstr;if(dlg.DoModal()==IDOK){st
7、r=dlg.GetPathName();}elsereturn;//封装在MapHelper.h中的全局函数AddImageLayer(m_Map,str);}一、图层管理1、图层数量//获得层数voidCMoLectureView::OnButton3(){//TODO:AddyourcontrolnotificationhandlercodehereCMoLayersm_Layers=m_Map.GetLayers();//获得图层集合intnLayerCount=m_Layers.GetCount
8、();}2、遍历图层//遍历图层voidCMoLectureView::OnButton4(){//TODO:AddyourcontrolnotificationhandlercodehereCMoLayersm_Layers=m_Map.GetLayers();//获得图层集合intnLayerCount=m_Layers.GetCount();inti;VARIANTindex;VariantInit(&index);index.vt=VT_I2;for(i=0;i9、{CMoMapLayerlayer;index.iVal=i;layer=m_Layers.Item(index);AfxMessageBox(layer.GetName());}}遍历图层可以得到每一个图层对象Layer,并对每一个图层对象可以遍历图层对象的属性、操作图层。如设置图层的可见性:layer.SetVisible(FALSE);万能变量的定义:(1)方式1VARIANTindex;VariantInit(&index);index.vt=VT_I2;index.iVal=i;(2)方式2l10、ongnCount=0;COleVariantindex;index=COleVariant(nCount,VT_I4);3、得到层中所有特征//遍历图层记录voidCMoLectureView::OnButton5(){//TODO:AddyourcontrolnotificationhandlercodehereCMoLayersm_Layers=m_Map.GetLayers();//获得图层集合intnLayerCount=m_La
9、{CMoMapLayerlayer;index.iVal=i;layer=m_Layers.Item(index);AfxMessageBox(layer.GetName());}}遍历图层可以得到每一个图层对象Layer,并对每一个图层对象可以遍历图层对象的属性、操作图层。如设置图层的可见性:layer.SetVisible(FALSE);万能变量的定义:(1)方式1VARIANTindex;VariantInit(&index);index.vt=VT_I2;index.iVal=i;(2)方式2l
10、ongnCount=0;COleVariantindex;index=COleVariant(nCount,VT_I4);3、得到层中所有特征//遍历图层记录voidCMoLectureView::OnButton5(){//TODO:AddyourcontrolnotificationhandlercodehereCMoLayersm_Layers=m_Map.GetLayers();//获得图层集合intnLayerCount=m_La
此文档下载收益归作者所有