如何在在MapX中画线

来源:互联网 发布:淘宝首页图片轮播尺寸 编辑:程序博客网 时间:2024/05/08 04:07

响应组建的按下事件,下面是具体的实现代码。

void CMapView::OnMouseDownMap(short Button, short Shift, float X, float Y) { 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); //设为动态图层   } CMapXPoint pt; pt.Set(X, Y); //m_ctrlMapX.ConvertCoord() 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();            //更新图层}