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 an application where one of the things it does is create a point then creates buffer (which is a graphic) at the specific point, what I want to do is when the buffer has been created, is to zoom to the extent of the buffer.

I have tried the following code but it doesn't seem to work

Dim penv2 As IEnvelope
Set penv2 = New Envelope
Set penv2 = pActiveView.extent
Dim pArea As IArea
Set pArea = pElement.Geometry.Envelope
penv2.CenterAt pArea.Centroid            
pActiveView.Refresh

I've also tried

Dim penv2 As IEnvelope
Set penv2 = pElement.Geometry.Envelope
pActiveView.Extent = penv2 
pActiveView.Refresh 

But nothing happens. Any ideas on where I am going wrong?

Thanks

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

This works for me:

Option Explicit
Sub ZoomToElement()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pGCS As IGraphicsContainerSelect
    Set pGCS = pMxDoc.FocusMap

    If pGCS.ElementSelectionCount <> 1 Then
        Debug.Print "select just one element first"
        Exit Sub
    End If

    Dim pEnv As IEnvelope
    Set pEnv = pGCS.SelectedElement(0).Geometry.Envelope

    Dim pAV As IActiveView
    Set pAV = pMxDoc.FocusMap

    pAV.Extent = pEnv
    pAV.Refresh
End Sub
share|improve this answer
add comment

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.