Changeset 22281 in osm for applications/viewer


Ignore:
Timestamp:
2010-07-12T03:48:37+02:00 (14 years ago)
Author:
yellowbkpk
Message:

The TileSource can specify the tile size. Used to allow custom tile sources to hvae differently-sized tiles e.g. for mobile tilesets.

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
4 edited

Legend:

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

    r19870 r22281  
    7373    protected JButton zoomOutButton;
    7474
     75    private TileSource tileSource;
     76
    7577    /**
    7678     * Creates a standard {@link JMapViewer} instance that can be controlled via
     
    8789    public JMapViewer(TileCache tileCache, int downloadThreadCount) {
    8890        super();
    89         tileController = new TileController(new OsmTileSource.Mapnik(), tileCache, this);
     91        tileSource = new OsmTileSource.Mapnik();
     92        tileController = new TileController(tileSource, tileCache, this);
    9093        mapMarkerList = new LinkedList<MapMarker>();
    9194        mapRectangleList = new LinkedList<MapRectangle>();
     
    9598        setLayout(null);
    9699        initializeZoomSlider();
    97         setMinimumSize(new Dimension(Tile.SIZE, Tile.SIZE));
     100        setMinimumSize(new Dimension(tileSource.getTileSize(), tileSource.getTileSize()));
    98101        setPreferredSize(new Dimension(400, 400));
    99102        setDisplayPositionByLatLon(50, 9, 3);
     
    357360        y -= center.y - getHeight() / 2;
    358361        if (checkOutside) {
    359             if (x < 0 || y < 0 || x > getWidth() || y > getHeight()) {
     362            if (x < 0 || y < 0 || x > getWidth() || y > getHeight())
    360363                return null;
    361             }
    362364        }
    363365        return new Point(x, y);
     
    382384     */
    383385    public Point getMapPosition(Coordinate coord) {
    384         if (coord != null) {
     386        if (coord != null)
    385387            return getMapPosition(coord.getLat(), coord.getLon());
    386         } else {
     388        else
    387389            return null;
    388         }
    389390    }
    390391
     
    397398     */
    398399    public Point getMapPosition(Coordinate coord, boolean checkOutside) {
    399         if (coord != null) {
     400        if (coord != null)
    400401            return getMapPosition(coord.getLat(), coord.getLon(), checkOutside);
    401         } else {
     402        else
    402403            return null;
    403         }
    404404    }
    405405
     
    410410        int iMove = 0;
    411411
    412         int tilex = center.x / Tile.SIZE;
    413         int tiley = center.y / Tile.SIZE;
    414         int off_x = (center.x % Tile.SIZE);
    415         int off_y = (center.y % Tile.SIZE);
     412        int tilesize = tileSource.getTileSize();
     413        int tilex = center.x / tilesize;
     414        int tiley = center.y / tilesize;
     415        int off_x = (center.x % tilesize);
     416        int off_y = (center.y % tilesize);
    416417
    417418        int w2 = getWidth() / 2;
     
    421422
    422423        int diff_left = off_x;
    423         int diff_right = Tile.SIZE - off_x;
     424        int diff_right = tilesize - off_x;
    424425        int diff_top = off_y;
    425         int diff_bottom = Tile.SIZE - off_y;
     426        int diff_bottom = tilesize - off_y;
    426427
    427428        boolean start_left = diff_left < diff_right;
     
    429430
    430431        if (start_top) {
    431             if (start_left)
     432            if (start_left) {
    432433                iMove = 2;
    433             else
     434            } else {
    434435                iMove = 3;
     436            }
    435437        } else {
    436             if (start_left)
     438            if (start_left) {
    437439                iMove = 1;
    438             else
     440            } else {
    439441                iMove = 0;
     442            }
    440443        } // calculate the visibility borders
    441         int x_min = -Tile.SIZE;
    442         int y_min = -Tile.SIZE;
     444        int x_min = -tilesize;
     445        int y_min = -tilesize;
    443446        int x_max = getWidth();
    444447        int y_max = getHeight();
     
    450453            painted = false;
    451454            for (int i = 0; i < 4; i++) {
    452                 if (i % 2 == 0)
     455                if (i % 2 == 0) {
    453456                    x++;
     457                }
    454458                for (int j = 0; j < x; j++) {
    455459                    if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) {
     
    459463                            painted = true;
    460464                            tile.paint(g, posx, posy);
    461                             if (tileGridVisible)
    462                                 g.drawRect(posx, posy, Tile.SIZE, Tile.SIZE);
     465                            if (tileGridVisible) {
     466                                g.drawRect(posx, posy, tilesize, tilesize);
     467                            }
    463468                        }
    464469                    }
    465470                    Point p = move[iMove];
    466                     posx += p.x * Tile.SIZE;
    467                     posy += p.y * Tile.SIZE;
     471                    posx += p.x * tilesize;
     472                    posy += p.y * tilesize;
    468473                    tilex += p.x;
    469474                    tiley += p.y;
     
    473478        }
    474479        // outer border of the map
    475         int mapSize = Tile.SIZE << zoom;
     480        int mapSize = tilesize << zoom;
    476481        g.drawRect(w2 - center.x, h2 - center.y, mapSize, mapSize);
    477482
     
    666671        if (tileSource.getMinZoom() < MIN_ZOOM)
    667672            throw new RuntimeException("Minumim zoom level too low");
     673        this.tileSource = tileSource;
    668674        tileController.setTileSource(tileSource);
    669675        zoomSlider.setMinimum(tileSource.getMinZoom());
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java

    r18772 r22281  
    5454        }
    5555
     56        public int getTileSize() {
     57            return 256;
     58        }
    5659    }
    5760
     
    8689        }
    8790
     91        @Override
    8892        public int getMaxZoom() {
    8993            return 17;
     
    103107        }
    104108
     109        @Override
    105110        public int getMaxZoom() {
    106111            return 17;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r19232 r22281  
    4848    protected boolean loading = false;
    4949    protected boolean error = false;
    50     public static final int SIZE = 256;
    5150
    5251    /**
     
    7978     */
    8079    public void loadPlaceholderFromCache(TileCache cache) {
    81         BufferedImage tmpImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
     80        BufferedImage tmpImage = new BufferedImage(source.getTileSize(), source.getTileSize(), BufferedImage.TYPE_INT_RGB);
    8281        Graphics2D g = (Graphics2D) tmpImage.getGraphics();
    8382        // g.drawImage(image, 0, 0, null);
     
    9897                        if (tile != null && tile.isLoaded()) {
    9998                            paintedTileCount++;
    100                             tile.paint(g, x * SIZE, y * SIZE);
     99                            tile.paint(g, x * source.getTileSize(), y * source.getTileSize());
    101100                        }
    102101                    }
     
    115114                double scale = factor;
    116115                AffineTransform at = new AffineTransform();
    117                 int translate_x = (xtile % factor) * SIZE;
    118                 int translate_y = (ytile % factor) * SIZE;
     116                int translate_x = (xtile % factor) * source.getTileSize();
     117                int translate_y = (ytile % factor) * source.getTileSize();
    119118                at.setTransform(scale, 0, 0, scale, -translate_x, -translate_y);
    120119                g.setTransform(at);
     
    211210
    212211    /**
    213      * Note that the hash code does not include the {@link #source}. 
     212     * Note that the hash code does not include the {@link #source}.
    214213     * Therefore a hash based collection can only contain tiles
    215      * of one {@link #source}. 
     214     * of one {@link #source}.
    216215     */
    217216    @Override
     
    226225
    227226    /**
    228      * Compares this object with <code>obj</code> based on 
    229      * the fields {@link #xtile}, {@link #ytile} and 
     227     * Compares this object with <code>obj</code> based on
     228     * the fields {@link #xtile}, {@link #ytile} and
    230229     * {@link #zoom}.
    231230     * The {@link #source} field is ignored.
     
    255254    public String getStatus() {
    256255        String status = "new";
    257         if (this.loading)
     256        if (this.loading) {
    258257            status = "loading";
    259         if (this.loaded)
     258        }
     259        if (this.loaded) {
    260260            status = "loaded";
    261         if (this.error)
     261        }
     262        if (this.error) {
    262263            status = "error";
     264        }
    263265        return status;
    264266    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r18772 r22281  
    8686     */
    8787    public String getTileType();
     88
     89    /**
     90     * Specifies how large each tile is.
     91     * @return The size of a single tile in pixels.
     92     */
     93    public int getTileSize();
    8894}
Note: See TracChangeset for help on using the changeset viewer.