VC动态操作MapX

  m_mapctrl.CreateCustomTool(ADD_MAPICON, miToolTypePoint,CComVariant(2),CComVariant(0),CComVariant(0),CComVariant(0));//, miCrossCursor 

void Cmap5testdlgDlg::ToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL* EnableDefault)
{
 // TODO: 在此处添加消息处理程序代码
 if(ToolNum==ADD_MAPICON)
 {
       /*
    得到特性工厂,由点创建Symbol得到feature->得到style,最后加入到层;
    */
  CMapXPoint   point;  
        CMapXFeature   feature;
  COleVariant   vtPoint; 
  CMapXLayer layer=m_mapx->GetLayers().Item(1); 
  CMapXFeatureFactory   cFactory=m_mapx->GetFeatureFactory();  
   
        point.CreateDispatch(point.GetClsid());
  point.Set(X1,Y1);  
   
        vtPoint.vt   =   VT_DISPATCH;  
        vtPoint.pdispVal   =   point.m_lpDispatch;  
        vtPoint.pdispVal->AddRef();  

  feature=cFactory.CreateSymbol(vtPoint);
  //feature.SetCaption();//设置主键,或标签
  //feature.SetKeyValue();
  CMapXStyle   style=feature.GetStyle();
        style.PickSymbol();//弹出对话框
        feature.SetStyle(style.m_lpDispatch);      
  
  layer.SetAutoLabel(true);//自动显示标签或主键
  layer.AddFeature(feature);
  

 }

//方法二
/*CMapXFeature fea;
CMapXStyle sy;
CString feakey;


if(!fea.CreateDispatch(fea.GetClsid())) {
  TRACE0("Failed to Create Feature object");
  return;
}

if(!sy.CreateDispatch(sy.GetClsid())) {
TRACE0("Failed to Create Feature object");
return;
}

sy.SetSymbolFontHalo(1);
sy.GetSymbolFont().SetWeight(12);
sy.SetSymbolCharacter(36);  //36表示五角星,还有其他图标
sy.SetSymbolFontColor(0xff);

//if (feakey != "")
//m_mapx->GetLayers().Item("MONLAY").DeleteFeature(feakey);
try {
 fea.Attach(m_mapx->GetDispatch());
 fea.SetType(miFeatureTypeSymbol);
 fea.SetStyle(sy);
 
 fea.GetPoint().Set(X1,Y1);
 feakey = m_mapx->GetLayers().Item(1).AddFeature(fea).GetFeatureKey ();

 } catch (COleDispatchException *e) {
 e->ReportError();
 e->Delete();
 } catch (COleException *e) {
 e->ReportError();
 e->Delete();
 }*/
}

你可能感兴趣的:(VC动态操作MapX)