Ticket #679: use_parent_tiles.patch
| File use_parent_tiles.patch, 2.6 KB (added by , 18 years ago) |
|---|
-
src/OsmTile.java
diff --git a/src/OsmTile.java b/src/OsmTile.java index 572da17..23c3847 100644
a b 1 1 // License: GPL. Copyright 2007 by Tim Haussmann 2 2 3 import java.awt.geom.AffineTransform; 3 4 import java.awt.image.BufferedImage; 4 5 import java.awt.Color; 5 6 import java.awt.Graphics; 7 import java.awt.Graphics2D; 8 import java.awt.RenderingHints; 9 import java.awt.Shape; 6 10 7 11 /** 8 12 * @author Tim Haussmann … … public class OsmTile { 47 51 return iZoomLevel; 48 52 } 49 53 50 public void paint(Graphics g ){54 public void paint(Graphics g,TileDB db){ 51 55 52 56 if(iMapImage != null && ! isInvalid){ 53 57 g.drawImage( iMapImage, iX, iY, null ); … … public class OsmTile { 56 60 //draw nothing 57 61 } 58 62 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 } 63 88 } 64 89 } 65 90 … … public class OsmTile { 92 117 return "/"+toString()+".png"; 93 118 } 94 119 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 } 95 127 } -
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{ 184 184 for(int x=0; x<iVisibleTilesX; x++){ 185 185 OsmTile t = iTileDB.get(OsmTile.key(iZoomlevel, (-iOffsetX + x*OsmTile.WIDTH)/OsmTile.WIDTH, ((-iOffsetY+ y*OsmTile.HEIGHT)/OsmTile.HEIGHT))); 186 186 if(t != null){ 187 t.paint(g );187 t.paint(g,iTileDB); 188 188 } 189 189 } 190 190 }
