Changeset 9263 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2008-07-23T17:32:42+02:00 (16 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r9095 r9263 79 79 map.addMapMarker(new MapMarkerDot(49.807, 8.644)); 80 80 81 // map.setDisplayPositionByLatLon(49.807, 8.644, 11); 81 map.setDisplayPositionByLatLon(49.807, 8.6, 11); 82 //map.setTileGridVisible(true); 82 83 } 83 84 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r9095 r9263 304 304 Tile tile = getTile(tilex, tiley_tmp, zoom); 305 305 if (tile != null) { 306 if (!tile.isLoaded()) { 307 // Paint stretched preview from the next lower zoom 308 // level (if already loaded) 309 Tile parent = tile.getParentTile(tileCache); 310 if (parent != null && parent.isLoaded()) { 311 int parentx = tile.getXtile() % 2; 312 int parenty = tile.getYtile() % 2; 313 parent.parentPaint(g, x, y, parentx, parenty); 314 } else 315 tile.paint(g, x, y); 316 } else 317 tile.paint(g, x, y); 306 tile.paint(g, x, y); 307 if (tileGridVisible) 308 g.drawRect(x, y, Tile.WIDTH, Tile.HEIGHT); 318 309 } 319 if (tileGridVisible)320 g.drawRect(x, y, Tile.WIDTH, Tile.HEIGHT);321 310 tiley_tmp++; 322 311 } 323 312 tilex++; 324 313 } 314 g.fillOval(getWidth()/2 - 5, getHeight()/2 - 5, 10, 10); 315 g.drawString("Test", 50, 10); 325 316 if (!mapMarkersVisible || mapMarkerList == null) 326 317 return; … … 400 391 tile = new Tile(tilex, tiley, zoom, loadingImage); 401 392 tileCache.addTile(tile); 393 tile.loadPlaceholderFromCache(tileCache); 402 394 } 403 395 if (!tile.isLoaded()) { … … 409 401 return; 410 402 try { 411 //Thread.sleep(500);403 Thread.sleep(500); 412 404 tile.loadTileImage(); 413 405 repaint(); … … 470 462 } 471 463 464 public TileCache getTileCache() { 465 return tileCache; 466 } 467 472 468 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r9095 r9263 4 4 5 5 import java.awt.Graphics; 6 import java.awt.Graphics2D; 7 import java.awt.geom.AffineTransform; 6 8 import java.awt.image.BufferedImage; 7 9 import java.io.DataInputStream; … … 53 55 54 56 /** 57 * Tries to get tiles of a lower or higher zoom level (one or two level 58 * difference) from cache and use it as a placeholder until the tile has 59 * been loaded. 60 */ 61 public void loadPlaceholderFromCache(TileCache cache) { 62 BufferedImage tmpImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); 63 Graphics2D g = (Graphics2D) tmpImage.getGraphics(); 64 // g.drawImage(image, 0, 0, null); 65 for (int zoomDiff = 1; zoomDiff < 3; zoomDiff++) { 66 // first we check if there are already the 2^x tiles 67 // of a higher detail level 68 int zoom_high = zoom + zoomDiff; 69 if (zoom_high <= JMapViewer.MAX_ZOOM) { 70 int factor = 1 << zoomDiff; 71 int xtile_high = xtile << zoomDiff; 72 int ytile_high = ytile << zoomDiff; 73 double scale = 1.0 / factor; 74 g.setTransform(AffineTransform.getScaleInstance(scale, scale)); 75 int paintedTileCount = 0; 76 for (int x = 0; x < factor; x++) { 77 for (int y = 0; y < factor; y++) { 78 Tile tile = cache.getTile(xtile_high + x, ytile_high + y, zoom_high); 79 if (tile != null && tile.isLoaded()) { 80 paintedTileCount++; 81 tile.paint(g, x * WIDTH, y * HEIGHT); 82 } 83 } 84 } 85 if (paintedTileCount == factor * factor) { 86 image = tmpImage; 87 return; 88 } 89 } 90 91 int zoom_low = zoom - zoomDiff; 92 if (zoom_low >= JMapViewer.MIN_ZOOM) { 93 int xtile_low = xtile >> zoomDiff; 94 int ytile_low = ytile >> zoomDiff; 95 int factor = (1 << zoomDiff); 96 double scale = (double) factor; 97 AffineTransform at = new AffineTransform(); 98 int translate_x = (xtile % factor) * WIDTH; 99 int translate_y = (ytile % factor) * HEIGHT; 100 at.setTransform(scale, 0, 0, scale, -translate_x, -translate_y); 101 g.setTransform(at); 102 Tile tile = cache.getTile(xtile_low, ytile_low, zoom_low); 103 if (tile != null && tile.isLoaded()) { 104 tile.paint(g, 0, 0); 105 image = tmpImage; 106 return; 107 } 108 } 109 } 110 } 111 112 /** 55 113 * @return tile number on the x axis of this tile 56 114 */ … … 88 146 } 89 147 90 /**91 * Retrieves the "parent tile" from the specified tile cache. A parent tile92 * is the tile of a lower zoom level (coarser resolution) at the same93 * position of the map. Parent tiles are used for a preview until the tile94 * has been loaded.95 *96 * @param tileCache97 * @return98 */99 public Tile getParentTile(TileCache tileCache) {100 if (zoom < 1)101 return null;102 return tileCache.getTile(xtile / 2, ytile / 2, zoom - 1);103 }104 105 148 public synchronized void loadTileImage() throws IOException { 106 149 if (loaded) … … 132 175 if (image == null) 133 176 return; 134 /*135 * if (image.getHeight() < OSMMap.TILE_HEIGHT || image.getWidth() <136 * OSMMap.TILE_WIDTH) { x += (OSMMap.TILE_WIDTH - image.getWidth()) / 2;137 * y += (OSMMap.TILE_HEIGHT - image.getHeight()) / 2; }138 */139 177 g.drawImage(image, x, y, null); 140 }141 142 public void paint(Graphics g, int x, int y, int stretch) {143 if (image == null)144 return;145 int tx = x * stretch;146 int ty = y = stretch;147 g.drawImage(image, x, y, tx, ty, 0, 0, image.getWidth(), image.getHeight(), null);148 }149 150 /**151 * Paints one-fourth of the tile image {@link Graphics} <code>g</code> at152 * the position <code>x</code>/<code>y</code>.153 *154 * @param g155 * @param x156 * @param y157 * @param partx158 * (0 or 1) selects if the left or right part of tile should be159 * painted160 * @param party161 * (0 or 1) selects if the upper or lower part of tile should be162 * painted163 */164 public void parentPaint(Graphics g, int x, int y, int partx, int party) {165 int sx = 0;166 int sy = 0;167 if (partx == 1)168 sx = WIDTH_HALF;169 if (party == 1)170 sy = HEIGHT_HALF;171 g.drawImage(image, x, y, x + WIDTH, y + HEIGHT, sx, sy, sx + WIDTH_HALF, sy + HEIGHT_HALF,172 null);173 178 } 174 179
Note:
See TracChangeset
for help on using the changeset viewer.