mapx 显示新建图元的属性

/*
MapInfo Products Knowledge Base
Product: MapX
Version: 3.x/4.x
Platform: All Win32 Platforms
Category: C++
Summary:
Returning properties of a feature after it is attached to a Map.
Question:
MapX version 3.52 with Visual C++ 5.0. Numeric CoordSys of the map is Longitude/Latitude. The display CoordSys is Robinson. The map unit is degrees. Created a circular region and added it to the first layer using the following code snippet:
*/

CMapXFeatureFactory ff 
=  m_ctrlMapX.GetFeatureFactory();
CMapXFeature circle 
=  ff.CreateCircularRegion(miCircleTypeMap, pt.m_lpDispatch, Distance, COptionalVariant(), vResol, vStyle);
CMapXLayers layers 
=  m_ctrlMapX.GetLayers();
CMapXLayer layer 
=  layers.Item( 1 );
layer.AddFeature(circle);
/*
In the CreateCircularRegion function call, the center of the circle (pt) is 102.260776 (Longitude), 39.259696 (Latitude). The radius of circle (Distance) is 4.5601 (degrees).

Then, tried to return the feature (CMapXFeature circle) to another function for further processing. In this other function, tried to get the center of the circle by using the following function calls:
*/

double  centerX  =  circle.GetCenterX();
double  centerY  =  circle.GetCenterY();
/*
Both of these function calls return 0.000 (for both centerX and centerY). Tried using the MapXFeature::GetLabelPoint() function for this as well, and it returns the same thing. Shouldn't these function calls return centerX = 102.260776 and centerY = 39.259696?

Answer:

No, once a feature is attached to a map using Feature Factory, it is necessary to access its methods, properties and values by getting the feature from the layer; the original CMapXFeature no longer points to the same place in memory.

Sample code on how to do this using an ellipse (same concept here) follows:
*/


{
// Create a new ellipse region and add it to a temporary
// features layer
CMapXRectangle rect;
CMapXFeature createdEllipse;
CMapXFeature ftr;
int x;
if(!rect.CreateDispatch(rect.GetClsid())) 
{
TRACE0(
"Failed to Create rectangle object");
return;
}

try
 
{
     rect.Set(m_ctrlMapX.GetCenterX(),
     m_ctrlMapX.GetCenterY(),m_ctrlMapX.GetCenterX()
+30,
     m_ctrlMapX.GetCenterY()
+10);
     createdEllipse 
= m_ctrlMapX.GetFeatureFactory().CreateEllipticalRegion(rect);
     m_ctrlMapX.GetLayers().Item(
1).AddFeature(createdEllipse);
     x
=m_ctrlMapX.GetLayers().Item(1).AllFeatures().GetCount();
     ftr
=m_ctrlMapX.GetLayers().Item(1).GetFeatureByID(x);

CString msg;
msg.Format(
"Value is %f",ftr.GetCenterX());
AfxMessageBox(msg,
0,0);
retval(ftr);
}

 
catch(COleDispatchException* e) 
{
e
->ReportError();
e
->Delete();
}

 
catch(COleException* e) 
{
e
->ReportError();
e
->Delete();
}

}


void  CMapxSampleView::retval(CMapXFeature ellipse)
{
//type-cast doesn't work here so do it like this:
CString msg;
msg.Format(
"Value is %f",ellipse.GetCenterX());
AfxMessageBox(msg,
0,0);
}


// Last Modified: 1999-12-13 16:33:35
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值