阅读:1949回复:3
怎样给图层显示注记?
指定某一字段为注记文本内容,如何显示在图层中?
|
|
1楼#
发布于:2005-07-04 11:06
<STRONG>Description:</STRONG> <BR><BR><TEXT>This sample uses a UIToolControl to add a text label on the focus map. For simplicity sake, the label string is hard-coded to "X marks the spot."
<br>A map label is a text element that is added to a map's graphics layer. Text elements can also be added to the page layout's graphics layer - see the <a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\Samples.chm::/ArcMap/AddTextElement.htm" target="_blank" >'Add Text to Layout'</A> tip for an example of this. For example, we may be labelling a feature on a map in the first case, and giving the entire map a name in layout case. </TEXT> <TABLE bgColor=#edf6fd> <TR> <TD><B>Products:</B> <DIV 15px; POSITION: relative"> <p>ArcView: VBA</DIV> <p> <p><B>Platforms: </B>Windows <p><B>Minimum ArcGIS Release: </B>9.0</TD></TR></TABLE><BR><B>How to use:</B> <DIV> <OL> <LI>Add a new UIToolControl to any toolbar. <LI>Paste the code into the UIToolControl's mouse down event. <LI>Mind the name of the control, the sample assumes it is UIToolControl1. <LI>Modify the text string as desired. <LI>Completely shut down VBA so mouse events fire. <LI>Select the tool and click somewhere on the focus map to add the label. </LI></OL></DIV> <DIV><PRE> <DEVELOPENV>'Adds a text element (label) to the focus map's graphics layer Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long) Dim pMxDoc As IMxDocument Dim pGraphicsContainer As IGraphicsContainer Dim pActiveView As IActiveView Dim pTextElement As ITextElement Dim pElement As IElement Set pMxDoc = Application.Document Set pGraphicsContainer = pMxDoc.FocusMap Set pActiveView = pMxDoc.FocusMap Set pTextElement = New TextElement Set pElement = pTextElement pTextElement.Text = "X marks the spot" pElement.Geometry = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y) pGraphicsContainer.AddElement pTextElement, 0 pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing End Sub </DEVELOPENV></PRE></DIV> |
|
|
2楼#
发布于:2005-07-04 11:09
<P>针对图层标注,下面贴出一个函数,供参考接口用,具体可以查查帮助</P>
<P>Public Function f_Label_MakeLabels(pGeoLayer As IGeoFeatureLayer, pLabelField As String, BOLP As IBasicOverposterLayerProperties, Optional pLabelStyle As ILabelStyle = Nothing)<BR>On Error GoTo ErrHld<BR> If pLabelStyle Is Nothing Then<BR> <BR> BOLP.BufferRatio = 0<BR> BOLP.FeatureWeight = 0<BR> BOLP.LabelWeight = 3<BR> BOLP.GenerateUnplacedLabels = False<BR> <BR> Dim LLPP As ILineLabelPlacementPriorities<BR> Set LLPP = New LineLabelPlacementPriorities<BR> <BR> With LLPP<BR> .AboveAfter = 3<BR> .AboveAlong = 1<BR> .AboveBefore = 3<BR> .AboveEnd = 3<BR> .AboveStart = 3<BR> .BelowAfter = 3<BR> .BelowAlong = 3<BR> .BelowBefore = 3<BR> .BelowEnd = 3<BR> .BelowStart = 3<BR> .CenterAfter = 3<BR> .CenterAlong = 3<BR> .CenterBefore = 3<BR> .CenterEnd = 3<BR> .CenterStart = 3<BR> End With<BR> <BR> Dim LLP As ILineLabelPosition<BR> Set LLP = New LineLabelPosition<BR> LLP.ProduceCurvedLabels = False<BR> With LLP<BR> .Above = True<BR> .AtEnd = False<BR> .AtStart = False<BR> .Below = False<BR> .InLine = False<BR> .Left = False<BR> .OnTop = False<BR> .Right = False<BR> '** These Are Exclusive<BR> .Parallel = True<BR> .Perpendicular = False<BR> .Horizontal = False<BR> End With<BR> <BR> <BR> Dim PPP As IPointPlacementPriorities<BR> Set PPP = New PointPlacementPriorities<BR> With PPP<BR> .AboveCenter = 2<BR> .AboveLeft = 3<BR> .AboveRight = 1<BR> .BelowCenter = 3<BR> .BelowLeft = 3<BR> .BelowRight = 3<BR> .CenterLeft = 3<BR> .CenterRight = 2<BR> End With<BR> <BR> BOLP.PointPlacementOnTop = True<BR> BOLP.LineLabelPlacementPriorities = LLPP<BR> BOLP.LineLabelPosition = LLP<BR> BOLP.PointPlacementPriorities = PPP<BR> <BR> '添加文字注记<BR> Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection<BR> Dim aLELayerProps As ILabelEngineLayerProperties<BR> <BR> Dim pAnnotateLayerProperties As IAnnotateLayerProperties<BR> <BR> Set pAnnoLayerPropsColl = pGeoLayer.AnnotationProperties<BR> pAnnoLayerPropsColl.QueryItem 0, aLELayerProps<BR> Set pAnnotateLayerProperties = aLELayerProps<BR> pAnnotateLayerProperties.AnnotationMaximumScale = m_ScaleMax<BR> pAnnotateLayerProperties.AnnotationMinimumScale = m_ScaleMin</P> <P> With aLELayerProps<BR> .Expression = pLabelField<BR> .IsExpressionSimple = m_bIsExpressionSimple</P> <P> Dim i_AnnoVBScriptEngine As IAnnotationExpressionEngine<BR> Set i_AnnoVBScriptEngine = New AnnotationVBScriptEngine</P> <P> Set .ExpressionParser = i_AnnoVBScriptEngine<BR> Set .BasicOverposterLayerProperties = BOLP<BR> <BR> If Not m_Symbol Is Nothing Then<BR> Set .Symbol = m_Symbol<BR> End If<BR> End With<BR> End If</P> <P> pGeoLayer.DisplayAnnotation = True<BR> Exit Function<BR>ErrHld:<BR> MsgBox Err.Description ; " On f_Label_MakeLabels"<BR>End Function</P> |
|
|
3楼#
发布于:2005-07-04 17:31
<P>谢谢总统,我试试</P>
|
|