Changeset 16161 in osm for applications/editors/josm/plugins/slippymap
- Timestamp:
- 2009-06-26T22:04:43+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapKey.java
r16153 r16161 12 12 * @author LuVar <lubomir.varga@freemap.sk> 13 13 * @author Dave Hansen <dave@sr71.net> 14 * @author Dave Hansen <dave@linux.vnet.ibm.com>15 14 * 16 15 */ -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r16158 r16161 5 5 import java.awt.Color; 6 6 import java.awt.Component; 7 import java.awt.Dimension; 7 8 import java.awt.Graphics; 8 9 import java.awt.Image; 9 10 import java.awt.Point; 11 import java.awt.Rectangle; 10 12 import java.awt.event.ActionEvent; 11 13 import java.awt.event.MouseAdapter; … … 14 16 import java.util.ArrayList; 15 17 import java.util.Comparator; 18 import java.util.Enumeration; 16 19 import java.util.Hashtable; 17 20 import java.util.List; … … 42 45 * @author LuVar <lubomir.varga@freemap.sk> 43 46 * @author Dave Hansen <dave@sr71.net> 44 * @author Dave Hansen <dave@linux.vnet.ibm.com>45 47 * 46 48 */ … … 296 298 void loadAllTiles() { 297 299 MapView mv = Main.map.mapView; 298 int zoom = currentZoomLevel;299 300 LatLon topLeft = mv.getLatLon(0, 0); 300 301 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 301 z12x0 = lonToTileX(topLeft.lon(), zoom); 302 z12x1 = lonToTileX(botRight.lon(), zoom); 303 z12y0 = latToTileY(topLeft.lat(), zoom); 304 z12y1 = latToTileY(botRight.lat(), zoom); 305 if (z12x0 > z12x1) { 306 int tmp = z12x0; 307 z12x0 = z12x1; 308 z12x1 = tmp; 309 } 310 if (z12y0 > z12y1) { 311 int tmp = z12y0; 312 z12y0 = z12y1; 313 z12y1 = tmp; 314 } 302 303 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel); 304 315 305 // if there is more than 18 tiles on screen in any direction, do not 316 306 // load all tiles! 317 if (z12x1 - z12x0 > 18) { 318 System.out 319 .println("Not downloading all tiles because there is more than 18 tiles on X axis!"); 320 return; 321 } 322 if (z12y1 - z12y0 > 18) { 323 System.out 324 .println("Not downloading all tiles because there is more than 18 tiles on Y axis!"); 325 return; 326 } 327 328 for (int x = z12x0 - 1; x <= z12x1; x++) { 329 for (int y = z12y0 - 1; y <= z12y1; y++) { 330 SlippyMapKey key = new SlippyMapKey(x, y, currentZoomLevel); 331 SlippyMapTile tile = tileStorage.get(key); 332 if (!key.valid) { 333 System.out.println("paint-1() made invalid key"); 334 continue; 335 } 336 if (tile == null) 337 tileStorage.put(key, 338 tile = new SlippyMapTile(x, y, currentZoomLevel)); 339 if (tile.getImage() == null) { 340 this.loadSingleTile(tile); 341 } 342 } 343 } 307 if (ts.tilesSpanned() > (18*18)) { 308 System.out.println("Not downloading all tiles because there is more than 18 tiles on an axis!"); 309 return; 310 } 311 312 for (Tile t : ts.allTiles()) { 313 SlippyMapTile tile = getOrCreateTile(t.x, t.y, currentZoomLevel); 314 if (tile.getImage() == null) { 315 this.loadSingleTile(tile); 316 } 317 }//end of for Tile t 344 318 } 345 319 … … 655 629 g.setColor(Color.black); 656 630 g.drawString("currentZoomLevel=" + currentZoomLevel, 120, 120); 657 }// end of paint metod 658 631 }// end of paint method 632 633 /** 634 * This isn't very efficient, but it is only used when the 635 * user right-clicks on the map. 636 */ 659 637 SlippyMapTile getTileForPixelpos(int px, int py) { 660 int tilex = z12x1; 661 int tiley = z12y1; 662 for (int x = z12x0; x <= z12x1; x++) { 663 664 if (pixelpos[x - z12x0 + 1][0].x > px) { 665 tilex = x - 1; 666 break; 667 } 668 } 669 if (tilex == -1) 670 return null; 671 for (int y = z12y0; y <= z12y1; y++) { 672 673 if (pixelpos[0][y - z12y0 + 1].y > py) { 674 tiley = y - 1; 675 break; 676 } 677 } 678 if (tiley == -1) { 679 return null; 680 } 681 682 SlippyMapKey key = new SlippyMapKey(tilex, tiley, currentZoomLevel); 683 if (!key.valid) { 684 System.err.println("getTileForPixelpos("+px+","+py+") made invalid key"); 685 return null; 686 } 687 SlippyMapTile tile = tileStorage.get(key); 688 if (tile == null) 689 tileStorage.put(key, tile = new SlippyMapTile(tilex, tiley, currentZoomLevel)); 638 MapView mv = Main.map.mapView; 639 Point clicked = new Point(px, py); 640 LatLon topLeft = mv.getLatLon(0, 0); 641 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 642 TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel); 643 int z = currentZoomLevel; 644 645 Tile clickedTile = null; 646 for (Tile t1 : ts.allTiles()) { 647 Tile t2 = new Tile(t1.x+1, t1.y+1); 648 Point p1 = t1.pixelPos(z); 649 Point p2 = t2.pixelPos(z); 650 Rectangle r = new Rectangle(p1,new Dimension(p2.x, p2.y)); 651 if (!r.contains(clicked)) 652 continue; 653 clickedTile = t1; 654 break; 655 } 656 if (clickedTile == null) 657 return null; 658 System.out.println("clicked on tile: " + clickedTile.x + " " + clickedTile.y); 659 SlippyMapTile tile = getOrCreateTile(clickedTile.x, clickedTile.y, currentZoomLevel); 690 660 checkTileStorage(); 691 661 return tile; … … 752 722 } 753 723 754 public boolean imageUpdate(Image img, int infoflags, int x, int y, 755 int width, int height) { 756 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 757 if ((infoflags & ERROR) != 0) { 758 String url = "unknown"; 759 for (SlippyMapTile tile : tileStorage.values()) { 760 if (tile.getImage() != img) 761 continue; 762 url = tile.getImageURL().toString(); 763 } 764 System.err.println("imageUpdate(" + img + ") error " + url +")"); 765 } 766 if ((infoflags & SOMEBITS) != 0) { 767 //if (y%100 == 0) 768 // System.out.println("imageUpdate("+img+") SOMEBITS ("+x+","+y+")"); 769 } 770 // Repaint immediately if we are done, otherwise batch up 771 // repaint requests every 100 milliseconds 772 needRedraw = true; 773 Main.map.repaint(done ? 0 : 100); 774 return !done; 775 } 724 private SlippyMapTile imgToTile(Image img) { 725 // we use the enumeration to avoid ConcurrentUpdateExceptions 726 // with other users of the tileStorage 727 Enumeration<SlippyMapTile> e = tileStorage.elements(); 728 while (e.hasMoreElements()) { 729 SlippyMapTile t = e.nextElement(); 730 if (t.getImageNoTimestamp() != img) { 731 continue; 732 } 733 return t; 734 } 735 return null; 736 } 737 738 private static int nr_loaded = 0; 739 private static int at_zoom = -1; 740 741 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 742 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 743 SlippyMapTile imageTile = imgToTile(img); 744 if (imageTile == null) { 745 return false; 746 } 747 748 if ((infoflags & ERROR) != 0) { 749 String url; // = "unknown"; 750 url = imageTile.getImageURL().toString(); 751 System.err.println("imageUpdate(" + img + ") error " + url + ")"); 752 } 753 if (((infoflags & ALLBITS) != 0)) { 754 int z = imageTile.getZoom(); 755 if (z == at_zoom) { 756 nr_loaded++; 757 } else { 758 System.out.println("downloaded " + nr_loaded + " at: " + at_zoom + " now going to " + z); 759 nr_loaded = 0; 760 at_zoom = z; 761 } 762 imageTile.markAsDownloaded(); 763 } 764 if ((infoflags & SOMEBITS) != 0) { 765 // if (y%100 == 0) 766 //System.out.println("imageUpdate("+img+") SOMEBITS ("+x+","+y+")"); 767 } 768 // Repaint immediately if we are done, otherwise batch up 769 // repaint requests every 100 milliseconds 770 needRedraw = true; 771 Main.map.repaint(done ? 0 : 100); 772 return !done; 773 } 776 774 777 775 /* -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java
r16153 r16161 17 17 * @author LuVar <lubomir.varga@freemap.sk> 18 18 * @author Dave Hansen <dave@sr71.net> 19 * @author Dave Hansen <dave@linux.vnet.ibm.com>20 19 * 21 20 */
Note:
See TracChangeset
for help on using the changeset viewer.