我用vc+MapX 要实现一个鹰眼图的功能,现在遇到的问题是:当在小地图上画矩形框的时候,画出来的不是矩形 而是一个菱形,线都是斜的 很奇怪 部分代码如下,高手帮忙解释一下:
extern CRect g_ctrlMapCoord; VARIANT scrLeft,scrTop,scrRight,scrBottom;
VARIANT mapLeft,mapTop,mapRight,mapBottom;
double eagelLeft,eagelTop,eagelRight,eagelBottom;
double left,top,right,bottom;
eagelLeft= eagelTop = eagelRight= eagelBottom = 0;
left=g_ctrlMapCoord.left;
top=g_ctrlMapCoord.top;
right=g_ctrlMapCoord.right;
bottom=g_ctrlMapCoord.bottom; CMapXStyle style;
CMapXLayer layer;
CMapXFeatures features;
CMapXFeature feature;
static CMapXFeature m_eagelFeature;
CMapXFeatureFactory factory;
CMapXParts parts;
CMapXPoints points;
points.CreateDispatch(points.GetClsid());
//进行坐标变换
m_smallMap.ConvertCoordV(&scrLeft,&scrTop,COleVariant(left),COleVariant(top),miMapToScreen);
m_smallMap.ConvertCoordV(&scrRight,&scrBottom,COleVariant(right),COleVariant(bottom),miMapToScreen);
m_smallMap.ConvertCoordV(&scrLeft,&scrTop,&mapLeft,&mapTop,miScreenToMap);
m_smallMap.ConvertCoordV(&scrRight,&scrBottom,&mapRight,&mapBottom,miScreenToMap);
eagelLeft = mapLeft.dblVal;
eagelTop =mapTop.dblVal;
eagelRight =mapRight.dblVal;
eagelBottom = mapBottom.dblVal;
//获得添加矩形框的图层
layer =m_smallMap.GetLayers().Item("DynRect");
features= layer.AllFeatures();
//若图层上没有矩形框 ,则新建
if(features.GetCount()==0)
{
points.AddXY(eagelLeft,eagelTop);
points.AddXY(eagelRight,eagelTop);
points.AddXY(eagelRight,eagelBottom);
points.AddXY(eagelLeft,eagelBottom); COleVariant vtPoints;
vtPoints.vt = VT_DISPATCH;
vtPoints.pdispVal = points.m_lpDispatch;
vtPoints.pdispVal->AddRef();
style= layer.GetStyle();
style.SetRegionPattern(miPatternNoFill);
style.SetRegionBorderColor(miColorRed);
style.SetRegionBorderWidth(2);
COleVariant vtStyle;
vtStyle.vt= VT_DISPATCH ;
vtStyle.pdispVal = style.m_lpDispatch;
vtStyle.pdispVal->AddRef();
factory= m_smallMap.GetFeatureFactory();
feature= factory.CreateRegion(vtPoints,vtStyle);
m_eagelFeature= layer.AddFeature (feature.m_lpDispatch);
}
else //否则更新矩形框的位置或大小
{
points.AddXY(eagelLeft,eagelTop);
points.AddXY(eagelRight,eagelTop);
points.AddXY(eagelRight,eagelBottom);
points.AddXY(eagelLeft,eagelBottom);
parts=m_eagelFeature.GetParts();
parts.RemoveAll();
parts.Add(points);
m_eagelFeature.Update();
}
layer.Refresh();
extern CRect g_ctrlMapCoord; VARIANT scrLeft,scrTop,scrRight,scrBottom;
VARIANT mapLeft,mapTop,mapRight,mapBottom;
double eagelLeft,eagelTop,eagelRight,eagelBottom;
double left,top,right,bottom;
eagelLeft= eagelTop = eagelRight= eagelBottom = 0;
left=g_ctrlMapCoord.left;
top=g_ctrlMapCoord.top;
right=g_ctrlMapCoord.right;
bottom=g_ctrlMapCoord.bottom; CMapXStyle style;
CMapXLayer layer;
CMapXFeatures features;
CMapXFeature feature;
static CMapXFeature m_eagelFeature;
CMapXFeatureFactory factory;
CMapXParts parts;
CMapXPoints points;
points.CreateDispatch(points.GetClsid());
//进行坐标变换
m_smallMap.ConvertCoordV(&scrLeft,&scrTop,COleVariant(left),COleVariant(top),miMapToScreen);
m_smallMap.ConvertCoordV(&scrRight,&scrBottom,COleVariant(right),COleVariant(bottom),miMapToScreen);
m_smallMap.ConvertCoordV(&scrLeft,&scrTop,&mapLeft,&mapTop,miScreenToMap);
m_smallMap.ConvertCoordV(&scrRight,&scrBottom,&mapRight,&mapBottom,miScreenToMap);
eagelLeft = mapLeft.dblVal;
eagelTop =mapTop.dblVal;
eagelRight =mapRight.dblVal;
eagelBottom = mapBottom.dblVal;
//获得添加矩形框的图层
layer =m_smallMap.GetLayers().Item("DynRect");
features= layer.AllFeatures();
//若图层上没有矩形框 ,则新建
if(features.GetCount()==0)
{
points.AddXY(eagelLeft,eagelTop);
points.AddXY(eagelRight,eagelTop);
points.AddXY(eagelRight,eagelBottom);
points.AddXY(eagelLeft,eagelBottom); COleVariant vtPoints;
vtPoints.vt = VT_DISPATCH;
vtPoints.pdispVal = points.m_lpDispatch;
vtPoints.pdispVal->AddRef();
style= layer.GetStyle();
style.SetRegionPattern(miPatternNoFill);
style.SetRegionBorderColor(miColorRed);
style.SetRegionBorderWidth(2);
COleVariant vtStyle;
vtStyle.vt= VT_DISPATCH ;
vtStyle.pdispVal = style.m_lpDispatch;
vtStyle.pdispVal->AddRef();
factory= m_smallMap.GetFeatureFactory();
feature= factory.CreateRegion(vtPoints,vtStyle);
m_eagelFeature= layer.AddFeature (feature.m_lpDispatch);
}
else //否则更新矩形框的位置或大小
{
points.AddXY(eagelLeft,eagelTop);
points.AddXY(eagelRight,eagelTop);
points.AddXY(eagelRight,eagelBottom);
points.AddXY(eagelLeft,eagelBottom);
parts=m_eagelFeature.GetParts();
parts.RemoveAll();
parts.Add(points);
m_eagelFeature.Update();
}
layer.Refresh();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货