如何在在MapX中画线的代码(Visual C++)

4 篇文章 0 订阅
CMapXPoints  Pnts;          //点集对象
 CMapXFeatureFactory FeaFac;
 CMapXLayer   Layer;
 CMapXFeature Feature;
 CMapXStyle   Style;
 double centerX,centerY;    //得到地图的中心
 centerX=m_ctrlMapX.GetCenterX();
 centerY=m_ctrlMapX.GetCenterY();
 Pnts.CreateDispatch(Pnts.GetClsid());
 // 判断是否存在tempLayer图层
 CMapXLayers layers=m_ctrlMapX.GetLayers();
 BOOL Flag=false;
 for(int i=0;i<layers.GetCount();i++)
 {
  Layer=layers.Item(i+1);
  if(Layer.GetName()=="tempLayer")
  {
    Flag=true; 
    break;
  }

 }
 //没有tempLayer图层,就新建
 if (Flag==false)
 {
  CMapXLayer lyr=m_ctrlMapX.GetLayers().CreateLayer("tempLayer");
  m_ctrlMapX.GetLayers().SetAnimationLayer(lyr); //设为动态图层  
 }
 Layer=m_ctrlMapX.GetLayers().Item("tempLayer");
 FeaFac=m_ctrlMapX.GetFeatureFactory();
 //加点
 Pnts.AddXY(centerX,centerY);
 Pnts.AddXY(centerX+20,centerY+20);
 //
 COleVariant vtPoints;
 vtPoints.vt=VT_DISPATCH;
 vtPoints.pdispVal=Pnts.m_lpDispatch;
 vtPoints.pdispVal->AddRef();

 Feature=FeaFac.CreateLine(vtPoints); //按照点集画线
    Style=Feature.GetStyle();
 Style.SetLineColor(miColorRed); //线条颜色
 Style.SetLineWidth(2);          //线条宽度
 Feature.SetStyle(Style.m_lpDispatch);
 Layer.AddFeature(Feature);  //加入Feature
 Layer.Refresh();            //更新图层

------------------------------
简单说明,tempLayer是画线的图层,首先判断是否存在。如果不存在就新建,并且使它为动态图层。
点的加入顺序不同,画出来的线条也是不一样的,大家可以测试一下,就明白了。
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值