RT,我在网上看到例子,是使用MapX在VC里画个简单的矩形,代码
CMapXPoints Pnts;
CMapXFeatureFactory FeaFac;
CMapXLayer Layer;
CMapXFeature Feature;
CMapXStyle Style;
CMapXRectangle rect;
rect.CreateDispatch(rect.GetClsid());
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()=="SOUNDINGS")
{
Flag=true;
break;
}
}
//没有tempLayer图层,就新建
if (Flag==false)
{
CMapXLayer lyr=m_ctrlMapX.GetLayers().CreateLayer("SOUNDINGS");
m_ctrlMapX.GetLayers().SetAnimationLayer(lyr); //设为动态图层
}
Layer=m_ctrlMapX.GetLayers().Item("SOUNDINGS");
FeaFac=m_ctrlMapX.GetFeatureFactory();
Pnts.AddXY(centerX,centerY); //第一个点
Pnts.AddXY(centerX+200,centerY); //第二个点
Pnts.AddXY(centerX+200,centerY+200); //第三个点
Pnts.AddXY(centerX,centerY+20); //第四个点
COleVariant vtPoints;
vtPoints.vt=VT_DISPATCH;
vtPoints.pdispVal=Pnts.m_lpDispatch;
vtPoints.pdispVal->AddRef();
Feature=FeaFac.CreateRegion(vtPoints);
Style=Feature.GetStyle();
Style.SetRegionPattern(miPatternNoFill); //填充颜色 无
Style.SetRegionBorderColor(miColorRed); //边框颜色 红
Style.SetRegionBorderWidth(2); //边框宽度
Feature.SetStyle(Style.m_lpDispatch);
Layer.AddFeature(Feature); //加入Feature
Layer.Refresh(); //更新图层
但是为什么在图层里什么也没有显示?
------解决方案--------------------
这段代码是没问题的。是不是其他地方的问题。如果说调用没问题就是显示的问题。可以看看初始化的地方。