- Timestamp:
- 2016-08-15T14:45:38+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
r10699 r10805 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection; 3 4 import java.util.Collections; 5 import java.util.HashMap; 6 import java.util.Map; 7 import java.util.function.DoubleUnaryOperator; 3 8 4 9 import org.openstreetmap.josm.data.Bounds; … … 8 13 import org.openstreetmap.josm.data.projection.datum.Datum; 9 14 import org.openstreetmap.josm.data.projection.proj.Proj; 15 import org.openstreetmap.josm.tools.Utils; 10 16 11 17 /** … … 116 122 @Override 117 123 public LatLon eastNorth2latlon(EastNorth en) { 124 return eastNorth2latlon(en, LatLon::normalizeLon); 125 } 126 127 @Override 128 public LatLon eastNorth2latlonClamped(EastNorth en) { 129 LatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180)); 130 Bounds bounds = getWorldBoundsLatLon(); 131 return new LatLon(Utils.clamp(ll.lat(), bounds.getMinLat(), bounds.getMaxLat()), 132 Utils.clamp(ll.lon(), bounds.getMinLon(), bounds.getMaxLon())); 133 } 134 135 private LatLon eastNorth2latlon(EastNorth en, DoubleUnaryOperator normalizeLon) { 118 136 double[] latlonRad = proj.invproject((en.east() * toMeter - x0) / ellps.a / k0, (en.north() * toMeter - y0) / ellps.a / k0); 119 LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), LatLon.normalizeLon(Math.toDegrees(latlonRad[1]) + lon0 + pm)); 137 double lon = Math.toDegrees(latlonRad[1]) + lon0 + pm; 138 LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), normalizeLon.applyAsDouble(lon)); 120 139 return datum.toWGS84(ll); 140 } 141 142 @Override 143 public Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area) { 144 if (proj.lonIsLinearToEast()) { 145 //FIXME: Respect datum? 146 // wrap the wrold around 147 Bounds bounds = getWorldBoundsLatLon(); 148 double minEast = latlon2eastNorth(bounds.getMin()).east(); 149 double maxEast = latlon2eastNorth(bounds.getMax()).east(); 150 double dEast = maxEast - minEast; 151 if ((area.minEast < minEast || area.maxEast > maxEast) && dEast > 0) { 152 // We could handle the dEast < 0 case but we don't need it atm. 153 int minChunk = (int) Math.floor((area.minEast - minEast) / dEast); 154 int maxChunk = (int) Math.floor((area.maxEast - minEast) / dEast); 155 HashMap<ProjectionBounds, Projecting> ret = new HashMap<>(); 156 for (int chunk = minChunk; chunk <= maxChunk; chunk++) { 157 ret.put(new ProjectionBounds(Math.max(area.minEast, minEast + chunk * dEast), area.minNorth, 158 Math.min(area.maxEast, maxEast + chunk * dEast), area.maxNorth), 159 new ShiftedProjecting(this, new EastNorth(-chunk * dEast, 0))); 160 } 161 return ret; 162 } 163 } 164 165 return Collections.singletonMap(area, this); 121 166 } 122 167 … … 179 224 return projectionBoundsBox; 180 225 } 226 227 @Override 228 public Projection getBaseProjection() { 229 return this; 230 } 181 231 } -
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r10381 r10805 14 14 * factor and x/y offset. 15 15 */ 16 public interface Projection {16 public interface Projection extends Projecting { 17 17 /** 18 18 * The default scale factor in east/north units per pixel … … 22 22 */ 23 23 double getDefaultZoomInPPD(); 24 25 /**26 * Convert from lat/lon to easting/northing.27 *28 * @param ll the geographical point to convert (in WGS84 lat/lon)29 * @return the corresponding east/north coordinates30 */31 EastNorth latlon2eastNorth(LatLon ll);32 24 33 25 /** -
trunk/src/org/openstreetmap/josm/data/projection/proj/Mercator.java
r10378 r10805 120 120 return scaleFactor; 121 121 } 122 123 @Override 124 public boolean lonIsLinearToEast() { 125 return true; 126 } 122 127 } -
trunk/src/org/openstreetmap/josm/data/projection/proj/Proj.java
r10001 r10805 91 91 */ 92 92 boolean isGeographic(); 93 94 /** 95 * Checks wether the result of projecting a lon coordinate only has a linear relation to the east coordinate and 96 * is not related to lat/north at all. 97 * @return <code>true</code> if lon has a linear relationship to east only. 98 * @since 10805 99 */ 100 default boolean lonIsLinearToEast() { 101 return false; 102 } 93 103 } -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r10651 r10805 17 17 import org.openstreetmap.josm.data.coor.EastNorth; 18 18 import org.openstreetmap.josm.data.coor.LatLon; 19 import org.openstreetmap.josm.data.projection.Projecting; 19 20 import org.openstreetmap.josm.data.projection.Projection; 20 21 import org.openstreetmap.josm.gui.download.DownloadDialog; … … 28 29 public final class MapViewState { 29 30 30 private final Projecti on projection;31 private final Projecting projecting; 31 32 32 33 private final int viewWidth; … … 51 52 * @param topLeft The top left corner in east/north space. 52 53 */ 53 private MapViewState(Projecti onprojection, int viewWidth, int viewHeight, double scale, EastNorth topLeft) {54 this.projecti on= projection;54 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft) { 55 this.projecting = projection; 55 56 this.scale = scale; 56 57 this.topLeft = topLeft; … … 63 64 64 65 private MapViewState(EastNorth topLeft, MapViewState mapViewState) { 65 this.projecti on = mapViewState.projection;66 this.projecting = mapViewState.projecting; 66 67 this.scale = mapViewState.scale; 67 68 this.topLeft = topLeft; … … 74 75 75 76 private MapViewState(double scale, MapViewState mapViewState) { 76 this.projecti on = mapViewState.projection;77 this.projecting = mapViewState.projecting; 77 78 this.scale = scale; 78 79 this.topLeft = mapViewState.topLeft; … … 85 86 86 87 private MapViewState(JComponent position, MapViewState mapViewState) { 87 this.projecti on = mapViewState.projection;88 this.projecting = mapViewState.projecting; 88 89 this.scale = mapViewState.scale; 89 90 this.topLeft = mapViewState.topLeft; … … 106 107 } 107 108 108 private MapViewState(Projecti on projection, MapViewState mapViewState) {109 this.projecti on = projection;109 private MapViewState(Projecting projecting, MapViewState mapViewState) { 110 this.projecting = projecting; 110 111 this.scale = mapViewState.scale; 111 112 this.topLeft = mapViewState.topLeft; … … 201 202 */ 202 203 public Projection getProjection() { 203 return projecti on;204 return projecting.getBaseProjection(); 204 205 } 205 206 … … 269 270 */ 270 271 public MapViewState usingProjection(Projection projection) { 271 if (projection.equals(this.projecti on)) {272 if (projection.equals(this.projecting)) { 272 273 return this; 273 274 } else { … … 358 359 * Gets the current position in LatLon coordinates according to the current projection. 359 360 * @return The positon as LatLon. 361 * @see #getLatLonClamped() 360 362 */ 361 363 public LatLon getLatLon() { 362 return projection.eastNorth2latlon(getEastNorth()); 364 return projecting.getBaseProjection().eastNorth2latlon(getEastNorth()); 365 } 366 367 /** 368 * Gets the latlon coordinate clamped to the current world area. 369 * @return The lat/lon coordinate 370 * @since 10805 371 */ 372 public LatLon getLatLonClamped() { 373 return projecting.eastNorth2latlonClamped(getEastNorth()); 363 374 } 364 375 … … 474 485 */ 475 486 public Bounds getLatLonBoundsBox() { 476 return projection.getLatLonBoundsBox(getProjectionBounds()); 487 // TODO @michael2402: Use hillclimb. 488 return projecting.getBaseProjection().getLatLonBoundsBox(getProjectionBounds()); 477 489 } 478 490 -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r10757 r10805 231 231 232 232 protected void initTileSource(T tileSource) { 233 coordinateConverter = new TileCoordinateConverter(Main.map.mapView, getDisplaySettings());233 coordinateConverter = new TileCoordinateConverter(Main.map.mapView, tileSource, getDisplaySettings()); 234 234 attribution.initialize(tileSource); 235 235 … … 368 368 */ 369 369 private double getScaleFactor(int zoom) { 370 if (!Main.isDisplayingMapView()) return 1; 371 MapView mv = Main.map.mapView; 372 LatLon topLeft = mv.getLatLon(0, 0); 373 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 374 TileXY t1 = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom); 375 TileXY t2 = tileSource.latLonToTileXY(botRight.toCoordinate(), zoom); 376 377 int screenPixels = mv.getWidth()*mv.getHeight(); 378 double tilePixels = Math.abs((t2.getY()-t1.getY())*(t2.getX()-t1.getX())*tileSource.getTileSize()*tileSource.getTileSize()); 379 if (screenPixels == 0 || tilePixels == 0) return 1; 380 return screenPixels/tilePixels; 370 if (coordinateConverter != null) { 371 return coordinateConverter.getScaleFactor(zoom); 372 } else { 373 return 1; 374 } 381 375 } 382 376 … … 1246 1240 1247 1241 private LatLon getShiftedLatLon(EastNorth en) { 1248 return Main.getProjection().eastNorth2latlon(en.add(-getDisplaySettings().getDx(), -getDisplaySettings().getDy()));1242 return coordinateConverter.getProjecting().eastNorth2latlonClamped(en); 1249 1243 } 1250 1244 … … 1520 1514 @Override 1521 1515 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 1522 ProjectionBounds pb = mv.getState().getViewArea().getProjectionBounds();1523 1524 needRedraw = false; 1525 1516 // old and unused. 1517 } 1518 1519 private void drawInViewArea(Graphics2D g, MapView mv, ProjectionBounds pb) { 1526 1520 int zoom = currentZoomLevel; 1527 1521 if (getDisplaySettings().isAutoZoom()) { … … 1898 1892 allocateCacheMemory(); 1899 1893 if (memory != null) { 1900 super.paint(graphics); 1901 } 1894 doPaint(graphics); 1895 } 1896 } 1897 1898 private void doPaint(MapViewGraphics graphics) { 1899 ProjectionBounds pb = graphics.getClipBounds().getProjectionBounds(); 1900 1901 needRedraw = false; // TEMPORARY 1902 1903 drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), pb); 1902 1904 } 1903 1905 -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileCoordinateConverter.java
r10651 r10805 6 6 7 7 import org.openstreetmap.gui.jmapviewer.Tile; 8 import org.openstreetmap.gui.jmapviewer.TileXY; 8 9 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 9 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.data.projection.Projecting; 13 import org.openstreetmap.josm.data.projection.ShiftedProjecting; 10 14 import org.openstreetmap.josm.gui.MapView; 11 15 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; … … 19 23 private MapView mapView; 20 24 private TileSourceDisplaySettings settings; 25 private TileSource tileSource; 21 26 22 27 /** 23 28 * Create a new coordinate converter for the map view. 24 29 * @param mapView The map view. 30 * @param tileSource The tile source to use when converting coordinates. 25 31 * @param settings displacement settings. 26 32 */ 27 public TileCoordinateConverter(MapView mapView, TileSource DisplaySettings settings) {33 public TileCoordinateConverter(MapView mapView, TileSource tileSource, TileSourceDisplaySettings settings) { 28 34 this.mapView = mapView; 35 this.tileSource = tileSource; 29 36 this.settings = settings; 30 37 } … … 32 39 private MapViewPoint pos(ICoordinate ll) { 33 40 return mapView.getState().getPointFor(new LatLon(ll)).add(settings.getDisplacement()); 41 } 42 43 /** 44 * Gets the projecting instance to use to convert between latlon and eastnorth coordinates. 45 * @return The {@link Projecting} instance. 46 */ 47 public Projecting getProjecting() { 48 return new ShiftedProjecting(mapView.getProjection(), settings.getDisplacement()); 34 49 } 35 50 … … 55 70 return pos(c1).rectTo(pos(c2)).getInView(); 56 71 } 72 73 /** 74 * Returns average number of screen pixels per tile pixel for current mapview 75 * @param zoom zoom level 76 * @return average number of screen pixels per tile pixel 77 */ 78 public double getScaleFactor(int zoom) { 79 LatLon topLeft = mapView.getLatLon(0, 0); 80 LatLon botRight = mapView.getLatLon(mapView.getWidth(), mapView.getHeight()); 81 TileXY t1 = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom); 82 TileXY t2 = tileSource.latLonToTileXY(botRight.toCoordinate(), zoom); 83 84 int screenPixels = mapView.getWidth()*mapView.getHeight(); 85 double tilePixels = Math.abs((t2.getY()-t1.getY())*(t2.getX()-t1.getX())*tileSource.getTileSize()*tileSource.getTileSize()); 86 if (screenPixels == 0 || tilePixels == 0) return 1; 87 return screenPixels/tilePixels; 88 } 57 89 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10761 r10805 1552 1552 } 1553 1553 } 1554 1555 /** 1556 * Clamp a value to the given range 1557 * @param val The value 1558 * @param min minimum value 1559 * @param max maximum value 1560 * @return the value 1561 * @since 10805 1562 */ 1563 public static double clamp(double val, double min, double max) { 1564 if (val < min) { 1565 return min; 1566 } else if (val > max) { 1567 return max; 1568 } else { 1569 return val; 1570 } 1571 } 1554 1572 }
Note:
See TracChangeset
for help on using the changeset viewer.