如何用ArcGIS Engine+C#net实现注记功能
1个回答
2015-01-10
展开全部
以前用VC写的代码。。自己翻译吧。
具体参数是 pLayer 标注图层,pFontDisp 标注字体,pColor标注字体的颜色,
bstrExpression 表示你用哪个字段进行标注 m_bViewLabel 表示是否显示标注。
BOOL CDGGisFrameView::LabelLayer(ILayerPtr pLayer, IFontDispPtr pFontDisp, IColorPtr pColor, CComBSTR bstrExpression,BOOL m_bViewLabel)
{
if (pLayer==NULL)
{
return FALSE;
}
if (bstrExpression=="")
{
return FALSE;
}
IFeatureLayerPtr pFeatureLayer;
IGeoFeatureLayerPtr pGeoFeatureLayer;
pFeatureLayer=(IFeatureLayerPtr)pLayer;
pGeoFeatureLayer=(IGeoFeatureLayerPtr)pFeatureLayer;
ITrackCancelPtr pTrackCancel(CLSID_CancelTracker);
IActiveViewPtr pView=m_wndViewPage2D.m_ctrlMap.GetMap();
IScreenDisplayPtr pScreenDisplay;
pView->get_ScreenDisplay(&pScreenDisplay);
IDisplayPtr pDisplay=(IDisplayPtr)pScreenDisplay;
if (m_bViewLabel==FALSE)
{
pGeoFeatureLayer->put_DisplayAnnotation(VARIANT_FALSE);
pView->Refresh();
return TRUE;
}
else
{
pGeoFeatureLayer->put_DisplayAnnotation(VARIANT_TRUE);
}
IAnnotateLayerPropertiesPtr pALP(CLSID_LabelEngineLayerProperties);
pALP->putref_FeatureLayer(pGeoFeatureLayer);
IEnvelopePtr pEnv;
pEnv=m_wndViewPage2D.m_ctrlMap.GetExtent();
pALP->put_Extent(pEnv);
ILabelEngineLayerPropertiesPtr pLELP;
pLELP=pALP;
ITextSymbolPtr pTextSymbol;
pLELP->get_Symbol(&pTextSymbol);
if (pColor!=NULL)
{
IRgbColorPtr pRgbColor(CLSID_RgbColor);
pRgbColor=pColor;
pTextSymbol->put_Color(pColor);
}
if (pFontDisp!=NULL)
{
pTextSymbol->put_Font(pFontDisp);
}
pLELP->put_Expression((BSTR)bstrExpression);
IAnnotateLayerPropertiesCollectionPtr pCol;
pGeoFeatureLayer->get_AnnotationProperties(&pCol);
pCol->Clear();
pCol->Add(pALP);
HRESULT hr=pGeoFeatureLayer->Draw((esriDrawPhase)esriDPAnnotation,pDisplay,pTrackCancel);
if (FAILED(hr))
{
return FALSE;
}
pView->Refresh();
return TRUE;
}
具体参数是 pLayer 标注图层,pFontDisp 标注字体,pColor标注字体的颜色,
bstrExpression 表示你用哪个字段进行标注 m_bViewLabel 表示是否显示标注。
BOOL CDGGisFrameView::LabelLayer(ILayerPtr pLayer, IFontDispPtr pFontDisp, IColorPtr pColor, CComBSTR bstrExpression,BOOL m_bViewLabel)
{
if (pLayer==NULL)
{
return FALSE;
}
if (bstrExpression=="")
{
return FALSE;
}
IFeatureLayerPtr pFeatureLayer;
IGeoFeatureLayerPtr pGeoFeatureLayer;
pFeatureLayer=(IFeatureLayerPtr)pLayer;
pGeoFeatureLayer=(IGeoFeatureLayerPtr)pFeatureLayer;
ITrackCancelPtr pTrackCancel(CLSID_CancelTracker);
IActiveViewPtr pView=m_wndViewPage2D.m_ctrlMap.GetMap();
IScreenDisplayPtr pScreenDisplay;
pView->get_ScreenDisplay(&pScreenDisplay);
IDisplayPtr pDisplay=(IDisplayPtr)pScreenDisplay;
if (m_bViewLabel==FALSE)
{
pGeoFeatureLayer->put_DisplayAnnotation(VARIANT_FALSE);
pView->Refresh();
return TRUE;
}
else
{
pGeoFeatureLayer->put_DisplayAnnotation(VARIANT_TRUE);
}
IAnnotateLayerPropertiesPtr pALP(CLSID_LabelEngineLayerProperties);
pALP->putref_FeatureLayer(pGeoFeatureLayer);
IEnvelopePtr pEnv;
pEnv=m_wndViewPage2D.m_ctrlMap.GetExtent();
pALP->put_Extent(pEnv);
ILabelEngineLayerPropertiesPtr pLELP;
pLELP=pALP;
ITextSymbolPtr pTextSymbol;
pLELP->get_Symbol(&pTextSymbol);
if (pColor!=NULL)
{
IRgbColorPtr pRgbColor(CLSID_RgbColor);
pRgbColor=pColor;
pTextSymbol->put_Color(pColor);
}
if (pFontDisp!=NULL)
{
pTextSymbol->put_Font(pFontDisp);
}
pLELP->put_Expression((BSTR)bstrExpression);
IAnnotateLayerPropertiesCollectionPtr pCol;
pGeoFeatureLayer->get_AnnotationProperties(&pCol);
pCol->Clear();
pCol->Add(pALP);
HRESULT hr=pGeoFeatureLayer->Draw((esriDrawPhase)esriDPAnnotation,pDisplay,pTrackCancel);
if (FAILED(hr))
{
return FALSE;
}
pView->Refresh();
return TRUE;
}
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询