Changeset 30248 in osm for applications/viewer/jmapviewer/src/org
- Timestamp:
- 2014-01-31T14:23:11+01:00 (11 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/JMapViewer.java
r30245 r30248 87 87 protected ZOOM_BUTTON_STYLE zoomButtonStyle; 88 88 89 pr ivateTileSource tileSource;89 protected TileSource tileSource; 90 90 91 91 protected AttributionSupport attribution = new AttributionSupport(); … … 211 211 */ 212 212 public void setDisplayPosition(Point mapPoint, Coordinate to, int zoom) { 213 int x = OsmMercator.LonToX(to.getLon(), zoom);214 int y = OsmMercator.LatToY(to.getLat(), zoom);213 int x = tileSource.LonToX(to.getLon(), zoom); 214 int y = tileSource.LatToY(to.getLat(), zoom); 215 215 setDisplayPosition(mapPoint, x, y, zoom); 216 216 } … … 269 269 for (MapMarker marker : mapMarkerList) { 270 270 if(marker.isVisible()){ 271 int x = OsmMercator.LonToX(marker.getLon(), mapZoomMax);272 int y = OsmMercator.LatToY(marker.getLat(), mapZoomMax);271 int x = tileSource.LonToX(marker.getLon(), mapZoomMax); 272 int y = tileSource.LatToY(marker.getLat(), mapZoomMax); 273 273 x_max = Math.max(x_max, x); 274 274 y_max = Math.max(y_max, y); … … 282 282 for (MapRectangle rectangle : mapRectangleList) { 283 283 if(rectangle.isVisible()){ 284 x_max = Math.max(x_max, OsmMercator.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax));285 y_max = Math.max(y_max, OsmMercator.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax));286 x_min = Math.min(x_min, OsmMercator.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax));287 y_min = Math.min(y_min, OsmMercator.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax));284 x_max = Math.max(x_max, tileSource.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax)); 285 y_max = Math.max(y_max, tileSource.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax)); 286 x_min = Math.min(x_min, tileSource.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax)); 287 y_min = Math.min(y_min, tileSource.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax)); 288 288 } 289 289 } … … 294 294 if(polygon.isVisible()){ 295 295 for (ICoordinate c : polygon.getPoints()) { 296 int x = OsmMercator.LonToX(c.getLon(), mapZoomMax);297 int y = OsmMercator.LatToY(c.getLat(), mapZoomMax);296 int x = tileSource.LonToX(c.getLon(), mapZoomMax); 297 int y = tileSource.LatToY(c.getLat(), mapZoomMax); 298 298 x_max = Math.max(x_max, x); 299 299 y_max = Math.max(y_max, y); … … 369 369 */ 370 370 public Coordinate getPosition() { 371 double lon = OsmMercator.XToLon(center.x, zoom);372 double lat = OsmMercator.YToLat(center.y, zoom);371 double lon = tileSource.XToLon(center.x, zoom); 372 double lat = tileSource.YToLat(center.y, zoom); 373 373 return new Coordinate(lat, lon); 374 374 } … … 398 398 int x = center.x + mapPointX - getWidth() / 2; 399 399 int y = center.y + mapPointY - getHeight() / 2; 400 double lon = OsmMercator.XToLon(x, zoom);401 double lat = OsmMercator.YToLat(y, zoom);400 double lon = tileSource.XToLon(x, zoom); 401 double lat = tileSource.YToLat(y, zoom); 402 402 return new Coordinate(lat, lon); 403 403 } … … 413 413 */ 414 414 public Point getMapPosition(double lat, double lon, boolean checkOutside) { 415 int x = OsmMercator.LonToX(lon, zoom);416 int y = OsmMercator.LatToY(lat, zoom);415 int x = tileSource.LonToX(lon, zoom); 416 int y = tileSource.LatToY(lat, zoom); 417 417 x -= center.x - getWidth() / 2; 418 418 y -= center.y - getHeight() / 2; … … 433 433 */ 434 434 public Integer getLatOffset(double lat, double offset, boolean checkOutside) { 435 int y = OsmMercator.LatToY(lat+offset, zoom);435 int y = tileSource.LatToY(lat+offset, zoom); 436 436 y -= center.y - getHeight() / 2; 437 437 if (checkOutside) { … … 511 511 Coordinate centerCoord=getPosition(center); 512 512 513 double mDistance =OsmMercator.getDistance(originCoord.getLat(), originCoord.getLon(),513 double mDistance = tileSource.getDistance(originCoord.getLat(), originCoord.getLon(), 514 514 centerCoord.getLat(), centerCoord.getLon()); 515 515 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
r30223 r30248 11 11 public class OsmMercator { 12 12 13 p rivatestatic int TILE_SIZE = 256;13 public static int TILE_SIZE = 256; 14 14 public static final double MAX_LAT = 85.05112877980659; 15 15 public static final double MIN_LAT = -85.05112877980659; … … 101 101 * @author Jan Peter Stotz 102 102 */ 103 public static intLonToX(double aLongitude, int aZoomlevel) {103 public static double LonToX(double aLongitude, int aZoomlevel) { 104 104 int mp = getMaxPixels(aZoomlevel); 105 int x = (int) ((mp * (aLongitude + 180l)) / 360l); 106 x = Math.min(x, mp - 1); 107 return x; 105 double x = (mp * (aLongitude + 180l)) / 360l; 106 return Math.min(x, mp - 1); 108 107 } 109 108 … … 126 125 * @author Jan Peter Stotz 127 126 */ 128 public static intLatToY(double aLat, int aZoomlevel) {127 public static double LatToY(double aLat, int aZoomlevel) { 129 128 if (aLat < MIN_LAT) 130 129 aLat = MIN_LAT; … … 134 133 double log = Math.log((1.0 + sinLat) / (1.0 - sinLat)); 135 134 int mp = getMaxPixels(aZoomlevel); 136 int y = (int) (mp * (0.5 - (log / (4.0 * Math.PI)))); 137 y = Math.min(y, mp - 1); 138 return y; 135 double y = mp * (0.5 - (log / (4.0 * Math.PI))); 136 return Math.min(y, mp - 1); 139 137 } 140 138 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r30223 r30248 94 94 int getTileSize(); 95 95 96 /** 97 * Gets the distance using Spherical law of cosines. 98 * @return the distance, m. 99 */ 100 double getDistance(double la1, double lo1, double la2, double lo2); 101 102 /** 103 * Transform longitude to pixelspace. 104 * @return [0..2^Zoomlevel*TILE_SIZE[ 105 */ 106 int LonToX(double aLongitude, int aZoomlevel); 107 108 /** 109 * Transforms latitude to pixelspace. 110 * @return [0..2^Zoomlevel*TILE_SIZE[ 111 */ 112 int LatToY(double aLat, int aZoomlevel); 113 114 /** 115 * Transforms pixel coordinate X to longitude 116 * @return ]-180..180[ 117 */ 118 double XToLon(int aX, int aZoomlevel); 119 120 /** 121 * Transforms pixel coordinate Y to latitude. 122 * @return [MIN_LAT..MAX_LAT] 123 */ 124 double YToLat(int aY, int aZoomlevel); 125 126 /** 127 * Transforms longitude to X tile coordinate. 128 * @return [0..2^Zoomlevel[ 129 */ 130 double lonToTileX(double lon, int zoom); 131 132 /** 133 * Transforms latitude to Y tile coordinate. 134 * @return [0..2^Zoomlevel[ 135 */ 96 136 double latToTileY(double lat, int zoom); 97 137 98 double lonToTileX(double lon, int zoom); 138 /** 139 * Transforms tile X coordinate to longitude. 140 * @return ]-180..180[ 141 */ 142 double tileXToLon(int x, int zoom); 99 143 144 /** 145 * Transforms tile Y coordinate to latitude. 146 * @return [MIN_LAT..MAX_LAT] 147 */ 100 148 double tileYToLat(int y, int zoom); 101 102 double tileXToLon(int x, int zoom);103 149 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java
r30241 r30248 3 3 4 4 import java.io.IOException; 5 6 import org.openstreetmap.gui.jmapviewer.OsmMercator; 5 7 6 8 public abstract class AbstractTMSTileSource extends AbstractTileSource { … … 62 64 } 63 65 66 /* 67 * Most tilesources use OsmMercator projection. 68 */ 64 69 @Override 65 70 public int getTileSize() { 66 return 256; 71 return OsmMercator.TILE_SIZE; 72 } 73 74 @Override 75 public double getDistance(double lat1, double lon1, double lat2, double lon2) { 76 return OsmMercator.getDistance(lat1, lon1, lat2, lon2); 77 } 78 79 @Override 80 public int LonToX(double lon, int zoom) { 81 return (int )OsmMercator.LonToX(lon, zoom); 82 } 83 84 @Override 85 public int LatToY(double lat, int zoom) { 86 return (int )OsmMercator.LatToY(lat, zoom); 87 } 88 89 @Override 90 public double XToLon(int x, int zoom) { 91 return OsmMercator.XToLon(x, zoom); 92 } 93 94 @Override 95 public double YToLat(int y, int zoom) { 96 return OsmMercator.YToLat(y, zoom); 67 97 } 68 98 69 99 @Override 70 100 public double latToTileY(double lat, int zoom) { 71 double l = lat / 180 * Math.PI; 72 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l))); 73 return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI; 101 return OsmMercator.LatToY(lat, zoom) / OsmMercator.TILE_SIZE; 74 102 } 75 103 76 104 @Override 77 105 public double lonToTileX(double lon, int zoom) { 78 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;106 return OsmMercator.LonToX(lon, zoom) / OsmMercator.TILE_SIZE; 79 107 } 80 108 81 109 @Override 82 110 public double tileYToLat(int y, int zoom) { 83 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, zoom - 1)))) * 180 / Math.PI;111 return OsmMercator.YToLat(y * OsmMercator.TILE_SIZE, zoom); 84 112 } 85 113 86 114 @Override 87 115 public double tileXToLon(int x, int zoom) { 88 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;116 return OsmMercator.XToLon(x * OsmMercator.TILE_SIZE, zoom); 89 117 } 90 118 }
Note:
See TracChangeset
for help on using the changeset viewer.