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();
 }*/
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值