Ignore:
Timestamp:
2017-04-09T11:08:10+02:00 (7 years ago)
Author:
bastiK
Message:

fixed #7427 - Support reprojection (warping) of imagery layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java

    r11830 r11858  
    1111import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
    1212import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
    13 import org.openstreetmap.josm.Main;
    1413import org.openstreetmap.josm.data.Bounds;
    1514import org.openstreetmap.josm.data.ProjectionBounds;
     
    3231    private double[] degreesPerTile;
    3332    private static final float SCALE_DENOMINATOR_ZOOM_LEVEL_1 = 559082264.0287178f;
     33    private Projection tileProjection;
    3434
    3535    /**
    3636     * Constructs a new {@code AbstractWMSTileSource}.
    3737     * @param info tile source info
     38     * @param tileProjection the tile projection
    3839     */
    39     public AbstractWMSTileSource(TileSourceInfo info) {
     40    public AbstractWMSTileSource(TileSourceInfo info, Projection tileProjection) {
    4041        super(info);
     42        this.tileProjection = tileProjection;
    4143    }
    4244
     
    4850    }
    4951
     52    public void setTileProjection(Projection tileProjection) {
     53        this.tileProjection = tileProjection;
     54        initProjection();
     55    }
     56
     57    public Projection getTileProjection() {
     58        return this.tileProjection;
     59    }
     60
    5061    /**
    5162     * Initializes class with current projection in JOSM. This call is needed every time projection changes.
    5263     */
    5364    public void initProjection() {
    54         initProjection(Main.getProjection());
     65        initProjection(this.tileProjection);
    5566    }
    5667
     
    99110    @Override
    100111    public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
    101         return Main.getProjection().eastNorth2latlon(getTileEastNorth(x, y, zoom)).toCoordinate();
     112        return tileProjection.eastNorth2latlon(getTileEastNorth(x, y, zoom)).toCoordinate();
    102113    }
    103114
     
    112123    @Override
    113124    public TileXY latLonToTileXY(double lat, double lon, int zoom) {
    114         EastNorth enPoint = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));
     125        EastNorth enPoint = tileProjection.latlon2eastNorth(new LatLon(lat, lon));
    115126        return eastNorthToTileXY(enPoint, zoom);
    116127    }
     
    144155    public Point latLonToXY(double lat, double lon, int zoom) {
    145156        double scale = getDegreesPerTile(zoom) / getTileSize();
    146         EastNorth point = Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));
     157        EastNorth point = tileProjection.latlon2eastNorth(new LatLon(lat, lon));
    147158        return new Point(
    148159                (int) Math.round((point.east() - anchorPosition.east()) / scale),
     
    164175    public ICoordinate xyToLatLon(int x, int y, int zoom) {
    165176        double scale = getDegreesPerTile(zoom) / getTileSize();
    166         Projection proj = Main.getProjection();
    167177        EastNorth ret = new EastNorth(
    168178                anchorPosition.east() + x * scale,
    169179                anchorPosition.north() - y * scale
    170180                );
    171         return proj.eastNorth2latlon(ret).toCoordinate();
     181        return tileProjection.eastNorth2latlon(ret).toCoordinate();
    172182    }
    173183
     
    197207    @Override
    198208    public String getServerCRS() {
    199         return Main.getProjection().toCode();
     209        return this.tileProjection.toCode();
    200210    }
    201211}
Note: See TracChangeset for help on using the changeset viewer.