Ticket #679: use_parent_tiles.patch

File use_parent_tiles.patch, 2.6 KB (added by JohannesRudolph, 18 years ago)

The patch

  • src/OsmTile.java

    diff --git a/src/OsmTile.java b/src/OsmTile.java
    index 572da17..23c3847 100644
    a b  
    11// License: GPL. Copyright 2007 by Tim Haussmann
    22
     3import java.awt.geom.AffineTransform;
    34import java.awt.image.BufferedImage;
    45import java.awt.Color;
    56import java.awt.Graphics;
     7import java.awt.Graphics2D;
     8import java.awt.RenderingHints;
     9import java.awt.Shape;
    610
    711/**
    812 * @author Tim Haussmann
    public class OsmTile {  
    4751                return iZoomLevel;
    4852        }
    4953       
    50         public void paint(Graphics g){
     54        public void paint(Graphics g,TileDB db){
    5155               
    5256                if(iMapImage != null && ! isInvalid){
    5357                        g.drawImage( iMapImage, iX, iY, null );
    public class OsmTile {  
    5660                        //draw nothing
    5761                }
    5862                else{
    59                         g.setColor(Color.RED);
    60                         g.drawLine(iX, iY, iX+WIDTH-1, iY+HEIGHT-1);
    61                         g.drawLine(iX, iY+HEIGHT-1, iX+WIDTH-1, iY);
    62                         g.drawRect(iX, iY, WIDTH-1, HEIGHT-1);
     63                        // first try to interpolate tile from parent                   
     64                        OsmTile parent = getParent(db);
     65                        if (parent!=null){
     66                                Graphics2D g2d = (Graphics2D) g;
     67                                AffineTransform oldTr = g2d.getTransform();
     68                                Shape oldClip = g2d.getClip();
     69                                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
     70                               
     71                                // since the parent will paint 4 tiles in the
     72                                // current zoom level we have to clip the drawing
     73                                // region to the current tile
     74                                g2d.clipRect(iX, iY, WIDTH, HEIGHT);
     75                                g2d.scale(2, 2);                               
     76                                parent.paint(g,db);
     77                               
     78                                g2d.setTransform(oldTr);
     79                                g2d.setClip(oldClip);
     80                        }
     81                        else{
     82                                // otherwise draw placeholder
     83                                g.setColor(Color.RED);
     84                                g.drawLine(iX, iY, iX+WIDTH-1, iY+HEIGHT-1);
     85                                g.drawLine(iX, iY+HEIGHT-1, iX+WIDTH-1, iY);
     86                                g.drawRect(iX, iY, WIDTH-1, HEIGHT-1);
     87                        }
    6388                }
    6489        }
    6590       
    public class OsmTile {  
    92117                return "/"+toString()+".png";
    93118        }
    94119       
     120        public OsmTile getParent(TileDB db){
     121                return iZoomLevel == 0 ? null : db.get(parentKey());
     122        }
     123
     124        public String parentKey() {
     125                return key(iZoomLevel - 1,iIndexX/2,iIndexY/2);
     126        }
    95127}
  • src/SlippyMapChooser.java

    diff --git a/src/SlippyMapChooser.java b/src/SlippyMapChooser.java
    index 14e52d8..0feaf57 100644
    a b public class SlippyMapChooser extends JComponent implements DownloadSelection{  
    184184                        for(int x=0; x<iVisibleTilesX; x++){                                   
    185185                                OsmTile t = iTileDB.get(OsmTile.key(iZoomlevel,  (-iOffsetX + x*OsmTile.WIDTH)/OsmTile.WIDTH, ((-iOffsetY+ y*OsmTile.HEIGHT)/OsmTile.HEIGHT)));
    186186                                if(t != null){
    187                                         t.paint(g);                                             
     187                                        t.paint(g,iTileDB);                                             
    188188                                }
    189189                        }
    190190                }