Changeset 11961 in josm for trunk/src/org


Ignore:
Timestamp:
2017-04-19T22:25:12+02:00 (7 years ago)
Author:
bastiK
Message:

see #7427 - avoid black lines at tile borders (primarily for native tiles)

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r11958 r11961  
    965965        }
    966966        g.drawImage(toDrawImg, (int) Math.round(screen0.getX()), (int) Math.round(screen0.getY()),
    967                 (int) Math.round(screen1.getX() - screen0.getX()), (int) Math.round(screen1.getY() - screen0.getY()), this);
     967                (int) Math.round(screen1.getX()) - (int) Math.round(screen0.getX()),
     968                (int) Math.round(screen1.getY()) - (int) Math.round(screen0.getY()), this);
    968969        if (clip != null) {
    969970            g.setClip(oldClip);
     
    10271028    private List<Tile> paintTileImages(Graphics2D g, TileSet ts, int zoom, Tile border) {
    10281029        if (zoom <= 0) return Collections.emptyList();
    1029         Shape borderClip = coordinateConverter.getScreenQuadrilateralForTile(border);
     1030        Shape borderClip = coordinateConverter.getTileShapeScreen(border);
    10301031        List<Tile> missedTiles = new LinkedList<>();
    10311032        // The callers of this code *require* that we return any tiles that we do not draw in missedTiles.
     
    11401141            // draw tile outline in semi-transparent red
    11411142            g.setColor(new Color(255, 0, 0, 50));
    1142             g.draw(coordinateConverter.getScreenQuadrilateralForTile(tile));
     1143            g.draw(coordinateConverter.getTileShapeScreen(tile));
    11431144        }
    11441145    }
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileCoordinateConverter.java

    r11910 r11961  
    22package org.openstreetmap.josm.gui.layer.imagery;
    33
     4import java.awt.Polygon;
     5import java.awt.Rectangle;
    46import java.awt.Shape;
    5 import java.awt.geom.Path2D;
    67import java.awt.geom.Point2D;
    78import java.awt.geom.Rectangle2D;
     
    121122
    122123    /**
    123      * Returns a quadrilateral formed by the 4 corners of the tile in screen coordinates.
     124     * Returns a shape that approximates the outline of the tile in screen coordinates.
    124125     *
    125126     * If the tile is rectangular, this will be the exact border of the tile.
     
    127128     * of the tile outline.
    128129     * @param tile the tile
    129      * @return quadrilateral tile outline in screen coordinates
    130      */
    131     public Shape getScreenQuadrilateralForTile(Tile tile) {
    132         Point2D p00 = this.getPixelForTile(tile.getXtile(), tile.getYtile(), tile.getZoom());
    133         Point2D p10 = this.getPixelForTile(tile.getXtile() + 1, tile.getYtile(), tile.getZoom());
    134         Point2D p11 = this.getPixelForTile(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom());
    135         Point2D p01 = this.getPixelForTile(tile.getXtile(), tile.getYtile() + 1, tile.getZoom());
    136 
    137         Path2D pth = new Path2D.Double();
    138         pth.moveTo(p00.getX(), p00.getY());
    139         pth.lineTo(p01.getX(), p01.getY());
    140         pth.lineTo(p11.getX(), p11.getY());
    141         pth.lineTo(p10.getX(), p10.getY());
    142         pth.closePath();
    143         return pth;
     130     * @return tile outline in screen coordinates
     131     */
     132    public Shape getTileShapeScreen(Tile tile) {
     133        if (requiresReprojection()) {
     134            Point2D p00 = this.getPixelForTile(tile.getXtile(), tile.getYtile(), tile.getZoom());
     135            Point2D p10 = this.getPixelForTile(tile.getXtile() + 1, tile.getYtile(), tile.getZoom());
     136            Point2D p11 = this.getPixelForTile(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom());
     137            Point2D p01 = this.getPixelForTile(tile.getXtile(), tile.getYtile() + 1, tile.getZoom());
     138            return new Polygon(new int[] {
     139                    (int) Math.round(p00.getX()),
     140                    (int) Math.round(p01.getX()),
     141                    (int) Math.round(p11.getX()),
     142                    (int) Math.round(p10.getX())},
     143                new int[] {
     144                    (int) Math.round(p00.getY()),
     145                    (int) Math.round(p01.getY()),
     146                    (int) Math.round(p11.getY()),
     147                    (int) Math.round(p10.getY())}, 4);
     148        } else {
     149            Point2D p00 = this.getPixelForTile(tile.getXtile(), tile.getYtile(), tile.getZoom());
     150            Point2D p11 = this.getPixelForTile(tile.getXtile() + 1, tile.getYtile() + 1, tile.getZoom());
     151            return new Rectangle((int) Math.round(p00.getX()), (int) Math.round(p00.getY()),
     152                    (int) Math.round(p11.getX()) - (int) Math.round(p00.getX()),
     153                    (int) Math.round(p11.getY()) - (int) Math.round(p00.getY()));
     154        }
    144155    }
    145156
Note: See TracChangeset for help on using the changeset viewer.