3

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

asked Jun 29, 2012 at 10:50

1 Answer 1

5

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
answered Jun 29, 2012 at 12:10
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.