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());
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;
}
}
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();
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
Feature=FeaFac.CreateLine(vtPoints);
Style=Feature.GetStyle();
Style.SetLineColor(miColorRed);
Style.SetLineWidth(2);
Feature.SetStyle(Style.m_lpDispatch);
Layer.AddFeature(Feature);
Layer.Refresh();
CMapXFeatureFactory FeaFac;
CMapXLayer Layer;
CMapXFeature Feature;
CMapXStyle Style;
double centerX,centerY;
centerX = m_ctrlMapX.GetCenterX();
centerY = m_ctrlMapX.GetCenterY();
Pnts.CreateDispatch(Pnts.GetClsid());
CMapXLayers layers = m_ctrlMapX.GetLayers();
BOOL Flag = false ;
for ( int i = 0 ;i < layers.GetCount();i ++ )
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/717446ca04a6125dc5b6b54e0fa14ab4.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
if (Flag==false)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
Layer=m_ctrlMapX.GetLayers().Item("tempLayer");
FeaFac=m_ctrlMapX.GetFeatureFactory();
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
Pnts.AddXY(centerX,centerY);
Pnts.AddXY(centerX+20,centerY+20);
COleVariant vtPoints;
vtPoints.vt=VT_DISPATCH;
vtPoints.pdispVal=Pnts.m_lpDispatch;
vtPoints.pdispVal->AddRef();
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
Feature=FeaFac.CreateLine(vtPoints);
Style=Feature.GetStyle();
Style.SetLineColor(miColorRed);
Style.SetLineWidth(2);
Feature.SetStyle(Style.m_lpDispatch);
Layer.AddFeature(Feature);
Layer.Refresh();