How to set the Dataframe extent in the page layout view ?

1071
5
05-13-2012 11:38 PM
ShreyPrasad
New Contributor
Hi All,

    In my page layout view I have to separate data frame both showing some data. When ever I am trying to set the extent of the data frame it is not setting as desired.
For example  I have to polygon feature in the above data frame I want to show the extent of the 1st  polygon feature extent and in the next data frame I want to show the extent of the next selected feature- polygon, but that data frame is always showing some random extent .I am not getting how to solve this.Below is the code which I am u sing for  the same.

Code :
  public static void RotateDataframe(double angle, IFeature pFeature, int currentmap)
        {

            IDisplayTransformation pDispTrans = null;
            IActiveView pActiveview = null;
            IEnvelope pEnvele = new EnvelopeClass();
            IPageLayout pLayout = null;
            IGraphicsContainer pGraphicsContainer = null;
            IMapFrame pMapFrame = null;
          
            IEnvelope pEnv = null;
            IEnvelope overLappingExtent = null;
            try
            {



                pActiveview = pMxDocument.ActiveView.FocusMap as IActiveView;

                pActiveview.Refresh();
             
                pDispTrans= pActiveview.ScreenDisplay.DisplayTransformation as IDisplayTransformation;

                pDispTrans.Rotation = angle;
               pActiveview.Extent = pFeature.Extent;

              
                pActiveview.Refresh();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
0 Kudos
5 Replies
johannesuhl
New Contributor
Hey Shrey,
I am running into similar problems. Did you find a solution for your problem?
I know how to define the data frame dimensions (via the IGraphicsContainer) but I would like to set the data frame extent to a certain region defined by lower left and upper right coordinates.
Thank you!!
Regards,
Johannes
0 Kudos
johannesuhl
New Contributor
just found a workaround:

I switch to the dataView and set the center point of the extent there (using the following code), then switch back to the LayoutView:

            Dim centerPoint As IPoint
            centerPoint = New ESRI.ArcGIS.Geometry.Point
            centerPoint.PutCoords((left_x + right_x) / 2, (upper_y + lower_y) / 2)
            Dim activeView As IActiveView
            activeView = pMxDoc.ActiveView
            ' get the active view�??s extent
            Dim ext As IEnvelope
            ext = activeView.Extent
            ' set extent center point:
            ext.CenterAt(centerPoint)
            ' set the extent
            activeView.Extent = ext
            activeView.Refresh()

Cheers,
Johannes
0 Kudos
NeilClemmons
Regular Contributor III
just found a workaround:

I switch to the dataView and set the center point of the extent there (using the following code), then switch back to the LayoutView:

            Dim centerPoint As IPoint
            centerPoint = New ESRI.ArcGIS.Geometry.Point
            centerPoint.PutCoords((left_x + right_x) / 2, (upper_y + lower_y) / 2)
            Dim activeView As IActiveView
            activeView = pMxDoc.ActiveView
            ' get the active view�??s extent
            Dim ext As IEnvelope
            ext = activeView.Extent
            ' set extent center point:
            ext.CenterAt(centerPoint)
            ' set the extent
            activeView.Extent = ext
            activeView.Refresh()

Cheers,
Johannes


There's no need to switch to data view in order to run this code.  If you change this line:
activeView = pMxDoc.ActiveView

To this:
activeView = pMxDoc.FocusMap

then it will work the same in layout view.  An active view can be either a map or a page layout.  The ActiveView property returns whichever one is appropriate for the current view.  If that's not what you want, then you set your active view reference using either the FocusMap or PageLayout properties.  Of course, if your layout contains multiple data frames and you want the map inside a data frame that is not the active data frame then you will need to get the frame element from the graphics container and get your map reference from that element.
0 Kudos
ShreyPrasad
New Contributor
Hi Johannes,

  I have used the following code andgot the end result what I was expecting hope it can be of any help to you.
  Code :
     public static void RotateDataframe(double angle, IFeature pFeature, int currentmap)
        {

            IDisplayTransformation pDispTrans = null;
            IActiveView pActiveview = null;
            IEnvelope pEnvele = new EnvelopeClass();
            IPageLayout pLayout = null;
            IGraphicsContainer pGraphicsContainer = null;
            IMapFrame pMapFrame = null;
            IDataFrameAreaOfInterestDialog pDataFrameAreaOfInterestDialog = null;
            IEnvelope pEnv = null;
            IEnvelope overLappingExtent = null;
            try
            {

                pActiveview = pMxDocument.ActiveView.FocusMap as IActiveView;
                pActiveview.Refresh();
                pDispTrans = pActiveview.ScreenDisplay.DisplayTransformation as IDisplayTransformation;
                pDispTrans.VisibleBounds = pFeature.Shape.Envelope;


           
                pDispTrans.Rotation = angle;
               
               pDispTrans.ScaleRatio = 95203;//1:50000 scale on the map
              
                pActiveview.Refresh();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


I have put number regarding the my template.Please change accordingly.
0 Kudos
johannesuhl
New Contributor
thank everybody for the answers!
0 Kudos