Changeset 33207 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2017-04-03T15:00:12+02:00 (8 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileRange.java
r33206 r33207 15 15 } 16 16 17 p rotectedTileRange(TileXY t1, TileXY t2, int zoom) {17 public TileRange(TileXY t1, TileXY t2, int zoom) { 18 18 minX = (int) Math.floor(Math.min(t1.getX(), t2.getX())); 19 19 minY = (int) Math.floor(Math.min(t1.getY(), t2.getY())); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r31573 r33207 9 9 import org.openstreetmap.gui.jmapviewer.JMapViewer; 10 10 import org.openstreetmap.gui.jmapviewer.Tile; 11 import org.openstreetmap.gui.jmapviewer.TileRange; 11 12 import org.openstreetmap.gui.jmapviewer.TileXY; 12 13 … … 210 211 */ 211 212 Map<String, String> getMetadata(Map<String, List<String>> headers); 213 214 /** 215 * Convert tile indeces (x/y/zoom) into projected coordinates of the tile origin. 216 * @param x x tile index 217 * @param y z tile index 218 * @param zoom zoom level 219 * @return projected coordinates of the tile origin 220 */ 221 IProjected tileXYtoProjected(int x, int y, int zoom); 222 223 /** 224 * Convert projected coordinates to tile indices. 225 * @param p projected coordinates 226 * @param zoom zoom level 227 * @return corresponding tile index x/y (floating point, truncate to integer 228 * for tile index) 229 */ 230 TileXY projectedToTileXY(IProjected p, int zoom); 231 232 /** 233 * Check if one tile is inside another tile. 234 * @param inner the tile that is suspected to be inside the other tile 235 * @param outer the tile that might contain the first tile 236 * @return true if first tile is inside second tile (or both are identical), 237 * false otherwise 238 */ 239 boolean isInside(Tile inner, Tile outer); 240 241 /** 242 * Returns a range of tiles, that cover a given tile, which is 243 * usually at a different zoom level. 244 * 245 * In standard tile layout, 4 tiles cover a tile one zoom lower, 16 tiles 246 * cover a tile 2 zoom levels below etc. 247 * If the zoom level of the covering tiles is greater or equal, a single 248 * tile suffices. 249 * 250 * @param tile the tile to cover 251 * @param newZoom zoom level of the covering tiles 252 * @return TileRange of all covering tiles at zoom <code>newZoom</code> 253 */ 254 TileRange getCoveringTileRange(Tile tile, int newZoom); 255 256 /** 257 * Get content reference system for this tile source. 258 * 259 * E.g. "EPSG:3857" for Google-Mercator. 260 * @return code for the content reference system in use 261 */ 262 String getServerCRS(); 263 212 264 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java
r32085 r33207 6 6 import org.openstreetmap.gui.jmapviewer.Coordinate; 7 7 import org.openstreetmap.gui.jmapviewer.OsmMercator; 8 import org.openstreetmap.gui.jmapviewer.Projected; 9 import org.openstreetmap.gui.jmapviewer.Tile; 10 import org.openstreetmap.gui.jmapviewer.TileRange; 8 11 import org.openstreetmap.gui.jmapviewer.TileXY; 9 12 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 13 import org.openstreetmap.gui.jmapviewer.interfaces.IProjected; 10 14 11 15 /** … … 75 79 ); 76 80 } 81 82 @Override 83 public IProjected tileXYtoProjected(int x, int y, int zoom) { 84 double mercatorWidth = 2 * Math.PI * OsmMercator.EARTH_RADIUS; 85 double f = mercatorWidth * getTileSize() / osmMercator.getMaxPixels(zoom); 86 return new Projected(f * x - mercatorWidth / 2, -(f * y - mercatorWidth / 2)); 87 } 88 89 @Override 90 public TileXY projectedToTileXY(IProjected p, int zoom) { 91 double mercatorWidth = 2 * Math.PI * OsmMercator.EARTH_RADIUS; 92 double f = mercatorWidth * getTileSize() / osmMercator.getMaxPixels(zoom); 93 return new TileXY((p.getEast() + mercatorWidth / 2) / f , (-p.getNorth() + mercatorWidth / 2) / f); 94 } 95 96 @Override 97 public boolean isInside(Tile inner, Tile outer) { 98 int dz = inner.getZoom() - outer.getZoom(); 99 if (dz < 0) return false; 100 return outer.getXtile() == inner.getXtile() >> dz && 101 outer.getYtile() == inner.getYtile() >> dz; 102 } 103 104 @Override 105 public TileRange getCoveringTileRange(Tile tile, int newZoom) { 106 if (newZoom <= tile.getZoom()) { 107 int dz = tile.getZoom() - newZoom; 108 TileXY xy = new TileXY(tile.getXtile() >> dz, tile.getYtile() >> dz); 109 return new TileRange(xy, xy, newZoom); 110 } else { 111 int dz = newZoom - tile.getZoom(); 112 TileXY t1 = new TileXY(tile.getXtile() << dz, tile.getYtile() << dz); 113 TileXY t2 = new TileXY(t1.getX() + (1 << dz) - 1, t1.getY() + (1 << dz) - 1); 114 return new TileRange(t1, t2, newZoom); 115 } 116 } 117 118 @Override 119 public String getServerCRS() { 120 return "EPSG:3857"; 121 } 77 122 }
Note:
See TracChangeset
for help on using the changeset viewer.