RubberCircle Example

  This sample shows how to create a tool which allows the user to digitize a new Circle using the RubberCircle coclass and IRubberBand interface. The RubberBand allows the user to drag out a circle from the center until the mouse button is released. A procedure is then called which takes the result of the rubberband operation (ICircularArc) and creates a new polygon object. The polygon is then used to create a new CircleElement which is in turn added to the Map's BasicGraphicsLayer for display.

How to use:

  1. In ArcMap, select Tools | Customize...
  2. Select the Commands tab and scroll down to UIControls in the left pane.
  3. Click NewUIControl...
  4. In the dialog which appears select UIToolControl and then click Create.
  5. Drag the new tool which appears in the right pane onto a toolbar of your choosing.
  6. Right-click over your tool on the toolbar and select View Source.
  7. Copy and paste the code below into the VBA code pane which appears.
  8. Close the VBA Window and return to the ArcMap Window.
  9. Now select your tool from the toolbar and digitize an Circle. Click the mouse where the center of the circle is to be and then, holding down the mouse button, move the mouse until the desired radius is reached. Releasing the mouse button completes the operation and creates a new CircleElement.
						Option Explicit
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 pCircArc As ICircularArc
  Dim pRubberCirc As IRubberBand
  
  ' QI for the MXDocument interface
  Set pMXDoc = ThisDocument
  
  ' Create a new RubberCircle
  Set pRubberCirc = New RubberCircle
  ' Return a new CircularArc from the tracker object using TrackNew
  Set pCircArc = pRubberCirc.TrackNew(pMXDoc.ActiveView.ScreenDisplay, Nothing)
  
  ' Call a function that converts the ICircularArc into a Polygon and 
  ' adds a new element to the ActiveView's BasicGraphicsLayer
  AddCreateElement pCircArc, pMXDoc.ActiveView
  
  ' Refresh the ActiveView
  pMXDoc.ActiveView.Refresh
End Sub

Private Sub AddCreateElement(pCircArc As ICircularArc, pAV As IActiveView)
' Takes an ICircularArc and IActiveView and creates a CircleElement 
' in the ActiveView's BasicGraphicsLayer
  Dim pElemFillShp As IFillShapeElement
  Dim pElem As IElement
  Dim pGraCont As IGraphicsContainer
  Dim pSFSym As ISimpleFillSymbol
  Dim pRGB As IRgbColor
  Dim pSegColl As ISegmentCollection
  
  ' Create a new Polygon object and access the ISegmentCollection interface 
  ' to add a segment
  Set pSegColl = New Polygon
  pSegColl.AddSegment pCircArc
  
  ' Create a new circleelement and use the IElement interface to set the 
  ' its Geometry
  Set pElem = New CircleElement
  pElem.Geometry = pSegColl
  
  ' QI for the IFillShapeElement interface so that the Symbol property can be set
  Set pElemFillShp = pElem
    
  ' Create a new RGBColor
  Set pRGB = New RgbColor
  With pRGB
    .Red = 198
    .Green = 255
    .Blue = 214
  End With
    
  ' Create a new SimpleFillSymbol and set its Color and Style
  Set pSFSym = New SimpleFillSymbol
  pSFSym.Color = pRGB
  pSFSym.Style = esriSFSSolid
  pElemFillShp.Symbol = pSFSym
  
  ' QI for the IGraphicsContainer interface from the IActiveView, allows 
  ' access to the BasicGraphicsLayer
  Set pGraCont = pAV
  'Add the element at Z order zero
  pGraCont.AddElement pElemFillShp, 0
  
End Sub

				

posted on 2006-06-14 18:09 简单就是美 阅读(302) 评论(0)  编辑  收藏 所属分类: ArcGIS开发

导航

统计

常用链接

随笔分类(95)

随笔档案(91)

新闻分类(6)

新闻档案(15)

积分与排名

最新评论

阅读排行榜