Ignore:
Timestamp:
2016-08-15T14:45:38+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13287 - Projection updates to support multiple projections (patch by michael2402) - gsoc-core

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileCoordinateConverter.java

    r10651 r10805  
    66
    77import org.openstreetmap.gui.jmapviewer.Tile;
     8import org.openstreetmap.gui.jmapviewer.TileXY;
    89import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     10import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    911import org.openstreetmap.josm.data.coor.LatLon;
     12import org.openstreetmap.josm.data.projection.Projecting;
     13import org.openstreetmap.josm.data.projection.ShiftedProjecting;
    1014import org.openstreetmap.josm.gui.MapView;
    1115import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
     
    1923    private MapView mapView;
    2024    private TileSourceDisplaySettings settings;
     25    private TileSource tileSource;
    2126
    2227    /**
    2328     * Create a new coordinate converter for the map view.
    2429     * @param mapView The map view.
     30     * @param tileSource The tile source to use when converting coordinates.
    2531     * @param settings displacement settings.
    2632     */
    27     public TileCoordinateConverter(MapView mapView, TileSourceDisplaySettings settings) {
     33    public TileCoordinateConverter(MapView mapView, TileSource tileSource, TileSourceDisplaySettings settings) {
    2834        this.mapView = mapView;
     35        this.tileSource = tileSource;
    2936        this.settings = settings;
    3037    }
     
    3239    private MapViewPoint pos(ICoordinate ll) {
    3340        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());
    3449    }
    3550
     
    5570        return pos(c1).rectTo(pos(c2)).getInView();
    5671    }
     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    }
    5789}
Note: See TracChangeset for help on using the changeset viewer.