Changeset 11894 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-04-13T12:58:56+02:00 (7 years ago)
Author:
bastiK
Message:

see #7427 - make sure fixed scale is used for alignment + javadoc

File:
1 edited

Legend:

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

    r11893 r11894  
    4646    }
    4747
     48    /**
     49     * Get the scale that was used for reprojecting the tile.
     50     *
     51     * This is not necessarily the mapview scale, but may be
     52     * adjusted to avoid excessively large cache image.
     53     * @return the scale that was used for reprojecting the tile
     54     */
    4855    public double getNativeScale() {
    4956        return nativeScale;
    5057    }
    5158
     59    /**
     60     * Check if it is necessary to refresh the cache to match the current mapview
     61     * scale and get optimized image quality.
     62     *
     63     * When the maximum zoom is exceeded, this method will generally return false.
     64     * @param currentScale the current mapview scale
     65     * @return true if the tile should be reprojected again from the source image.
     66     */
    5267    public boolean needsUpdate(double currentScale) {
    5368        if (Utils.equalsEpsilon(nativeScale, currentScale))
    5469            return false;
    55         // zoomed in even more - max zoom already reached, so no update
    5670        return !maxZoomReached || currentScale >= nativeScale;
    5771    }
     
    107121        ProjectionBounds pbTarget = projCurrent.getEastNorthBoundsBox(pbServer, projServer);
    108122
    109         // add margin and align to pixel grid
    110         double minEast = Math.floor(pbTarget.minEast / scaleMapView - margin) * scaleMapView;
    111         double minNorth = -Math.floor(-(pbTarget.minNorth / scaleMapView - margin)) * scaleMapView;
    112         double maxEast = Math.ceil(pbTarget.maxEast / scaleMapView + margin) * scaleMapView;
    113         double maxNorth = -Math.ceil(-(pbTarget.maxNorth / scaleMapView + margin)) * scaleMapView;
    114         ProjectionBounds pbTargetAligned = new ProjectionBounds(minEast, minNorth, maxEast, maxNorth);
    115 
    116         Dimension dim = getDimension(pbTargetAligned, scaleMapView);
     123        Dimension dim = getDimension(pbMarginAndAlign(pbTarget, scaleMapView, margin), scaleMapView);
    117124        Integer scaleFix = limitScale(source.getTileSize(), Math.sqrt(dim.getWidth() * dim.getHeight()));
    118125        double scale = scaleFix == null ? scaleMapView : (scaleMapView * scaleFix);
     126        ProjectionBounds pbTargetAligned = pbMarginAndAlign(pbTarget, scale, margin);
    119127
    120128        ImageWarp.PointTransform pointTransform = pt -> {
     
    151159    }
    152160
     161    // add margin and align to pixel grid
     162    private ProjectionBounds pbMarginAndAlign(ProjectionBounds box, double scale, double margin) {
     163        double minEast = Math.floor(box.minEast / scale - margin) * scale;
     164        double minNorth = -Math.floor(-(box.minNorth / scale - margin)) * scale;
     165        double maxEast = Math.ceil(box.maxEast / scale + margin) * scale;
     166        double maxNorth = -Math.ceil(-(box.maxNorth / scale + margin)) * scale;
     167        return new ProjectionBounds(minEast, minNorth, maxEast, maxNorth);
     168    }
     169
     170    // dimension in pixel
    153171    private Dimension getDimension(ProjectionBounds bounds, double scale) {
    154172        return new Dimension(
Note: See TracChangeset for help on using the changeset viewer.