Search in sources :

Example 1 with RectangularMapTile

use of com.revolsys.gis.grid.RectangularMapTile in project com.revolsys.open by revolsys.

the class GridLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final GridLayer layer) {
    try {
        final double scaleForVisible = viewport.getScaleForVisible();
        if (layer.isVisible(scaleForVisible)) {
            final BoundingBox boundingBox = viewport.getBoundingBox();
            final RectangularMapGrid grid = layer.getGrid();
            final List<RectangularMapTile> tiles = grid.getTiles(boundingBox);
            final Graphics2D graphics = viewport.getGraphics();
            if (graphics != null) {
                final Font font = graphics.getFont();
                for (final RectangularMapTile tile : cancellable.cancellable(tiles)) {
                    final BoundingBox tileBoundingBox = tile.getBoundingBox();
                    final BoundingBox intersectBoundingBox = boundingBox.intersection(tileBoundingBox);
                    if (!intersectBoundingBox.isEmpty()) {
                        final GeometryFactory geometryFactory = viewport.getGeometryFactory();
                        final Polygon polygon = tile.getPolygon(geometryFactory, 50);
                        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
                            viewport.drawGeometryOutline(polygon, this.geometryStyle);
                        }
                        try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
                            viewport.drawText(tile, polygon, this.textStyle);
                        }
                    }
                    graphics.setFont(font);
                }
            }
        }
    } catch (final IllegalArgumentException e) {
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) RectangularMapTile(com.revolsys.gis.grid.RectangularMapTile) Font(java.awt.Font) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid) Graphics2D(java.awt.Graphics2D)

Example 2 with RectangularMapTile

use of com.revolsys.gis.grid.RectangularMapTile in project com.revolsys.open by revolsys.

the class GridLayer method zoomToSheet.

public void zoomToSheet(final String mapsheet) {
    final Project project = getProject();
    if (project != null) {
        if (Property.hasValue(mapsheet)) {
            final MapPanel map = getMapPanel();
            final RectangularMapGrid grid = getGrid();
            final String gridName = grid.getName();
            try {
                final RectangularMapTile mapTile = grid.getTileByName(mapsheet);
                final BoundingBox boundingBox = mapTile.getBoundingBox();
                project.setViewBoundingBox(boundingBox);
            } catch (final Throwable e) {
                final String message = "Invalid mapsheet " + mapsheet + " for " + gridName;
                JOptionPane.showMessageDialog(map, message);
            } finally {
                final String preferenceName = CaseConverter.toCapitalizedWords(gridName) + "Mapsheet";
                PreferencesUtil.setString(getClass(), preferenceName, mapsheet);
            }
        }
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) RectangularMapTile(com.revolsys.gis.grid.RectangularMapTile) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)2 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)2 RectangularMapTile (com.revolsys.gis.grid.RectangularMapTile)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Polygon (com.revolsys.geometry.model.Polygon)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 MapPanel (com.revolsys.swing.map.MapPanel)1 Project (com.revolsys.swing.map.layer.Project)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1