Changeset 10805 in josm for trunk/src/org/openstreetmap/josm/gui/layer/imagery
- Timestamp:
- 2016-08-15T14:45:38+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.