Changeset 31125 in osm for applications
- Timestamp:
- 2015-05-14T13:25:43+02:00 (10 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
r30900 r31125 11 11 public class OsmMercator { 12 12 13 public static int TILE_SIZE = 256; 13 /** 14 * default tile size 15 */ 16 public static int DEFAUL_TILE_SIZE = 256; 17 /** maximum latitude (north) for mercator display */ 14 18 public static final double MAX_LAT = 85.05112877980659; 19 /** minimum latitude (south) for mercator display */ 15 20 public static final double MIN_LAT = -85.05112877980659; 16 private static double EARTH_RADIUS = 6378137; // equatorial earth radius for EPSG:3857 (Mercator) 17 18 public static double radius(int aZoomlevel) { 19 return (TILE_SIZE * (1 << aZoomlevel)) / (2.0 * Math.PI); 21 /** equatorial earth radius for EPSG:3857 (Mercator) */ 22 private static double EARTH_RADIUS = 6378137; 23 24 /** 25 * instance with tile size of 256 for easy conversions 26 */ 27 public static final OsmMercator MERCATOR_256 = new OsmMercator(); 28 29 /** tile size of the displayed tiles */ 30 private int tileSize = DEFAUL_TILE_SIZE; 31 32 /** 33 * Creates instance with default tile size of 256 34 */ 35 public OsmMercator() { 36 } 37 38 /** 39 * Creates instance with provided tile size. 40 * @param tileSize 41 */ 42 public OsmMercator(int tileSize) { 43 this.tileSize = tileSize; 44 } 45 46 public double radius(int aZoomlevel) { 47 return (tileSize * (1 << aZoomlevel)) / (2.0 * Math.PI); 20 48 } 21 49 22 50 /** 23 51 * Returns the absolut number of pixels in y or x, defined as: 2^Zoomlevel * 24 * TILE_WIDTH where TILE_WIDTHis the width of a tile in pixels52 * tileSize where tileSize is the width of a tile in pixels 25 53 * 26 54 * @param aZoomlevel zoom level to request pixel data 27 55 * @return number of pixels 28 56 */ 29 public staticint getMaxPixels(int aZoomlevel) {30 return TILE_SIZE* (1 << aZoomlevel);31 } 32 33 public staticint falseEasting(int aZoomlevel) {57 public int getMaxPixels(int aZoomlevel) { 58 return tileSize * (1 << aZoomlevel); 59 } 60 61 public int falseEasting(int aZoomlevel) { 34 62 return getMaxPixels(aZoomlevel) / 2; 35 63 } 36 64 37 public staticint falseNorthing(int aZoomlevel) {65 public int falseNorthing(int aZoomlevel) { 38 66 return (-1 * getMaxPixels(aZoomlevel) / 2); 39 67 } … … 51 79 * @author Jason Huntley 52 80 */ 53 public staticdouble getDistance(int x1, int y1, int x2, int y2, int zoomLevel) {81 public double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) { 54 82 double la1 = YToLat(y1, zoomLevel); 55 83 double lo1 = XToLon(x1, zoomLevel); … … 70 98 * @author Jason Huntley 71 99 */ 72 public staticdouble getDistance(double la1, double lo1, double la2, double lo2) {100 public double getDistance(double la1, double lo1, double la2, double lo2) { 73 101 double aStartLat = Math.toRadians(la1); 74 102 double aStartLong = Math.toRadians(lo1); … … 101 129 * @author Jan Peter Stotz 102 130 */ 103 public staticdouble LonToX(double aLongitude, int aZoomlevel) {131 public double LonToX(double aLongitude, int aZoomlevel) { 104 132 int mp = getMaxPixels(aZoomlevel); 105 133 double x = (mp * (aLongitude + 180l)) / 360l; … … 125 153 * @author Jan Peter Stotz 126 154 */ 127 public staticdouble LatToY(double aLat, int aZoomlevel) {155 public double LatToY(double aLat, int aZoomlevel) { 128 156 if (aLat < MIN_LAT) 129 157 aLat = MIN_LAT; … … 155 183 * @author Jan Peter Stotz 156 184 */ 157 public staticdouble XToLon(int aX, int aZoomlevel) {185 public double XToLon(int aX, int aZoomlevel) { 158 186 return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0; 159 187 } … … 166 194 * @return [MIN_LAT..MAX_LAT] is about [-85..85] 167 195 */ 168 public staticdouble YToLat(int aY, int aZoomlevel) {196 public double YToLat(int aY, int aZoomlevel) { 169 197 aY += falseNorthing(aZoomlevel); 170 198 double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java
r31124 r31125 15 15 protected String id; 16 16 private Map<String, String> noTileHeaders; 17 protected int tileSize; 18 protected OsmMercator osmMercator; 17 19 18 20 public AbstractTMSTileSource(TileSourceInfo info) { … … 24 26 this.id = info.getUrl(); 25 27 this.noTileHeaders = info.getNoTileHeaders(); 28 this.tileSize = info.getTileSize(); 29 osmMercator = new OsmMercator(this.tileSize); 26 30 } 27 31 … … 81 85 @Override 82 86 public int getTileSize() { 83 return OsmMercator.TILE_SIZE;87 return tileSize; 84 88 } 85 89 86 90 @Override 87 91 public double getDistance(double lat1, double lon1, double lat2, double lon2) { 88 return OsmMercator.getDistance(lat1, lon1, lat2, lon2);92 return osmMercator.getDistance(lat1, lon1, lat2, lon2); 89 93 } 90 94 91 95 @Override 92 96 public int LonToX(double lon, int zoom) { 93 return (int ) OsmMercator.LonToX(lon, zoom);97 return (int )osmMercator.LonToX(lon, zoom); 94 98 } 95 99 96 100 @Override 97 101 public int LatToY(double lat, int zoom) { 98 return (int ) OsmMercator.LatToY(lat, zoom);102 return (int )osmMercator.LatToY(lat, zoom); 99 103 } 100 104 101 105 @Override 102 106 public double XToLon(int x, int zoom) { 103 return OsmMercator.XToLon(x, zoom);107 return osmMercator.XToLon(x, zoom); 104 108 } 105 109 106 110 @Override 107 111 public double YToLat(int y, int zoom) { 108 return OsmMercator.YToLat(y, zoom);112 return osmMercator.YToLat(y, zoom); 109 113 } 110 114 111 115 @Override 112 116 public double latToTileY(double lat, int zoom) { 113 return OsmMercator.LatToY(lat, zoom) / OsmMercator.TILE_SIZE;117 return osmMercator.LatToY(lat, zoom) / tileSize; 114 118 } 115 119 116 120 @Override 117 121 public double lonToTileX(double lon, int zoom) { 118 return OsmMercator.LonToX(lon, zoom) / OsmMercator.TILE_SIZE;122 return osmMercator.LonToX(lon, zoom) / tileSize; 119 123 } 120 124 121 125 @Override 122 126 public double tileYToLat(int y, int zoom) { 123 return OsmMercator.YToLat(y * OsmMercator.TILE_SIZE, zoom);127 return osmMercator.YToLat(y * tileSize, zoom); 124 128 } 125 129 126 130 @Override 127 131 public double tileXToLon(int x, int zoom) { 128 return OsmMercator.XToLon(x * OsmMercator.TILE_SIZE, zoom);132 return osmMercator.XToLon(x * tileSize, zoom); 129 133 } 130 134 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java
r31122 r31125 94 94 @Override 95 95 public int LatToY(double lat, int zoom) { 96 return (int )(latToTileY(lat, zoom) * OsmMercator.TILE_SIZE);96 return (int )(latToTileY(lat, zoom) * tileSize); 97 97 } 98 98 99 99 @Override 100 100 public double YToLat(int y, int zoom) { 101 return tileYToLat((double )y / OsmMercator.TILE_SIZE, zoom);101 return tileYToLat((double )y / tileSize, zoom); 102 102 } 103 103 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java
r31122 r31125 3 3 4 4 import java.util.Map; 5 6 import org.openstreetmap.gui.jmapviewer.OsmMercator; 5 7 6 8 /** … … 28 30 protected String cookies; 29 31 32 /** tile size of the displayed tiles */ 33 private int tileSize = OsmMercator.DEFAUL_TILE_SIZE; 30 34 31 35 /** … … 58 62 59 63 /** 60 * 64 * Request name of the tile source 61 65 * @return name of the tile source 62 66 */ … … 66 70 67 71 /** 68 * 72 * Request URL of the tile source 69 73 * @return url of the tile source 70 74 */ … … 74 78 75 79 /** 76 * 80 * Request header information for empty tiles for servers delivering such tile types 77 81 * @return map of headers, that when set, means that this is "no tile at this zoom level" situation 78 82 */ … … 82 86 83 87 /** 84 * 88 * Request supported minimum zoom level 85 89 * @return minimum zoom level supported by tile source 86 90 */ … … 90 94 91 95 /** 92 * 96 * Request supported maximum zoom level 93 97 * @return maximum zoom level supported by tile source 94 98 */ … … 98 102 99 103 /** 100 * 104 * Request cookies to be sent together with request 101 105 * @return cookies to be sent along with request to tile source 102 106 */ … … 105 109 } 106 110 111 /** 112 * Request tile size of this tile source 113 * @return tile size provided by this tile source 114 */ 115 public int getTileSize() { 116 return tileSize; 117 } 118 119 /** 120 * Sets the tile size provided by this tile source 121 * @param tileSize 122 */ 123 public void setTileSize(int tileSize) { 124 if (tileSize <= 0) { 125 throw new AssertionError("Invalid tile size: " + tileSize); 126 } 127 this.tileSize = tileSize; 128 } 107 129 }
Note:
See TracChangeset
for help on using the changeset viewer.