Select to view content in your preferred language

Help How to zoom to a specific Object

703
2
08-30-2010 11:52 AM
AlejandroMorales
Emerging Contributor
Hi guys,
I was wondering if someone knows how to zoom in to a specific object. p.e. If I have a car layer with 10 cars in it, every car has its own ID (from 1 to 10), what I want it's to zoom it to a specific car ID, let's say 7 so I want the map makes zoom to the car with the ID = 7.

It's that possible? If it is, how can I do it?

Thanks
Alex,
0 Kudos
2 Replies
RiverTaig1
Deactivated User
This VBA code should point you in the right direction. The function ZoomToFeature takes the name of the FeatureClass (e.g. cars) and an ObjectID, and then zooms to that feature. If the feature class is a point feature, you need to buffer the geometry of the feature (you can't zoom to a point).  Good luck.

Private Sub Test()
    ZoomToFeature "AnchorGuy", 6205
End Sub

Private Function ZoomToFeature(FeatureClassName As String, oid As Long) As IFeatureClass
Dim mxDoc As IMxDocument
Set mxDoc = ThisDocument
Dim enLay As IEnumLayer
Set enLay = mxDoc.FocusMap.Layers(, True)
Dim lay As ILayer
Set lay = enLay.Next
Do While Not lay Is Nothing
    If TypeOf lay Is IFeatureLayer Then
        Dim fl As IFeatureLayer
        Set fl = lay
        Dim ds As IDataset
        Set ds = fl.FeatureClass
        If (ds.Name = FeatureClassName) Then
            Dim fc As IFeatureClass
            Set fc = ds
            Dim fe As IFeature
            Set fe = fc.GetFeature(oid)
            Dim topOp As ITopologicalOperator
            Set topOp = fe.ShapeCopy
            Dim bufGeom As IGeometry
            Set bufGeom = topOp.Buffer(100)
            mxDoc.ActiveView.Extent = bufGeom.Envelope
            mxDoc.ActiveView.Refresh
        End If
    End If
    Set lay = enLay.Next
Loop
End Function


Hi guys,
I was wondering if someone knows how to zoom in to a specific object. p.e. If I have a car layer with 10 cars in it, every car has its own ID (from 1 to 10), what I want it's to zoom it to a specific car ID, let's say 7 so I want the map makes zoom to the car with the ID = 7.

It's that possible? If it is, how can I do it?

Thanks
Alex,
0 Kudos
AlejandroMorales
Emerging Contributor
Steve, thanks for your help,
Would  you have it in javascript code?
0 Kudos