Mapx 画线

MapxInfo中添加字符型图标的代码

  CMapXFeature obj,newobj;
  CMapXPoints pts;
  CMapXPoint pt;
 
  if(!newobj.CreateDispatch(newobj.GetClsid()))
  {
    TRACE0("Failed to create Feature object");
    return;
  }
 
  if(!pts.CreateDispatch(pts.GetClsid()))
  {
    TRACE0("Failed to create Points collection");
    return;
  }
 
  if(!pt.CreateDispatch(pt.GetClsid()))
  {
    TRACE0("Failed to create Point object");
    return;
  }
  
  newobj.Attach(m_ctrlMapX.GetDispatch());
  try {   
    newobj.SetType(miFeatureTypeMultipoint);
    newobj.SetStyle(m_ctrlMapX.GetDefaultStyle()); 
   
    newobj.GetStyle().SetSymbolCharacter(53);  
    newobj.GetStyle().SetSymbolFontColor(255);
   
    newobj.GetStyle().GetSymbolFont().SetBold(TRUE);
   
    pt.Set(-101.023,45.0452);
    pts.Add(pt);
    pt.Set(-102.023,49.0452);
    pts.Add(pt);
    pt.Set(-100.0,34.2564);
    pts.Add(pt);
    newobj.GetParts().Add(pts);
   
    CMapXLayer mapxLayer;
    mapxLayer = m_ctrlMapX.GetLayers().Item("Event List");    
    obj = mapxLayer.AddFeature(newobj);    
  }
 
  catch (COleDispatchException *e)
  {
    e->ReportError();
    e->Delete();
  }
 
  catch (COleException *e)
  {
    e->ReportError();
    e->Delete();
  }
 

MapxInfo中添加Bmp图符的代码

  CMapXFeature obj,newobj;
  CMapXPoints pts;
  CMapXPoint pt;
 
  if(!newobj.CreateDispatch(newobj.GetClsid()))
  {
    TRACE0("Failed to create Feature object");
    return;
  }
 
  if(!pts.CreateDispatch(pts.GetClsid()))
  {
    TRACE0("Failed to create Points collection");
    return;
  }
 
  if(!pt.CreateDispatch(pt.GetClsid()))
  {
    TRACE0("Failed to create Point object");
    return;
  }
  
  newobj.Attach(m_ctrlMapX.GetDispatch());
  try { 
    newobj = m_ctrlMapX.GetFeatureFactory().CreateSymbol();  
    
    CMapXLayer mapxLayer;
    mapxLayer = m_ctrlMapX.GetLayers().Item("Event List");
 
  
    newobj.GetStyle().SetSymbolType(miSymbolTypeBitmap);
    newobj.GetStyle().SetSymbolBitmapSize(24);  // 图形的大小控制
    newobj.GetStyle().SetSymbolBitmapTransparent(FALSE);
    newobj.GetPoint().Set(-101.023,45.0452); // bmp 图显示的位置

    CMapXBitmapSymbols   bmps;  
    bmps.CreateDispatch(bmps.GetClsid());
    newobj.GetStyle().SetSymbolBitmapName(bmps.Item(15).GetName()); // 显示的图形
  
    obj = mapxLayer.AddFeature(newobj);    
  }
 
  catch (COleDispatchException *e)
  {
    e->ReportError();
    e->Delete();
  }
 
  catch (COleException *e)
  {
    e->ReportError();
    e->Delete();
  }
4月28日

Mapx中画线的代码(VC++) (转载)

文章来源:郭☆郭★宝☆贝 文章作者: 发布时间:2006-10-24
 
 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是画线的图层,首先判断是否存在。如果不存在就新建,并且使它为动态图层。
点的加入顺序不同,画出来的线条也是不一样的,大家可以测试一下,就明白了。
 

你可能感兴趣的:(object,list,测试,图形,layer)