Changeset 8618 in josm for trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
- Timestamp:
- 2015-07-26T17:03:37+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r8598 r8618 16 16 17 17 import org.openstreetmap.gui.jmapviewer.Coordinate; 18 import org.openstreetmap.gui.jmapviewer.OsmMercator; 18 19 import org.openstreetmap.gui.jmapviewer.Tile; 19 20 import org.openstreetmap.gui.jmapviewer.TileXY; … … 39 40 private final List<String> serverProjections; 40 41 private EastNorth topLeftCorner; 42 private Bounds worldBounds; 41 43 42 44 private static final String PATTERN_HEADER = "\\{header\\(([^,]+),([^}]+)\\)\\}"; … … 79 81 */ 80 82 public void initProjection(Projection proj) { 81 Bounds bounds = proj.getWorldBoundsLatLon();82 EastNorth min = proj.latlon2eastNorth( bounds.getMin());83 EastNorth max = proj.latlon2eastNorth( bounds.getMax());83 this.worldBounds = getWorldBounds(); 84 EastNorth min = proj.latlon2eastNorth(worldBounds.getMin()); 85 EastNorth max = proj.latlon2eastNorth(worldBounds.getMax()); 84 86 this.topLeftCorner = new EastNorth(min.east(), max.north()); 85 87 } … … 230 232 @Override 231 233 public int getTileXMax(int zoom) { 232 Projection proj = Main.getProjection(); 233 double scale = getDegreesPerTile(zoom); 234 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 235 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 236 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 237 return (int) Math.ceil(Math.abs(max.getX() - min.getX()) / scale); 234 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon()); 235 return latLonToTileXY(bottomRight.toCoordinate(), zoom).getXIndex(); 238 236 } 239 237 … … 245 243 @Override 246 244 public int getTileYMax(int zoom) { 247 Projection proj = Main.getProjection(); 248 double scale = getDegreesPerTile(zoom); 249 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 250 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 251 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 252 return (int) Math.ceil(Math.abs(max.getY() - min.getY()) / scale); 245 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon()); 246 return latLonToTileXY(bottomRight.toCoordinate(), zoom).getYIndex(); 253 247 } 254 248 … … 354 348 355 349 private double getDegreesPerTile(int zoom) { 356 return getDegreesPerTile(zoom, Main.getProjection()); 357 } 358 359 private double getDegreesPerTile(int zoom, Projection proj) { 360 Bounds bounds = proj.getWorldBoundsLatLon(); 361 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 362 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 350 Projection proj = Main.getProjection(); 351 EastNorth min = proj.latlon2eastNorth(worldBounds.getMin()); 352 EastNorth max = proj.latlon2eastNorth(worldBounds.getMax()); 353 363 354 int tilesPerZoom = (int) Math.pow(2, zoom - 1); 364 355 return Math.max( … … 368 359 } 369 360 361 /** 362 * returns world bounds, but detect situation, when default bounds are provided (-90, -180, 90, 180), and projection 363 * returns very close values for both min and max X. To work around this problem, cap this projection on north and south 364 * pole, the same way they are capped in Mercator projection, so conversions should work properly 365 */ 366 private final static Bounds getWorldBounds() { 367 Projection proj = Main.getProjection(); 368 Bounds bounds = proj.getWorldBoundsLatLon(); 369 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 370 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 371 372 if (Math.abs(min.getX() - max.getX()) < 1 && bounds.equals(new Bounds(new LatLon(-90, -180), new LatLon(90, 180)))) { 373 return new Bounds( 374 new LatLon(OsmMercator.MIN_LAT, bounds.getMinLon()), 375 new LatLon(OsmMercator.MAX_LAT, bounds.getMaxLon()) 376 ); 377 } 378 return bounds; 379 } 380 370 381 @Override 371 382 public String getTileId(int zoom, int tilex, int tiley) {
Note:
See TracChangeset
for help on using the changeset viewer.