Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r8846 r9167 16 16 import java.util.regex.Pattern; 17 17 18 import org.openstreetmap.gui.jmapviewer.OsmMercator;19 18 import org.openstreetmap.gui.jmapviewer.Tile; 20 19 import org.openstreetmap.gui.jmapviewer.TileXY; … … 23 22 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 24 23 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.data. Bounds;24 import org.openstreetmap.josm.data.ProjectionBounds; 26 25 import org.openstreetmap.josm.data.coor.EastNorth; 27 26 import org.openstreetmap.josm.data.coor.LatLon; … … 40 39 private final Set<String> serverProjections; 41 40 private EastNorth topLeftCorner; 42 private Bounds worldBounds;43 41 private int[] tileXMax; 44 42 private int[] tileYMax; … … 96 94 */ 97 95 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(); 101 99 this.topLeftCorner = new EastNorth(min.east(), max.north()); 102 100 103 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon());101 EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north()); 104 102 105 103 // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection … … 113 111 // this makes the zoom levels "glued" to standard TMS zoom levels 114 112 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); 116 114 tileXMax[zoom] = maxTileIndex.getXIndex(); 117 115 tileYMax[zoom] = maxTileIndex.getYIndex(); … … 243 241 Projection proj = Main.getProjection(); 244 242 EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon)); 243 return eastNorthToTileXY(enPoint, zoom); 244 } 245 246 private TileXY eastNorthToTileXY(EastNorth enPoint, int zoom) { 245 247 double scale = getDegreesPerTile(zoom); 246 248 return new TileXY( … … 356 358 return degreesPerTile[zoom]; 357 359 } 358 359 /**360 * returns world bounds, but detect situation, when default bounds are provided (-90, -180, 90, 180), and projection361 * returns very close values for both min and max X. To work around this problem, cap this projection on north and south362 * pole, the same way they are capped in Mercator projection, so conversions should work properly363 */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 }378 360 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java
r8857 r9167 15 15 import org.openstreetmap.josm.data.coor.EastNorth; 16 16 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.data.osm.BBox;18 17 import org.openstreetmap.josm.data.projection.CustomProjection; 19 18 import org.openstreetmap.josm.data.projection.Projection; … … 107 106 TemplatedWMSTileSource source = getSource(); 108 107 109 verifyLocation(source, new LatLon(60, 18), 3); 110 verifyLocation(source, new LatLon(60, 18)); 108 verifyTileSquarness(source, 0, 1, 4); 109 verifyLocation(source, new LatLon(60, 18.1), 3); 110 verifyLocation(source, new LatLon(60, 18.1)); 111 111 } 112 112 … … 158 158 tileIndex.getYIndex() <= source.getTileYMax(z)); 159 159 160 EastNorth locationEN = Main.getProjection().latlon2eastNorth(location); 161 EastNorth x1 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex, z)); 162 EastNorth x2 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z)); 160 163 // test that location is within tile bounds 161 BBox bbox = new BBox( 162 getTileLatLon(source, tileIndex, z), 163 getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z) 164 ); 165 assertTrue(location.toDisplayString() + " not within " + bbox.toString() + 164 assertTrue(locationEN.toString() + " not within " + bboxStr(x1, x2) + 166 165 " for tile " + z + "/" + tileIndex.getXIndex() + "/" + tileIndex.getYIndex(), 167 bbox.bounds(location));166 isWithin(locationEN, x1, x2)); 168 167 verifyTileSquarness(source, tileIndex.getXIndex(), tileIndex.getYIndex(), z); 168 } 169 170 private static boolean isWithin(EastNorth point, EastNorth topLeft, EastNorth bottomRight) { 171 return Math.min(topLeft.east(), bottomRight.east()) <= point.east() && 172 point.east() <= Math.max(topLeft.east(), bottomRight.east()) && 173 Math.min(topLeft.north(), bottomRight.north()) <= point.north() && 174 point.north() <= Math.max(topLeft.north(), bottomRight.north()); 175 } 176 177 private static String bboxStr(EastNorth x1, EastNorth x2) { 178 return "[" + x1.east() +", " + x1.north() + ", " + x2.east() + ", " + x2.north() +"]"; 169 179 } 170 180
Note:
See TracChangeset
for help on using the changeset viewer.