Search in sources :

Example 1 with RectangularMapGrid

use of com.revolsys.gis.grid.RectangularMapGrid 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 RectangularMapGrid

use of com.revolsys.gis.grid.RectangularMapGrid 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)

Example 3 with RectangularMapGrid

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

the class GridLayer method zoomToSheet.

public void zoomToSheet() {
    final LayerGroup project = getProject();
    if (project != null) {
        final MapPanel map = getMapPanel();
        final RectangularMapGrid grid = getGrid();
        final String gridName = grid.getName();
        final String preferenceName = CaseConverter.toCapitalizedWords(gridName) + "Mapsheet";
        String mapsheet = PreferencesUtil.getString(getClass(), preferenceName);
        final String title = "Zoom to Mapsheet: " + getName();
        mapsheet = (String) JOptionPane.showInputDialog(map, new JLabel("<html><p>" + gridName + "</p><p>Enter mapsheet to zoom to.</p></html>"), title, JOptionPane.QUESTION_MESSAGE, null, null, mapsheet);
        zoomToSheet(mapsheet);
    }
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) JLabel(javax.swing.JLabel) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid)

Aggregations

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