Changeset 31438 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2015-08-02T23:08:40+02:00 (9 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java
r31429 r31438 11 11 public final class FeatureAdapter { 12 12 13 private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter(); 14 private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter(); 15 private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter(); 16 13 17 private FeatureAdapter() { 14 18 // private constructor for utility classes 15 19 } 16 20 17 21 public interface BrowserAdapter { 18 22 void openLink(String url); … … 27 31 Logger getLogger(String name); 28 32 } 29 30 private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter();31 private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter();32 private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter();33 33 34 34 public static void registerBrowserAdapter(BrowserAdapter browserAdapter) { … … 51 51 return translationAdapter.tr(text, objects); 52 52 } 53 53 54 54 public static Logger getLogger(String name) { 55 55 return loggingAdapter.getLogger(name); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r31434 r31438 373 373 */ 374 374 public ICoordinate getPosition() { 375 return tileSource. XYToLatLon(center, zoom);375 return tileSource.xyToLatLon(center, zoom); 376 376 } 377 377 … … 400 400 int x = center.x + mapPointX - getWidth() / 2; 401 401 int y = center.y + mapPointY - getHeight() / 2; 402 return tileSource. XYToLatLon(x, y, zoom);402 return tileSource.xyToLatLon(x, y, zoom); 403 403 } 404 404 … … 547 547 int tilex = center.x / tilesize; 548 548 int tiley = center.y / tilesize; 549 int off_x = (center.x % tilesize);550 int off_y = (center.y % tilesize);549 int off_x = center.x % tilesize; 550 int off_y = center.y % tilesize; 551 551 552 552 int w2 = getWidth() / 2; … … 599 599 if (scrollWrapEnabled) { 600 600 // in case tilex is out of bounds, grab the tile to use for wrapping 601 int tilexWrap = (( (tilex % gridLength) + gridLength) % gridLength);601 int tilexWrap = ((tilex % gridLength) + gridLength) % gridLength; 602 602 tile = tileController.getTile(tilexWrap, tiley, zoom); 603 603 } else { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java
r31435 r31438 22 22 23 23 private static int workerThreadMaxCount = 8; 24 25 private final BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<>();26 27 private JobDispatcher() {28 addWorkerThread().firstThread = true;29 }30 31 /**32 * @return the singelton instance of the {@link JobDispatcher}33 */34 public static JobDispatcher getInstance() {35 return instance;36 }37 24 38 25 /** … … 64 51 private int workerThreadId = 0; 65 52 53 private final BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<>(); 54 55 private JobDispatcher() { 56 addWorkerThread().firstThread = true; 57 } 58 59 /** 60 * @return the singelton instance of the {@link JobDispatcher} 61 */ 62 public static JobDispatcher getInstance() { 63 return instance; 64 } 65 66 66 /** 67 67 * Removes all jobs from the queue that are currently not being processed. … … 73 73 /** 74 74 * Function to set the maximum number of workers for tile loading. 75 * @param workers maximum number of workers 75 76 */ 76 77 public static void setMaxWorkers(int workers) { … … 180 181 } 181 182 } 182 183 183 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
r31430 r31438 66 66 67 67 public int falseNorthing(int aZoomlevel) { 68 return (-1 * getMaxPixels(aZoomlevel) / 2);68 return -1 * getMaxPixels(aZoomlevel) / 2; 69 69 } 70 70 … … 81 81 */ 82 82 public double getDistance(int x1, int y1, int x2, int y2, int zoomLevel) { 83 double la1 = YToLat(y1, zoomLevel);84 double lo1 = XToLon(x1, zoomLevel);85 double la2 = YToLat(y2, zoomLevel);86 double lo2 = XToLon(x2, zoomLevel);83 double la1 = yToLat(y1, zoomLevel); 84 double lo1 = xToLon(x1, zoomLevel); 85 double la2 = yToLat(y2, zoomLevel); 86 double lo2 = xToLon(x2, zoomLevel); 87 87 88 88 return getDistance(la1, lo1, la2, lo2); … … 108 108 * Math.cos(aEndLong - aStartLong)); 109 109 110 return (EARTH_RADIUS * distance);110 return EARTH_RADIUS * distance; 111 111 } 112 112 … … 126 126 * @param aLongitude 127 127 * [-180..180] 128 * @param aZoomlevel zoom level 128 129 * @return [0..2^Zoomlevel*TILE_SIZE[ 129 130 */ … … 149 150 * @param aLat 150 151 * [-90...90] 152 * @param aZoomlevel zoom level 151 153 * @return [0..2^Zoomlevel*TILE_SIZE[ 152 154 */ … … 178 180 * @param aX 179 181 * [0..2^Zoomlevel*TILE_WIDTH[ 182 * @param aZoomlevel zoom level 180 183 * @return ]-180..180[ 181 184 */ 182 public double XToLon(int aX, int aZoomlevel) {185 public double xToLon(int aX, int aZoomlevel) { 183 186 return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0; 184 187 } … … 189 192 * @param aY 190 193 * [0..2^Zoomlevel*TILE_WIDTH[ 194 * @param aZoomlevel zoom level 191 195 * @return [MIN_LAT..MAX_LAT] is about [-85..85] 192 196 */ 193 public double YToLat(int aY, int aZoomlevel) {197 public double yToLat(int aY, int aZoomlevel) { 194 198 aY += falseNorthing(aZoomlevel); 195 199 double latitude = (Math.PI / 2) - (2 * Math.atan(Math.exp(-1.0 * aY / radius(aZoomlevel)))); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r31434 r31438 33 33 */ 34 34 public static final BufferedImage ERROR_IMAGE = loadImage("images/error.png"); 35 36 private static BufferedImage loadImage(String path) {37 try {38 return ImageIO.read(JMapViewer.class.getResourceAsStream(path));39 } catch (Exception ex) {40 ex.printStackTrace();41 return null;42 }43 }44 35 45 36 protected TileSource source; … … 85 76 this.image = image; 86 77 this.key = getTileKey(source, xtile, ytile, zoom); 78 } 79 80 private static BufferedImage loadImage(String path) { 81 try { 82 return ImageIO.read(JMapViewer.class.getResourceAsStream(path)); 83 } catch (Exception ex) { 84 ex.printStackTrace(); 85 return null; 86 } 87 87 } 88 88 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r31436 r31438 170 170 * @param aZoomlevel zoom level 171 171 * @return ]-180..180[ 172 * @deprecated use {@link # XYToLatLon(int, int, int)} instead172 * @deprecated use {@link #xyToLatLon(int, int, int)} instead 173 173 */ 174 174 @Deprecated … … 180 180 * @param aZoomlevel zoom level 181 181 * @return [MIN_LAT..MAX_LAT] 182 * @deprecated use {@link # XYToLatLon(int, int, int)} instead182 * @deprecated use {@link #xyToLatLon(int, int, int)} instead 183 183 */ 184 184 @Deprecated … … 190 190 * @return WGS84 Coordinates of given point 191 191 */ 192 ICoordinate XYToLatLon(Point point, int zoom);192 ICoordinate xyToLatLon(Point point, int zoom); 193 193 194 194 /** … … 199 199 * @return WGS84 Coordinates of given point 200 200 */ 201 ICoordinate XYToLatLon(int x, int y, int zoom);201 ICoordinate xyToLatLon(int x, int y, int zoom); 202 202 203 203 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTMSTileSource.java
r31435 r31438 153 153 @Override 154 154 public double XToLon(int x, int zoom) { 155 return osmMercator. XToLon(x, zoom);155 return osmMercator.xToLon(x, zoom); 156 156 } 157 157 158 158 @Override 159 159 public double YToLat(int y, int zoom) { 160 return osmMercator. YToLat(y, zoom);161 } 162 163 @Override 164 public ICoordinate XYToLatLon(Point point, int zoom) {165 return XYToLatLon(point.x, point.y, zoom);166 } 167 168 @Override 169 public ICoordinate XYToLatLon(int x, int y, int zoom) {160 return osmMercator.yToLat(y, zoom); 161 } 162 163 @Override 164 public ICoordinate xyToLatLon(Point point, int zoom) { 165 return xyToLatLon(point.x, point.y, zoom); 166 } 167 168 @Override 169 public ICoordinate xyToLatLon(int x, int y, int zoom) { 170 170 return new Coordinate( 171 osmMercator. YToLat(y, zoom),172 osmMercator. XToLon(x, zoom)171 osmMercator.yToLat(y, zoom), 172 osmMercator.xToLon(x, zoom) 173 173 ); 174 174 } … … 199 199 @Override 200 200 public double tileYToLat(int y, int zoom) { 201 return osmMercator. YToLat(y * tileSize, zoom);201 return osmMercator.yToLat(y * tileSize, zoom); 202 202 } 203 203 204 204 @Override 205 205 public double tileXToLon(int x, int zoom) { 206 return osmMercator. XToLon(x * tileSize, zoom);206 return osmMercator.xToLon(x * tileSize, zoom); 207 207 } 208 208 … … 220 220 public ICoordinate tileXYToLatLon(int x, int y, int zoom) { 221 221 return new Coordinate( 222 osmMercator. YToLat(y * tileSize, zoom),223 osmMercator. XToLon(x * tileSize, zoom)222 osmMercator.yToLat(y * tileSize, zoom), 223 osmMercator.xToLon(x * tileSize, zoom) 224 224 ); 225 225 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java
r31435 r31438 21 21 private static final int DEFAULT_MAXZOOM = 14; 22 22 private static final String API_KEY = "4018C5A9AECAD8868ED5DEB2E41D09F7"; 23 24 // Latitude to Y and back calculations. 25 26 /** radius of Earth at equator, m */ 27 private static double RADIUS_E = 6378137; 28 /** equator length, m */ 29 private static double EQUATOR = 40075016.68557849; 30 /** eccentricity of Earth's ellipsoid */ 31 private static double E = 0.0818191908426; 23 32 24 33 private enum ScanexLayer { … … 46 55 private ScanexLayer layer = ScanexLayer.IRS; 47 56 57 /** cached latitude used in {@link #tileYToLat(double, int)} */ 58 private double cachedLat = 0; 59 60 /** 61 * Constructs a new {@code ScanexTileSource}. 62 * @param info tile source info 63 */ 48 64 public ScanexTileSource(TileSourceInfo info) { 49 65 super(info); … … 77 93 } 78 94 79 /*80 * Latitude to Y and back calculations.81 */82 private static double RADIUS_E = 6378137; /* radius of Earth at equator, m */83 private static double EQUATOR = 40075016.68557849; /* equator length, m */84 private static double E = 0.0818191908426; /* eccentricity of Earth's ellipsoid */85 86 95 @Override 87 96 public int latToY(double lat, int zoom) { … … 111 120 * Newton's method. We cache previous calculated latitude, 112 121 * because new one is usually close to the old one. In case 113 * if solution gets out of bounds, we reset to a new random 114 * value. 122 * if solution gets out of bounds, we reset to a new random value. 115 123 */ 116 private double cachedLat = 0;117 124 private double tileYToLat(double y, int zoom) { 118 125 double lat0; … … 126 133 r.nextInt((int) (OsmMercator.MAX_LAT - OsmMercator.MIN_LAT)); 127 134 } 128 } while ( (Math.abs(lat0 - lat) > 0.000001));135 } while (Math.abs(lat0 - lat) > 0.000001); 129 136 130 137 cachedLat = lat; … … 141 148 double ec = Math.exp((1 - y/zoom)*Math.PI); 142 149 143 double f = (Math.tan(Math.PI/4+lat/2) -144 ec * Math.pow(Math.tan(Math.PI/4 + Math.asin(E * sinl)/2), E) );150 double f = Math.tan(Math.PI/4+lat/2) - 151 ec * Math.pow(Math.tan(Math.PI/4 + Math.asin(E * sinl)/2), E); 145 152 double df = 1/(1 - sinl) - ec * E * cosl/((1 - E * sinl) * 146 153 (Math.sqrt(1 - E * E * sinl * sinl)));
Note:
See TracChangeset
for help on using the changeset viewer.