请教一个
问题。
下面是在MapX帮助文档上摘抄的一个例子,添加文字到MapX地图上面。是用VC++写的。
- void CSampleProjectView::FeatureFactoryTextCreate() {
-
- CMapXFeature ftr;
-
- CMapXPoint pnt;
-
- COleVariant pntVt;
-
- if(!pnt.CreateDispatch(pnt.GetClsid())) {
-
- TRACE0("Failed to Create Point object");
-
- return;
-
- }
-
- try {
-
- // Use the map's current center as the point's coordinates
-
- pnt.Set(m_Map.GetCenterX(),m_Map.GetCenterY());
-
- pntVt.vt = VT_DISPATCH;
-
- pntVt.pdispVal = pnt.m_lpDispatch;
-
- pntVt.pdispVal->AddRef();
-
- // Create a text feature and add it to layer 1
-
- ftr = m_Map.GetLayers().Item(1).
-
- AddFeature(m_Map.GetFeatureFactory().
-
- CreateText(pntVt,"Some Text"));
-
- } catch (COleDispatchException *e) {
-
- e->ReportError();
-
- e->Delete();
-
- } catch (COleException *e) {
-
- e->ReportError();
-
- e->Delete();
-
- }
-
- }
但是用Qt按照类似的方面做了一遍。在地图上并为
显示出文字。
- bool MapXWidget::DrawText(const QString &text)
-
- {
-
- CMapXFeature* ftr;
-
- CMapXPoint* pnt = new CMapXPoint();
-
- QVariant pntVt;
-
- QVariant pntText = QVariant("Some Text");//text
-
- //if(!pnt.CreateDispatch(pnt.GetClsid())) {
-
- // TRACE0("Failed to Create Point object");
-
- // return;
-
- //}
-
- try {
-
- // Use the map's current center as the point's coordinates
-
- pnt->Set(m_map->CenterX(), m_map->CenterY());
-
- pntVt = pnt->asVariant();
-
- //pntVt.vt = VT_DISPATCH;
-
- //pntVt.pdispVal = pnt.m_lpDispatch;
-
- //pntVt.pdispVal->AddRef();
-
- // Create a text feature and add it to layer 1
-
- ftr = m_map->Layers()->Item(
-
- m_taglayer.LAYER_TRACK)->AddFeature(
-
- (IDispatch*)m_map->FeatureFactory()->CreateText(pntVt, pntText));
-
- } catch (...) {
-
- }
-
- return true;
-
- }