Changeset 9176 in josm


Ignore:
Timestamp:
2015-12-27T00:49:50+01:00 (9 years ago)
Author:
bastiK
Message:

restore old reference point for wms tiling (see #12186)
use negative tile indices for tiles left to this point

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    r9167 r9176  
    2222import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.data.Bounds;
    2425import org.openstreetmap.josm.data.ProjectionBounds;
    2526import org.openstreetmap.josm.data.coor.EastNorth;
     
    3839    private final Map<String, String> headers = new ConcurrentHashMap<>();
    3940    private final Set<String> serverProjections;
    40     private EastNorth topLeftCorner;
     41    private EastNorth anchorPosition;
     42    private int[] tileXMin;
     43    private int[] tileYMin;
    4144    private int[] tileXMax;
    4245    private int[] tileYMax;
     
    8992    }
    9093
     94    private void initAnchorPosition(Projection proj) {
     95        Bounds worldBounds = proj.getWorldBoundsLatLon();
     96        EastNorth min = proj.latlon2eastNorth(worldBounds.getMin());
     97        EastNorth max = proj.latlon2eastNorth(worldBounds.getMax());
     98        this.anchorPosition = new EastNorth(min.east(), max.north());
     99    }
     100
    91101    /**
    92102     * Initializes class with projection in JOSM. This call is needed every time projection changes.
     
    94104     */
    95105    public void initProjection(Projection proj) {
     106        initAnchorPosition(proj);
    96107        ProjectionBounds worldBounds = proj.getWorldBoundsBoxEastNorth();
    97         EastNorth min = worldBounds.getMin();
    98         EastNorth max = worldBounds.getMax();
    99         this.topLeftCorner = new EastNorth(min.east(), max.north());
    100 
     108
     109        EastNorth topLeft = new EastNorth(worldBounds.getMin().east(), worldBounds.getMax().north());
    101110        EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north());
    102111
    103112        // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection
    104113        double crsScale = 256 * 0.28e-03 / proj.getMetersPerUnit();
     114        tileXMin = new int[getMaxZoom() + 1];
     115        tileYMin = new int[getMaxZoom() + 1];
    105116        tileXMax = new int[getMaxZoom() + 1];
    106117        tileYMax = new int[getMaxZoom() + 1];
     
    111122            // this makes the zoom levels "glued" to standard TMS zoom levels
    112123            degreesPerTile[zoom] = (SCALE_DENOMINATOR_ZOOM_LEVEL_1 / Math.pow(2, zoom - 1)) * crsScale;
     124            TileXY minTileIndex = eastNorthToTileXY(topLeft, zoom);
     125            tileXMin[zoom] = minTileIndex.getXIndex();
     126            tileYMin[zoom] = minTileIndex.getYIndex();
    113127            TileXY maxTileIndex = eastNorthToTileXY(bottomRight, zoom);
    114128            tileXMax[zoom] = maxTileIndex.getXIndex();
     
    247261        double scale = getDegreesPerTile(zoom);
    248262        return new TileXY(
    249                 (enPoint.east() - topLeftCorner.east()) / scale,
    250                 (topLeftCorner.north() - enPoint.north()) / scale
     263                (enPoint.east() - anchorPosition.east()) / scale,
     264                (anchorPosition.north() - enPoint.north()) / scale
    251265                );
    252266    }
     
    264278    @Override
    265279    public int getTileXMin(int zoom) {
    266         return 0;
     280        return tileXMin[zoom];
    267281    }
    268282
     
    274288    @Override
    275289    public int getTileYMin(int zoom) {
    276         return 0;
     290        return tileYMin[zoom];
    277291    }
    278292
     
    282296        EastNorth point = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));
    283297        return new Point(
    284                     (int) Math.round((point.east() - topLeftCorner.east())   / scale),
    285                     (int) Math.round((topLeftCorner.north() - point.north()) / scale)
     298                    (int) Math.round((point.east() - anchorPosition.east())   / scale),
     299                    (int) Math.round((anchorPosition.north() - point.north()) / scale)
    286300                );
    287301    }
     
    302316        Projection proj = Main.getProjection();
    303317        EastNorth ret = new EastNorth(
    304                 topLeftCorner.east() + x * scale,
    305                 topLeftCorner.north() - y * scale
     318                anchorPosition.east() + x * scale,
     319                anchorPosition.north() - y * scale
    306320                );
    307321        return proj.eastNorth2latlon(ret).toCoordinate();
     
    350364        double scale = getDegreesPerTile(z);
    351365        return new EastNorth(
    352                         topLeftCorner.east() + x * scale,
    353                         topLeftCorner.north() - y * scale
     366                        anchorPosition.east() + x * scale,
     367                        anchorPosition.north() - y * scale
    354368                        );
    355369    }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r9078 r9176  
    879879     */
    880880    private Tile getTile(int x, int y, int zoom) {
    881         if (x < 0 || x > tileSource.getTileXMax(zoom) || y < 0 || y > tileSource.getTileYMax(zoom))
     881        if (x < tileSource.getTileXMin(zoom) || x > tileSource.getTileXMax(zoom) || y < tileSource.getTileYMin(zoom) || y > tileSource.getTileYMax(zoom))
    882882            return null;
    883883        return tileCache.getTile(tileSource, x, y, zoom);
Note: See TracChangeset for help on using the changeset viewer.