Changeset 11835 in josm


Ignore:
Timestamp:
2017-04-04T11:51:54+02:00 (6 months ago)
Author:
bastiK
Message:

see #7427 - alignment to the pixelgrid for precise tile placement

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

Legend:

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

    r11535 r11835  
    624624        newScale = scaleRound(newScale);
    625625
     626        // Align to the pixel grid:
     627        // This is a sub-pixel correction to ensure consistent drawing at a certain scale.
     628        // For example take 2 nodes, that have a distance of exactly 2.6 pixels.
     629        // Depending on the offset, the distance in rounded or truncated integer
     630        // pixels will be 2 or 3. It is preferable to have a consistent distance
     631        // and not switch back and forth as the viewport moves. This can be achieved by
     632        // locking an arbitrary point to integer pixel coordinates. (Here the EastNorth
     633        // origin is used as reference point.)
     634        // Note that the normal right mouse button drag moves the map by integer pixel
     635        // values, so it is not an issue in this case. It only shows when zooming
     636        // in & back out, etc.
     637        MapViewState mvs = getState().usingScale(newScale).movedTo(state.getCenterAtPixel(), newCenter);
     638        Point2D enOrigin = mvs.getPointFor(new EastNorth(0, 0)).getInView();
     639        Point2D enOriginAligned = new Point2D.Double(Math.round(enOrigin.getX()), Math.round(enOrigin.getY()));
     640        EastNorth enShift = mvs.getForView(enOriginAligned.getX(), enOriginAligned.getY()).getEastNorth();
     641        newCenter = newCenter.subtract(enShift);
     642
    626643        if (!newCenter.equals(getCenter()) || !Utils.equalsEpsilon(getScale(), newScale)) {
    627644            if (!initial) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r11834 r11835  
    11421142            boolean miss = false;
    11431143            Image img = null;
    1144             if (!tile.isLoaded()|| tile.hasError()) {
     1144            if (!tile.isLoaded() || tile.hasError()) {
    11451145                miss = true;
    11461146            } else {
Note: See TracChangeset for help on using the changeset viewer.