Changeset 11376 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2008-10-21T16:27:42+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
r9095 r11376 21 21 22 22 public static double radius(int aZoomlevel) { 23 return (TILE_SIZE * Math.pow(2,aZoomlevel)) / (2 * Math.PI);23 return (TILE_SIZE * (1 << aZoomlevel)) / (2.0 * Math.PI); 24 24 } 25 25 … … 32 32 */ 33 33 public static int getMaxPixels(int aZoomlevel) { 34 return (int) (TILE_SIZE *Math.pow(2,aZoomlevel));34 return TILE_SIZE * (1 << aZoomlevel); 35 35 } 36 36 37 37 public static int falseEasting(int aZoomlevel) { 38 return (int)getMaxPixels(aZoomlevel) / 2;38 return getMaxPixels(aZoomlevel) / 2; 39 39 } 40 40 41 41 public static int falseNorthing(int aZoomlevel) { 42 return ( int) (-1 * getMaxPixels(aZoomlevel) / 2);42 return (-1 * getMaxPixels(aZoomlevel) / 2); 43 43 } 44 44 … … 52 52 public static int LonToX(double aLongitude, int aZoomlevel) { 53 53 double longitude = Math.toRadians(aLongitude); 54 return (int) ((radius(aZoomlevel) * longitude) + falseEasting(aZoomlevel)); 54 int x = (int) ((radius(aZoomlevel) * longitude) + falseEasting(aZoomlevel)); 55 x = Math.min(x, getMaxPixels(aZoomlevel) - 1); 56 return x; 55 57 } 56 58 … … 68 70 aLat = MAX_LAT; 69 71 double latitude = Math.toRadians(aLat); 70 return (int) (-1 71 * (radius(aZoomlevel) / 2.0 * Math.log((1.0 + Math 72 .sin(latitude)) 73 / (1.0 - Math.sin(latitude)))) - falseNorthing(aZoomlevel)); 72 int y = 73 (int) (-1 74 * (radius(aZoomlevel) / 2.0 * Math.log((1.0 + Math.sin(latitude)) 75 / (1.0 - Math.sin(latitude)))) - falseNorthing(aZoomlevel)); 76 y = Math.min(y, getMaxPixels(aZoomlevel) - 1); 77 return y; 74 78 } 75 79 … … 85 89 double longRadians = aX / radius(aZoomlevel); 86 90 double longDegrees = Math.toDegrees(longRadians); 87 double rotations = Math.floor((longDegrees + 180) / 360); 88 double longitude = longDegrees - (rotations * 360); 89 return longitude; 91 return longDegrees; 90 92 } 91 93 … … 99 101 public static double YToLat(int aY, int aZoomlevel) { 100 102 aY += falseNorthing(aZoomlevel); 101 double latitude = (Math.PI / 2) 102 - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); 103 double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); 103 104 return -1 * Math.toDegrees(latitude); 104 105 }
Note:
See TracChangeset
for help on using the changeset viewer.