gsinner

Problem setting map extents for map frame in page layout control

Discussion created by gsinner on Aug 24, 2011
I'm working on an application that incorporates a lot of the "Synchronized MapControl and PageLayoutControl application" sample (found here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000001w4000000.htm ).  This is the description of the sample:

[INDENT]This sample demonstrates synchronization of a MapControl and a PageLayoutControl in one application. This means that, as in ArcMap, you can switch between the two views and maintain the scale and extent[/INDENT]

The issue that I'm having is that the map in the page layout does NOT maintain both the scale AND extent (not sure how it really can do both!).  Take a map that you originally create in ArcMap with a roughly square map frame on the page layout.  Load the map into the application built by the sample, and maximize the application window.  If you've got a monitor like mine, the map will now be wider than it is tall.  Switch the Layout tab and much of the map that you were viewing on the Map tab isn't visible on the Layout tab.

Our users are most concerned about maintaining the extent, i.e., if you can see it on the map in the map control, you should be able to see it on the map on the page control.  It doesn't matter if the extents of the map on the page are larger in order to accomodate different aspect ratios of the map control vs. the layout's map frame.  For example, if the application on my monitor has a more horizontal aspect ratio but the page layout's map frame is square, I would expect to get "extra" areas at the top and bottom of the map in the page because the page layout would want to fit the maximum dimension of the map view (width) into the layout frame (square), and fill the height as necessary to fill the square frame.  Take the same map into ArcMap and toggle between map and layout views, and you'll see that ArcMap is honoring the extents - that's what we're after too.

I can't seem to find the right way to set the extents of the map frame on the page to get the desired results as described above.  I tried this:

[INDENT]                IGraphicsContainer graphicsContainer = m_pageLayoutControl.PageLayout as IGraphicsContainer;
                if ( graphicsContainer != null )
                {
                    graphicsContainer.Reset();
                    IElement element = null;
                    while ( ( element = graphicsContainer.Next() ) != null )
                    {
                        if ( element is IMapFrame )
                        {
                            ESRI.ArcGIS.Carto.IMap map = ( element as IMapFrame ).Map;
                            IActiveView mapview = map as IActiveView;
                            mapview.Extent = m_mapControl.Extent;
                            mapview.Refresh();

                            break;
                        }
                    }
                }
[/INDENT]

It doesn't work because the extents reported by the m_mapControl and the mapview (from the IMapFrame) are the same.  Yet visually the maps on the map and in the layout control's map frame have very different extents (but appear to have the same scale).

I'd greatly appreciate any suggestions for how to get the map EXTENTS to be honored...

Thank you in advance!

Gary

Outcomes