Changeset 22281 in osm
- Timestamp:
- 2010-07-12T03:48:37+02:00 (14 years ago)
- 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 73 73 protected JButton zoomOutButton; 74 74 75 private TileSource tileSource; 76 75 77 /** 76 78 * Creates a standard {@link JMapViewer} instance that can be controlled via … … 87 89 public JMapViewer(TileCache tileCache, int downloadThreadCount) { 88 90 super(); 89 tileController = new TileController(new OsmTileSource.Mapnik(), tileCache, this); 91 tileSource = new OsmTileSource.Mapnik(); 92 tileController = new TileController(tileSource, tileCache, this); 90 93 mapMarkerList = new LinkedList<MapMarker>(); 91 94 mapRectangleList = new LinkedList<MapRectangle>(); … … 95 98 setLayout(null); 96 99 initializeZoomSlider(); 97 setMinimumSize(new Dimension( Tile.SIZE, Tile.SIZE));100 setMinimumSize(new Dimension(tileSource.getTileSize(), tileSource.getTileSize())); 98 101 setPreferredSize(new Dimension(400, 400)); 99 102 setDisplayPositionByLatLon(50, 9, 3); … … 357 360 y -= center.y - getHeight() / 2; 358 361 if (checkOutside) { 359 if (x < 0 || y < 0 || x > getWidth() || y > getHeight()) {362 if (x < 0 || y < 0 || x > getWidth() || y > getHeight()) 360 363 return null; 361 }362 364 } 363 365 return new Point(x, y); … … 382 384 */ 383 385 public Point getMapPosition(Coordinate coord) { 384 if (coord != null) {386 if (coord != null) 385 387 return getMapPosition(coord.getLat(), coord.getLon()); 386 } else {388 else 387 389 return null; 388 }389 390 } 390 391 … … 397 398 */ 398 399 public Point getMapPosition(Coordinate coord, boolean checkOutside) { 399 if (coord != null) {400 if (coord != null) 400 401 return getMapPosition(coord.getLat(), coord.getLon(), checkOutside); 401 } else {402 else 402 403 return null; 403 }404 404 } 405 405 … … 410 410 int iMove = 0; 411 411 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); 416 417 417 418 int w2 = getWidth() / 2; … … 421 422 422 423 int diff_left = off_x; 423 int diff_right = Tile.SIZE- off_x;424 int diff_right = tilesize - off_x; 424 425 int diff_top = off_y; 425 int diff_bottom = Tile.SIZE- off_y;426 int diff_bottom = tilesize - off_y; 426 427 427 428 boolean start_left = diff_left < diff_right; … … 429 430 430 431 if (start_top) { 431 if (start_left) 432 if (start_left) { 432 433 iMove = 2; 433 else434 } else { 434 435 iMove = 3; 436 } 435 437 } else { 436 if (start_left) 438 if (start_left) { 437 439 iMove = 1; 438 else440 } else { 439 441 iMove = 0; 442 } 440 443 } // 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; 443 446 int x_max = getWidth(); 444 447 int y_max = getHeight(); … … 450 453 painted = false; 451 454 for (int i = 0; i < 4; i++) { 452 if (i % 2 == 0) 455 if (i % 2 == 0) { 453 456 x++; 457 } 454 458 for (int j = 0; j < x; j++) { 455 459 if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { … … 459 463 painted = true; 460 464 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 } 463 468 } 464 469 } 465 470 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; 468 473 tilex += p.x; 469 474 tiley += p.y; … … 473 478 } 474 479 // outer border of the map 475 int mapSize = Tile.SIZE<< zoom;480 int mapSize = tilesize << zoom; 476 481 g.drawRect(w2 - center.x, h2 - center.y, mapSize, mapSize); 477 482 … … 666 671 if (tileSource.getMinZoom() < MIN_ZOOM) 667 672 throw new RuntimeException("Minumim zoom level too low"); 673 this.tileSource = tileSource; 668 674 tileController.setTileSource(tileSource); 669 675 zoomSlider.setMinimum(tileSource.getMinZoom()); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java
r18772 r22281 54 54 } 55 55 56 public int getTileSize() { 57 return 256; 58 } 56 59 } 57 60 … … 86 89 } 87 90 91 @Override 88 92 public int getMaxZoom() { 89 93 return 17; … … 103 107 } 104 108 109 @Override 105 110 public int getMaxZoom() { 106 111 return 17; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r19232 r22281 48 48 protected boolean loading = false; 49 49 protected boolean error = false; 50 public static final int SIZE = 256;51 50 52 51 /** … … 79 78 */ 80 79 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); 82 81 Graphics2D g = (Graphics2D) tmpImage.getGraphics(); 83 82 // g.drawImage(image, 0, 0, null); … … 98 97 if (tile != null && tile.isLoaded()) { 99 98 paintedTileCount++; 100 tile.paint(g, x * SIZE, y * SIZE);99 tile.paint(g, x * source.getTileSize(), y * source.getTileSize()); 101 100 } 102 101 } … … 115 114 double scale = factor; 116 115 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(); 119 118 at.setTransform(scale, 0, 0, scale, -translate_x, -translate_y); 120 119 g.setTransform(at); … … 211 210 212 211 /** 213 * Note that the hash code does not include the {@link #source}. 212 * Note that the hash code does not include the {@link #source}. 214 213 * Therefore a hash based collection can only contain tiles 215 * of one {@link #source}. 214 * of one {@link #source}. 216 215 */ 217 216 @Override … … 226 225 227 226 /** 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 230 229 * {@link #zoom}. 231 230 * The {@link #source} field is ignored. … … 255 254 public String getStatus() { 256 255 String status = "new"; 257 if (this.loading) 256 if (this.loading) { 258 257 status = "loading"; 259 if (this.loaded) 258 } 259 if (this.loaded) { 260 260 status = "loaded"; 261 if (this.error) 261 } 262 if (this.error) { 262 263 status = "error"; 264 } 263 265 return status; 264 266 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r18772 r22281 86 86 */ 87 87 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(); 88 94 }
Note:
See TracChangeset
for help on using the changeset viewer.