0

I need to export a map for several extents (typically states or regions of a country) to PDF. I have a MXD document that I open in an ArcObject console program.

I manage to set the PageLayout to A2 form and change the orientation of the page depending on my extent.

Nevertheless, I would like to set the data frame to fill my PageLayout with a given margin (1cm for example) between the PageLayout and the data frame, and then change the map extent to my region extent. How can I do that please ?

My actual code is

                    IPageLayout pageLayout = (IPageLayout)activeView;
                IPage page = pageLayout.getPage();

                if(regionExtent.getHeight() > regionExtent.getWidth()) {
                    log.info("Orientation : Portrait");
                    page.setOrientation((short) 1);
                } else {
                    log.info("Orientation : Paysage");
                    page.setOrientation((short) 2);
                }
                log.info("Format : A2");
                page.setFormID(esriPageFormID.esriPageFormA2);
                page.setUnits(esriUnits.esriCentimeters);
                page.setStretchGraphicsWithPage(true);
                pageLayout.zoomToWhole();
                pageLayout.setAlignToMargins(true);

                IMap map = activeView.getFocusMap();
                // here I have to get the map fill the pageLayout
0

Filling the map layout with you data extent you could just zoom to the layer. If there is a certain feature within the layer that defines the extent than you could use a query filter to select that feature than zoom to the selected feature. A general web search should give you some leads on zooming to layers, setting query filters, or zooming to selected features.

  • I can already get the extent of a region and zoom to it with map.setExtent(regionExtent). The problem is that the map don't fill the page layout. – superrache Feb 18 '14 at 15:39
  • @superrache, I thought that was part of your question, "then change the map extent to my region extent. How can I do that please"? You may want to edit your question. – artwork21 Feb 18 '14 at 16:13
0

I finally found a solution: As the PageLayout is a GraphicsContainer, I can access every IElement of it, included the map as an IElement or IMapFrame. Then I change the mapFrame dimensions and align it with my page margins, before zooming the map to the region extent :

IGraphicsContainer graphicsContainer = (IGraphicsContainer)pageLayout;
    graphicsContainer.reset();
    IElement mapElement = null;
    while(!(mapElement instanceof IMapFrame)) {
        mapElement = graphicsContainer.next();
    }

    Envelope mapElementEnvelope = new Envelope();
    mapElementEnvelope.setXMin(margin);
    mapElementEnvelope.setYMin(margin);

    if(extent.getHeight() > extent.getWidth()) {
        log.info("Orientation : Portrait");
        page.setOrientation((short) 1);
        mapElementEnvelope.setXMax(paperWidth - margin);
        mapElementEnvelope.setYMax(paperHeight - margin);
    } else {
        log.info("Orientation : Paysage");
        page.setOrientation((short) 2);
        mapElementEnvelope.setXMax(paperHeight - margin);
        mapElementEnvelope.setYMax(paperWidth - margin);
    }

    mapElement.setGeometry(mapElementEnvelope);

    pageLayout.zoomToWhole();
    pageLayout.setAlignToMargins(true);

    double w = extent.getWidth();
    double h = extent.getHeight();
    extent.expand(expandExtentPercents * w, expandExtentPercents * h, false);
    ((IActiveView)map).setExtent(extent);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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