Ignore:
Timestamp:
2017-04-05T11:28:03+02:00 (8 years ago)
Author:
bastik
Message:

[jmapviewer] see #josm7427 - adapt the Tile class a bit, so it can store reprojected tiles.

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r33034 r33209  
    44import java.awt.Graphics;
    55import java.awt.Graphics2D;
     6import java.awt.Point;
    67import java.awt.geom.AffineTransform;
    78import java.awt.image.BufferedImage;
     
    4041    protected int zoom;
    4142    protected BufferedImage image;
     43    protected TileAnchor anchor;
    4244    protected String key;
    4345    protected volatile boolean loaded; // field accessed by multiple threads without any monitors, needs to be volatile
     
    7577        this.ytile = ytile;
    7678        this.zoom = zoom;
    77         this.image = image;
     79        this.setImage(image);
    7880        this.key = getTileKey(source, xtile, ytile, zoom);
    7981    }
     
    239241    }
    240242
    241     public void setImage(BufferedImage image) {
    242         this.image = image;
     243    /**
     244     * Get the position of the tile inside the image.
     245     * @return the position of the tile inside the image
     246     * @see #getImage()
     247     */
     248    public TileAnchor getAnchor() {
     249        return anchor;
     250    }
     251
     252    public final synchronized void setImage(BufferedImage image) {
     253        if (image == null) {
     254            this.image = null;
     255            this.anchor = null;
     256        } else {
     257            this.image = image;
     258            this.anchor = new TileAnchor(
     259                    new Point.Double(0, 0),
     260                    new Point.Double(image.getWidth(), image.getHeight()));
     261        }
    243262    }
    244263
    245264    public void loadImage(InputStream input) throws IOException {
    246         image = ImageIO.read(input);
     265        setImage(ImageIO.read(input));
    247266    }
    248267
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r33207 r33209  
    9898
    9999    /**
     100     * Transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined).
    100101     * @param lon longitude
    101102     * @param lat latitude
    102103     * @param zoom zoom level
    103      * @return transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined)
     104     * @return the pixel coordinates
    104105     */
    105106    Point latLonToXY(double lat, double lon, int zoom);
    106107
    107108    /**
     109     * Transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined).
    108110     * @param point point
    109111     * @param zoom zoom level
    110      * @return transforms longitude and latitude to pixel space (as if all tiles at specified zoom level where joined)
     112     * @return the pixel coordinates
    111113     */
    112114    Point latLonToXY(ICoordinate point, int zoom);
    113115
    114116    /**
     117     * Transforms a point in pixel space to longitude/latitude (WGS84).
    115118     * @param point point
    116119     * @param zoom zoom level
     
    120123
    121124    /**
    122      *
     125     * Transforms a point in pixel space to longitude/latitude (WGS84).
    123126     * @param x X coordinate
    124127     * @param y Y coordinate
     
    129132
    130133    /**
     134     * Transforms longitude and latitude to tile indices.
    131135     * @param lon longitude
    132136     * @param lat latitude
     
    137141
    138142    /**
    139      *
     143     * Transforms longitude and latitude to tile indices.
    140144     * @param point point
    141145     * @param zoom zoom level
     
    145149
    146150    /**
    147      * @param xy X/Y coordinates
     151     * Transforms tile indices to longitude and latitude.
     152     * @param xy X/Y tile indices
    148153     * @param zoom zoom level
    149154     * @return WGS84 coordinates of given tile
     
    152157
    153158    /**
    154      *
     159     * Determines to longitude and latitude of a tile.
     160     * (Refers to the tile origin - upper left tile corner)
    155161     * @param tile Tile
    156162     * @return WGS84 coordinates of given tile
     
    159165
    160166    /**
    161      *
    162      * @param x X coordinate
    163      * @param y Y coordinate
     167     * Transforms tile indices to longitude and latitude.
     168     * @param x x tile index
     169     * @param y y tile index
    164170     * @param zoom zoom level
    165171     * @return WGS84 coordinates of given tile
     
    168174
    169175    /**
    170      * @param zoom zoom level
    171      * @return maximum X index of tile for specified zoom level
     176     * Get maximum x index of tile for specified zoom level.
     177     * @param zoom zoom level
     178     * @return maximum x index of tile for specified zoom level
    172179     */
    173180    int getTileXMax(int zoom);
    174181
    175182    /**
    176      *
    177      * @param zoom zoom level
    178      * @return minimum X index of tile for specified zoom level
     183     * Get minimum x index of tile for specified zoom level.
     184     * @param zoom zoom level
     185     * @return minimum x index of tile for specified zoom level
    179186     */
    180187    int getTileXMin(int zoom);
    181188
    182189    /**
    183      *
    184      * @param zoom zoom level
    185      * @return maximum Y index of tile for specified zoom level
     190     * Get maximum y index of tile for specified zoom level.
     191     * @param zoom zoom level
     192     * @return maximum y index of tile for specified zoom level
    186193     */
    187194    int getTileYMax(int zoom);
    188195
    189196    /**
    190      * @param zoom zoom level
    191      * @return minimum Y index of tile for specified zoom level
     197     * Get minimum y index of tile for specified zoom level
     198     * @param zoom zoom level
     199     * @return minimum y index of tile for specified zoom level
    192200     */
    193201    int getTileYMin(int zoom);
     
    213221
    214222    /**
    215      * Convert tile indeces (x/y/zoom) into projected coordinates of the tile origin.
     223     * Convert tile indices (x/y/zoom) into projected coordinates of the tile origin.
    216224     * @param x x tile index
    217225     * @param y z tile index
     
    255263
    256264    /**
    257      * Get content reference system for this tile source.
     265     * Get coordinate reference system for this tile source.
    258266     *
    259267     * E.g. "EPSG:3857" for Google-Mercator.
    260      * @return code for the content reference system in use
     268     * @return code for the coordinate reference system in use
    261269     */
    262270    String getServerCRS();
Note: See TracChangeset for help on using the changeset viewer.