Search in sources :

Example 11 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class SinglePage method print.

@Override
public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException {
    if (pageIndex == 0) {
        setGraphics((Graphics2D) graphics);
        final int translateX = (int) pageFormat.getImageableX();
        final int translateY = (int) pageFormat.getImageableY();
        graphics.translate(translateX - 1, translateY - 1);
        final Project project = getProject();
        final MapPanel mapPanel = project.getMapPanel();
        final Layer baseMapLayer = mapPanel.getBaseMapLayer();
        render(baseMapLayer);
        render(project);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE;
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) Layer(com.revolsys.swing.map.layer.Layer)

Example 12 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class SaveAsPdf method save.

public static void save() {
    final Project project = Project.get();
    final String directory = "/Users/paustin/Downloads/";
    final File file = new File(directory, project.getName() + ".pdf");
    try {
        final PDDocument document = new PDDocument();
        final Viewport2D viewport = project.getViewport();
        BoundingBox boundingBox = viewport.getBoundingBox();
        final int width = viewport.getViewWidthPixels();
        final int height = viewport.getViewHeightPixels();
        final int srid = boundingBox.getCoordinateSystemId();
        if (srid == 3857) {
            boundingBox = boundingBox.convert(boundingBox.getGeometryFactory().getGeographicGeometryFactory());
        }
        final PDRectangle pageSize = new PDRectangle(width, height);
        final PDPage page = new PDPage(pageSize);
        try (PdfViewport pdfViewport = new PdfViewport(document, page, project, width, height, boundingBox)) {
            final LayerRenderer<? extends Layer> renderer = project.getRenderer();
            renderer.render(pdfViewport);
        }
        document.addPage(page);
        final PDDocumentCatalog catalog = document.getDocumentCatalog();
        final PDMetadata metadata = new PDMetadata(document);
        catalog.setMetadata(metadata);
        // jempbox version
        final XMPMetadata xmp = new XMPMetadata();
        final XMPSchemaDublinCore xmpSchema = new XMPSchemaDublinCore(xmp);
        xmp.addSchema(xmpSchema);
        xmpSchema.setAbout("");
        metadata.importXMPMetadata(xmp);
        document.save(file);
    } catch (final Throwable e) {
        Logs.error(SaveAsPdf.class, "Unable to create PDF " + file, e);
    }
}
Also used : XMPSchemaDublinCore(org.apache.jempbox.xmp.XMPSchemaDublinCore) PDPage(org.apache.pdfbox.pdmodel.PDPage) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog) Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) XMPMetadata(org.apache.jempbox.xmp.XMPMetadata) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) BoundingBox(com.revolsys.geometry.model.BoundingBox) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) File(java.io.File)

Example 13 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class SelectRecordsOverlay method refreshImageSelected.

private GeoreferencedImage refreshImageSelected() {
    final Viewport2D viewport = getViewport();
    if (viewport != null) {
        final int width = viewport.getViewWidthPixels();
        final int height = viewport.getViewHeightPixels();
        if (width > 0 && height > 0) {
            try (final ImageViewport imageViewport = new ImageViewport(viewport, BufferedImage.TYPE_INT_ARGB_PRE);
                BaseCloseable transformCloseable = imageViewport.setUseModelCoordinates(true)) {
                final Graphics2D graphics = imageViewport.getGraphics();
                final Project project = getProject();
                refreshImageRenderer(imageViewport, project);
                refreshImageSelectedAndHighlighted(imageViewport, graphics, project);
                return imageViewport.getGeoreferencedImage();
            }
        }
    }
    return null;
}
Also used : Project(com.revolsys.swing.map.layer.Project) Viewport2D(com.revolsys.swing.map.Viewport2D) BaseCloseable(com.revolsys.io.BaseCloseable) ImageViewport(com.revolsys.swing.map.ImageViewport) Point(com.revolsys.geometry.model.Point) Graphics2D(java.awt.Graphics2D)

Example 14 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class MapPanel method addZoomBookmark.

public void addZoomBookmark() {
    final BoundingBox boundingBox = getBoundingBox();
    if (!boundingBox.isEmpty()) {
        final String name = JOptionPane.showInputDialog(this, "Enter bookmark name", "Add Zoom Bookmark", JOptionPane.QUESTION_MESSAGE);
        if (Property.hasValue(name)) {
            final Project project = getProject();
            project.addZoomBookmark(name, boundingBox);
        }
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 15 with Project

use of com.revolsys.swing.map.layer.Project in project com.revolsys.open by revolsys.

the class MapPanel method showZoomBookmarkMenu.

public void showZoomBookmarkMenu() {
    final BaseJPopupMenu menu = new BaseJPopupMenu();
    menu.addMenuItem("Add Bookmark", "add", this::addZoomBookmark);
    menu.addSeparator();
    final Project project = getProject();
    for (final Entry<String, BoundingBox> entry : project.getZoomBookmarks().entrySet()) {
        final String name = entry.getKey();
        final BoundingBox boundingBox = entry.getValue();
        menu.addMenuItem("Zoom to " + name, "magnifier", () -> zoomToBoundingBox(boundingBox));
    }
    menu.showMenu(this.zoomBookmarkButton, 0, 20);
}
Also used : Project(com.revolsys.swing.map.layer.Project) BoundingBox(com.revolsys.geometry.model.BoundingBox) BaseJPopupMenu(com.revolsys.swing.menu.BaseJPopupMenu)

Aggregations

Project (com.revolsys.swing.map.layer.Project)28 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Viewport2D (com.revolsys.swing.map.Viewport2D)4 MapPanel (com.revolsys.swing.map.MapPanel)3 Point (com.revolsys.geometry.model.Point)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ImageViewport (com.revolsys.swing.map.ImageViewport)2 Layer (com.revolsys.swing.map.layer.Layer)2 LayerGroup (com.revolsys.swing.map.layer.LayerGroup)2 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)2 PageFormat (java.awt.print.PageFormat)2 PrinterException (java.awt.print.PrinterException)2 PrinterJob (java.awt.print.PrinterJob)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Geometry (com.revolsys.geometry.model.Geometry)1 LineString (com.revolsys.geometry.model.LineString)1 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)1 RectangularMapTile (com.revolsys.gis.grid.RectangularMapTile)1