1

I want to change the extent (area of interest of the view of the focus map) to the bounding box of the selected features. I use the code below ( I wrote lots of classes for my project and i'm using them in this code) I checked and I'm pretty sure that the envelope in the last line is correct and it represents the extent of selected features. but when i set the area of interest of the focus map to it, nothing happens and the view doesn't zoom to the selected area. can anyone help?

    private void button4_Click(object sender, EventArgs e)
    {
        IMap map = mxdoc.FocusMap;
        gl.map = map;
        ILayer layer = gl.getSelectedLayer(comboBox1.SelectedItem.ToString());
        List<IFeature> features = new List<IFeature>();
        SF.featureLayer = layer as IFeatureLayer;
        features = SF.GetSelectedFeatures();
        Z.features = features;
        IEnvelope envelope = Z.ExtentOfSelected();
        map.AreaOfInterest = envelope;

    }
3

1 Answer 1

2

Try this, use IActiveView interface to set the current view of map

private void button4_Click(object sender, EventArgs e)
    {
        IMap map = mxdoc.FocusMap;

        // get activview of the map
        IActiveView activeView = (IActiveView)map;

        gl.map = map;
        ILayer layer = gl.getSelectedLayer(comboBox1.SelectedItem.ToString());
        List<IFeature> features = new List<IFeature>();
        SF.featureLayer = layer as IFeatureLayer;
        features = SF.GetSelectedFeatures();
        Z.features = features;
        IEnvelope envelope = Z.ExtentOfSelected();

        // expand the envelope by 1.2 factor
        envelope.Expand(1.2, 1.2, true);
        activeView.Extent = envelope;
        activeView.Refresh();


    }
0

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