MapX VC++  添加图层

MapX添加图层的方法
向MAPX添加图层的方法有多种,我使用了两种方法:
第一种方法:
生成一个新的图层,也就是说会多出来tab,id,dat,map共四个文件。
具体代码为:
char clientpath[121];
GetCurrentDirectory(120,clientpath);//得到当前路径
CString m_tempclientpath = _T("");
m_tempclientpath.Format("%s\map\GPS_status.tab",clientpath);    //地图所在的目录放置tab文件
CString tempPathGST=_T("");
tempPathGST.Format("%s\map\Untitled.gst",clientpath);    //取得地图集gst文件路径
CMapXFields Flds;
if(!Flds.CreateDispatch(Flds.GetClsid ()))
//return FALSE;
    MessageBox("Create Field error!");
VARIANT FieldName;                     //字段名称
FieldName.vt = VT_BSTR;
CString csTmp;         //中文字段名称
csTmp = _T("StatusField");
LPCTSTR lcsTmp = (LPCTSTR)csTmp;
VARIANT FieldLength;                  //字段长度
FieldLength.vt=VT_I2;
FieldLength.iVal =200;
long iwidth = 200;
Flds.AddStringField(lcsTmp,iwidth,false);
//Create a variant that points to the fields collection just created
VARIANT vFlds;
vFlds.vt = VT_DISPATCH;
vFlds.pdispVal = Flds.m_lpDispatch;
//Create a new LayerInfo Object
CMapXLayerInfo Linfo;
Linfo.CreateDispatch(Linfo.GetClsid());
//Set the Layer Info type to type: New Table
Linfo.SetType(miLayerInfoTypeNewTable);
//Add the parameters for the new table
Linfo.AddParameter("FileSpec", COleVariant(m_tempclientpath)); //Tab file
Linfo.AddParameter("Name", COleVariant("GPS_status")); //Layer name
Linfo.AddParameter("Fields", vFlds); //Fields
Linfo.AddParameter("OverwriteFile", COleVariant("1"));
//Add the new layer to the map

CMapXLayer lyr=m_CtrlMapX.GetLayers().Add(Linfo.m_lpDispatch);
MessageBox("Create Layer correctly,StatusLayer!");
//下面代码为了显示所有图层的名字,检验是否添加了新的图层
CMapXLayers layers=m_CtrlMapX.GetLayers();
int iii=layers.GetCount();
if (iii>0)
{       
        for (int iss=1; iss <= iii; iss ++)
        {
            CMapXLayer templayer=layers.Item(iss);
            CString sss=templayer.GetName();
            AfxMessageBox(sss);
        }
}
//save the gst file
//如果不储存gst,那么下次打开的时候还是没有将这个图层添加到gst文件中去
//m_CtrlMapX.SaveMapAsGeoset("",tempPathGST);

第二种方法:已经有了图层文件,只需将文件添加到地图集中去
其他代码参照第一个例子
取得tab文件的路径在m_tempclientpath中,添加图层
CMapXLayer lyr=m_CtrlMapX.GetLayers().Add(m_tempclientpath);
记得最后要保存gst文件,否则下次打开还需要添加。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值