资源预览内容
第1页 / 共66页
第2页 / 共66页
第3页 / 共66页
第4页 / 共66页
第5页 / 共66页
第6页 / 共66页
第7页 / 共66页
第8页 / 共66页
第9页 / 共66页
第10页 / 共66页
亲,该文档总共66页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1 VC+AE 系列 实现对图层的标注、简单渲染 标注图层:1. void CAOTestView:OnCartoLabel()2. 3. / TODO: Add your command handler code here4.5. HRESULT hr;6. IMapPtr pMap= m_ctrlMap.GetMap(); /m_ctrlMap是MapControl的控件变量7. ILayerPtr ipLayer=NULL;8. pMap-get_Layer(m_ctrlMap.GetLayerCount()-1,&ipLayer); /获取最后的图层9.10. ILabelEngineLayerPropertiesPtr pLBProp;11. IAnnotateLayerPropertiesPtr pALProp;12. IAnnotateLayerPropertiesCollectionPtr pALProps;13. IGeoFeatureLayerPtr pGeoFeatLyr= ipLayer;14.15. if(NULL=pGeoFeatLyr)16. return ;17. hr=pGeoFeatLyr-get_AnnotationProperties(&pALProps);18. hr=pALProps-QueryItem(0,&pALProp,NULL,NULL);19. if(NULL=(pLBProp=pALProp)20. return ;21. pLBProp-put_IsExpressionSimple(VARIANT_TRUE);22. pLBProp-put_Expression(_bstr_t)Height);/设置标注字段,大家拷过去时要改下字段名23.24. /创建标注符号25. IFormattedTextSymbolPtr pFormatTxtSym(CLSID_TextSymbol);26.27.28. /自己设置符号的样式/29. / /设置标注的字体30. / IFontPtr pFont(_uuidof(StdFont);31. / pFont-put_Name(_bstr_t) Courier New);/字体集32. / CY cy;33. / cy.Hi = 10 * 72;34. / cy.Lo = 8 * 72;35. / pFont-put_Size(cy);36. / pFont-put_Bold(TRUE);37. / pFormatTxtSym-put_Font(IFontDispPtr)pFont) ;38. /39. / /设置标注的颜色40. / IColorPtr pColor;41. / pFormatTxtSym-get_Color(&pColor);42. / hr=pColor-put_RGB(RGB(0,120,0);/深绿色43. / if(FAILED(hr) return;44. / hr=pFormatTxtSym-put_Color(pColor);45.46. /从样式库文件中获取符号的样式/47. IStyleGalleryItemPtr pSGitem=NULL;48. IEnumStyleGalleryItemPtr pEnumSGitem;49. IStyleGalleryPtr pStyleGall(CLSID_ServerStyleGallery);50. IStyleGalleryStoragePtr pSGstorage(pStyleGall);51. CString strStyleFile=C:Program FilesArcGISStylesESRI.ServerStyle;52. CString strStyleClass=Text Symbols;53.54. /获取样式文件55. pSGstorage-put_TargetFile(_bstr_t)strStyleFile);56. pStyleGall-get_Items(_bstr_t)strStyleClass,(_bstr_t)strStyleFile,57. (_bstr_t),&pEnumSGitem);58. if (NULL=pEnumSGitem)59. 60. MessageBox(获取样式集失败!);61. return;62. 63.64. BSTR bsName;65. pEnumSGitem-Reset();66. pEnumSGitem-Next(&pSGitem);67.68. if (NULL=pSGitem)69. 70. MessageBox(获取样式项失败!);71. return;72. 73. IUnknownPtr pUnk;74. pSGitem-get_Item(&pUnk);75. if (NULL=(pFormatTxtSym=pUnk)76. 77. return;78. 79.80. pLBProp-putref_Symbol(pFormatTxtSym);81. pGeoFeatLyr-put_DisplayAnnotation(VARIANT_TRUE);/显示标注82.83. IActiveViewPtr pAV=m_ctrlMap.GetActiveView();84. pAV-Refresh();85. 复制代码 渲染图层渲染前:渲染后:1. void CAOTestView:OnCartoRender()2. 3. / TODO: Add your command handler code here4.5. HRESULT hr;6. IActiveViewPtr ipAV=m_ctrlMap.GetActiveView();7. IMapPtr ipMap=m_ctrlMap.GetMap();8. ILayerPtr ipLyr;9.10. hr=ipMap-get_Layer(0,&ipLyr);/图层要点状的11. if (FAILED(hr)12. return ;13.14. /简单渲染15. ISimpleRendererPtr ipSimpleRnder;16. IFeatureRendererPtr ipRnder;17. IGeoFeatureLayerPtr ipGeoFeaLyr;18.19. if (ipGeoFeaLyr=ipLyr)=NULL)20. return ;21. hr=ipGeoFeaLyr-get_Renderer(&ipRnder);22. if (ipSimpleRnder=ipRnder)=NULL)23. 24. hr=ipSimpleRnder.CreateInstance(CLSID_SimpleRenderer);25. if(FAILED(hr)26. return ;27. ipRnder=ipSimpleRnder;28. 29.30.31. /创建一个简单的点状符号32. ISimpleMarkerSymbolPtr ipSymbol(CLSID_SimpleMarkerSymbol);33.34. IColorPtr ipColor;35. hr=ipSymbol-get_Color(&ipColor);36. if(FAILED(hr)37. return ;38. hr=ipColor-put_RGB(RGB(255,0,0);/红色39. if(FAILED(hr)40. return ;41. hr=ipSymbol-put_Color(ipColor);42. if(FAILED(hr)43. return ;44. hr=ipSymbol-put_Style(esriSMSCircle);/圆形45. if(FAILED(hr)46. return ;47.48. /设置渲染49. hr=ipSimpleRnder-putref_Symbol(ISymbolPtr)ipSymbol);50. if(FAILED(hr) return ;51. hr=ipSimpleRnder-put_Label(_bstr_t)CSU_DXC);52. if(FAILED(hr) return ;53. hr=ipGeoFeaLyr-putref_Renderer(ipRnder);54. if(FAILED(hr) return ;55.56. hr=ipAV-ContentsChanged();57. hr=ipAV-Refresh();58. if(FAILED(hr) return ;59. 复制代码本帖最后由 dxcgis 于 2008-7-31 17:16 编辑AOTest_StyleManager.JPG(61.55 KB)StyleManager ArcMap中的样式管理器2 VC+AE系列 实现要素的编辑、移动、删除等功能 具体操作步骤:一、选取要素。 通过鼠标在MapControl中拉框选取要素(同时按住shift键)。二、进行编辑、移动、删除操作。 编辑:1、在MapControl中双击,弹出对话框,对话框默认显示要素原值。2、在对话框中输入要素的新值。3、 单击OK完成编辑。 移动:选中要素后,按住鼠标拖动到合适的位置即可。 删除:选中要素后,按Delete键删除要素。定义变量BOOLm_bMove;BOOLm_bSel;IScreenDisplayPtr ipDisp;IActiveViewPtr m_pAV;IMapPtrm_ipMap;IFeatureLayerPtrm_ipFeatLyr;IMovePointFeedbackPtr m_ipMPFdbk; /移动点FeedbackINewEnvelopeFeedbackPtr m_ipNEFdbk;/新矩形框FeedbackIFeaturePtr m_ipCurFeat;初始化设置(可在相应的菜单事件中添加)m_pAVm_ctrlMap.GetActiveView();m_ipMap=m_ctrlMap.GetMap();/取得图层ILayerPtr ipLayer ;m_ipMap-get_Layer(0,&ipLayer)
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号