/**//* 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