Ignore:
Timestamp:
2015-12-26T20:41:45+01:00 (8 years ago)
Author:
wiktorn
Message:
  • Move TemplatedWMSTileSource to Projection.getWorldBoundsBoxEastNorth
  • fix failing tests - move to EastNorth computations instead of LatLon,

which might be non-square, which lead to trouble checking, whether point was
within the bounds or not

See #12186

File:
1 edited

Legend:

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

    r8846 r9167  
    1616import java.util.regex.Pattern;
    1717
    18 import org.openstreetmap.gui.jmapviewer.OsmMercator;
    1918import org.openstreetmap.gui.jmapviewer.Tile;
    2019import org.openstreetmap.gui.jmapviewer.TileXY;
     
    2322import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
    2423import org.openstreetmap.josm.Main;
    25 import org.openstreetmap.josm.data.Bounds;
     24import org.openstreetmap.josm.data.ProjectionBounds;
    2625import org.openstreetmap.josm.data.coor.EastNorth;
    2726import org.openstreetmap.josm.data.coor.LatLon;
     
    4039    private final Set<String> serverProjections;
    4140    private EastNorth topLeftCorner;
    42     private Bounds worldBounds;
    4341    private int[] tileXMax;
    4442    private int[] tileYMax;
     
    9694     */
    9795    public void initProjection(Projection proj) {
    98         this.worldBounds = getWorldBounds();
    99         EastNorth min = proj.latlon2eastNorth(worldBounds.getMin());
    100         EastNorth max = proj.latlon2eastNorth(worldBounds.getMax());
     96        ProjectionBounds worldBounds = proj.getWorldBoundsBoxEastNorth();
     97        EastNorth min = worldBounds.getMin();
     98        EastNorth max = worldBounds.getMax();
    10199        this.topLeftCorner = new EastNorth(min.east(), max.north());
    102100
    103         LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon());
     101        EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north());
    104102
    105103        // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection
     
    113111            // this makes the zoom levels "glued" to standard TMS zoom levels
    114112            degreesPerTile[zoom] = (SCALE_DENOMINATOR_ZOOM_LEVEL_1 / Math.pow(2, zoom - 1)) * crsScale;
    115             TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom);
     113            TileXY maxTileIndex = eastNorthToTileXY(bottomRight, zoom);
    116114            tileXMax[zoom] = maxTileIndex.getXIndex();
    117115            tileYMax[zoom] = maxTileIndex.getYIndex();
     
    243241        Projection proj = Main.getProjection();
    244242        EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon));
     243        return eastNorthToTileXY(enPoint, zoom);
     244    }
     245
     246    private TileXY eastNorthToTileXY(EastNorth enPoint, int zoom) {
    245247        double scale = getDegreesPerTile(zoom);
    246248        return new TileXY(
     
    356358        return degreesPerTile[zoom];
    357359    }
    358 
    359     /**
    360      * returns world bounds, but detect situation, when default bounds are provided (-90, -180, 90, 180), and projection
    361      * returns very close values for both min and max X. To work around this problem, cap this projection on north and south
    362      * pole, the same way they are capped in Mercator projection, so conversions should work properly
    363      */
    364     private static Bounds getWorldBounds() {
    365         Projection proj = Main.getProjection();
    366         Bounds bounds = proj.getWorldBoundsLatLon();
    367         EastNorth min = proj.latlon2eastNorth(bounds.getMin());
    368         EastNorth max = proj.latlon2eastNorth(bounds.getMax());
    369 
    370         if (Math.abs(min.getX() - max.getX()) < 1 && bounds.equals(new Bounds(new LatLon(-90, -180), new LatLon(90, 180)))) {
    371             return new Bounds(
    372                     new LatLon(OsmMercator.MIN_LAT, bounds.getMinLon()),
    373                     new LatLon(OsmMercator.MAX_LAT, bounds.getMaxLon())
    374                     );
    375         }
    376         return bounds;
    377     }
    378360}
Note: See TracChangeset for help on using the changeset viewer.