This is CreateMap code for MapXMobile in EVC4

 void CTest4View::CreateMap(CString filename,double d_x,double d_y,CString s_x,CString s_y)
{
CString fieldName;
CMapXFields fields;
CMapXField field;
CMapXLayerInfo layerinfo;
CMapXLayer layer;
CMapXPoint point;
CMapXFeature feature;
CMapXFeatures features;

TRY{
  point.CreateDispatch(point.GetClsid());
  point.Set(d_x,d_y);
  VARIANT vPt;
  vPt.vt = VT_DISPATCH;
  vPt.pdispVal = point.m_lpDispatch;
  
  COleVariant liName(_T("Received"));  
  COleVariant strFile(filename + _T("tab"));
  // _T("\\Storage Card\\");_T("\\My Documents\\Maps\\");
  fields.CreateDispatch(fields.GetClsid());
  fields.AddStringField(_T("ID"),100);
  fields.AddStringField(_T("Name"),100);
  fields.AddStringField(_T("Long"),20);
  fields.AddStringField(_T("Lat"),20);

  VARIANT vFlgs;
  vFlgs.vt = VT_DISPATCH;
  vFlgs.pdispVal = fields.m_lpDispatch;
  layerinfo.CreateDispatch(layerinfo.GetClsid());
  layerinfo.SetType(miLayerInfoTypeNewTable);   //加载表的类型
  layerinfo.AddParameter(_T("Name"),liName);  //地图集的别名
  layerinfo.AddParameter(_T("FileSpec"),strFile);  //加载表的路径名
  layerinfo.AddParameter(_T("Fields"),vFlgs);
  //layerinfo.AddParameter(_T("OverwriteFile"),_T("1"));
  layer = m_ctrlMapX.GetLayers().Add(layerinfo.m_lpDispatch);
  feature = m_ctrlMapX.GetFeatureFactory().CreateSymbol(vPt);
  layer.AddFeature(feature);   //在地图上增加此图元
  //对图元点进行属性创建.
  CMapXLayer lyr;
  CMapXDataset ds;
  CMapXFeatures ftrs;
  CMapXFeature f;
  CMapXRowValues rvs;
  CMapXRowValue rv;
  lyr=m_ctrlMapX.GetLayers().Item(_T("Received"));
  COleVariant vLayer;
  vLayer.vt = VT_DISPATCH;
  vLayer.pdispVal = lyr.m_lpDispatch;
  ds = m_ctrlMapX.GetDatasets().Add(miDataSetLayer,vLayer,_T("Received"));
  ftrs = m_ctrlMapX.GetLayers().Item(_T("Received")).SearchAtPoint(point);
  f = ftrs.Item(1);
  COleVariant vF;
  vF.vt = VT_DISPATCH;
  vF.pdispVal = f.m_lpDispatch;
  rvs = ds.GetRowValues(vF);

  COleVariant vID = _T("1");
  COleVariant vName = _T("name1");
  COleVariant vLong = s_x;
  COleVariant vLat = s_y;
  rv = rvs.Item(_T("ID"));
  rv.SetValue(vID);
  rv = rvs.Item(_T("Name"));
  rv.SetValue(vName);
  rv = rvs.Item(_T("Long"));
  rv.SetValue(vLong);
  rv = rvs.Item(_T("Lat"));
  rv.SetValue(vLat);
  //m_ctrlMapX.SetAutoRedraw(false);
  //layer.SetEditable(true);  
  //feature.Update(true,rvs);
  f.Update(true,rvs);
  ds.Refresh();
  fields.ReleaseDispatch();
  layerinfo.ReleaseDispatch();
  bCreated = true;
}
CATCH(COleDispatchException,e)
{
  e->ReportError();
}
AND_CATCH(COleException,e)
{
  e->ReportError();
}
END_CATCH
}
本文标签:
posted @ 2008-11-28 17:39  googlegis  阅读(137)  评论(0编辑  收藏  举报

坐标合肥,非典型GIS开发人员 GitHub