Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am writing a small application that allows the user to click on the map, and it will create 3 buffers (these are graphics using the IElement interface) at specified distances. What I want to do is if there are buffers on the map from the previous click, and the user clicks on the map to create another set of buffers, delete the oldest set of buffers (which are graphics) So in essence at anyone time there should only be 3 buffers on the map.

Has anyone got any ideas on the best way to do this?

Thanks

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can delete graphics through the IGraphicsContainer interface, either DeleteElements or DeleteAllElements method. See sample code below.

Delete Graphics Refresh Active Snippet

Here is a Delete Graphic by Name VBA sample.

Public Sub DeleteGraphicsByName(ByVal pMxDoc As IMxDocument, ByVal sElementName As String, Optional ByVal bRefresh As Boolean = False)

    'Delete the named graphics from the gra container
    Dim pGraCon As IGraphicsContainer
    Dim pElementProp As IElementProperties
    Dim pElement As IElement

    ' Get the graphics container
    pGraCon = pMxDoc.FocusMap
    pGraCon.Reset()

    'Search for and delete the previous graphic by name
    pElementProp = pGraCon.Next
    Do Until pElementProp Is Nothing
      If pElementProp.Name = sElementName Then
        pElement = pElementProp
        pGraCon.DeleteElement(pElement)
      End If
      pElementProp = pGraCon.Next
    Loop

    If bRefresh Then
      pMxDoc.ActiveView.PartialRefresh(esriViewGraphics, Nothing, Nothing)
    End If

  End Sub
share|improve this answer
    
Thanks, got it working. –  Halil Siddique Jun 29 '12 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.