Changeset 9176 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-12-27T00:49:50+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r9167 r9176 22 22 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.data.Bounds; 24 25 import org.openstreetmap.josm.data.ProjectionBounds; 25 26 import org.openstreetmap.josm.data.coor.EastNorth; … … 38 39 private final Map<String, String> headers = new ConcurrentHashMap<>(); 39 40 private final Set<String> serverProjections; 40 private EastNorth topLeftCorner; 41 private EastNorth anchorPosition; 42 private int[] tileXMin; 43 private int[] tileYMin; 41 44 private int[] tileXMax; 42 45 private int[] tileYMax; … … 89 92 } 90 93 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 91 101 /** 92 102 * Initializes class with projection in JOSM. This call is needed every time projection changes. … … 94 104 */ 95 105 public void initProjection(Projection proj) { 106 initAnchorPosition(proj); 96 107 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()); 101 110 EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north()); 102 111 103 112 // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection 104 113 double crsScale = 256 * 0.28e-03 / proj.getMetersPerUnit(); 114 tileXMin = new int[getMaxZoom() + 1]; 115 tileYMin = new int[getMaxZoom() + 1]; 105 116 tileXMax = new int[getMaxZoom() + 1]; 106 117 tileYMax = new int[getMaxZoom() + 1]; … … 111 122 // this makes the zoom levels "glued" to standard TMS zoom levels 112 123 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(); 113 127 TileXY maxTileIndex = eastNorthToTileXY(bottomRight, zoom); 114 128 tileXMax[zoom] = maxTileIndex.getXIndex(); … … 247 261 double scale = getDegreesPerTile(zoom); 248 262 return new TileXY( 249 (enPoint.east() - topLeftCorner.east()) / scale,250 ( topLeftCorner.north() - enPoint.north()) / scale263 (enPoint.east() - anchorPosition.east()) / scale, 264 (anchorPosition.north() - enPoint.north()) / scale 251 265 ); 252 266 } … … 264 278 @Override 265 279 public int getTileXMin(int zoom) { 266 return 0;280 return tileXMin[zoom]; 267 281 } 268 282 … … 274 288 @Override 275 289 public int getTileYMin(int zoom) { 276 return 0;290 return tileYMin[zoom]; 277 291 } 278 292 … … 282 296 EastNorth point = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon)); 283 297 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) 286 300 ); 287 301 } … … 302 316 Projection proj = Main.getProjection(); 303 317 EastNorth ret = new EastNorth( 304 topLeftCorner.east() + x * scale,305 topLeftCorner.north() - y * scale318 anchorPosition.east() + x * scale, 319 anchorPosition.north() - y * scale 306 320 ); 307 321 return proj.eastNorth2latlon(ret).toCoordinate(); … … 350 364 double scale = getDegreesPerTile(z); 351 365 return new EastNorth( 352 topLeftCorner.east() + x * scale,353 topLeftCorner.north() - y * scale366 anchorPosition.east() + x * scale, 367 anchorPosition.north() - y * scale 354 368 ); 355 369 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r9078 r9176 879 879 */ 880 880 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)) 882 882 return null; 883 883 return tileCache.getTile(tileSource, x, y, zoom);
Note:
See TracChangeset
for help on using the changeset viewer.