- Timestamp:
- 2012-06-01T11:52:08+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r5017 r5261 67 67 import org.openstreetmap.josm.data.preferences.StringProperty; 68 68 import org.openstreetmap.josm.data.projection.Projection; 69 import org.openstreetmap.josm.gui.MapFrame; 69 70 import org.openstreetmap.josm.gui.MapView; 70 71 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; … … 124 125 HashSet<Tile> tileRequestsOutstanding = new HashSet<Tile>(); 125 126 @Override 126 public synchronized void tileLoadingFinished(Tile tile, boolean success) 127 { 127 public synchronized void tileLoadingFinished(Tile tile, boolean success) { 128 128 if (tile.hasError()) { 129 129 success = false; … … 143 143 144 144 @Override 145 public TileCache getTileCache() 146 { 145 public TileCache getTileCache() { 147 146 return tileCache; 148 147 } … … 189 188 } 190 189 191 void clearTileCache(ProgressMonitor monitor) 192 { 190 /** 191 * Clears the tile cache. 192 * 193 * If the current tileLoader is an instance of OsmTileLoader, a new 194 * TmsTileClearController is created and passed to the according clearCache 195 * method. 196 * 197 * @param monitor 198 * @see MemoryTileCache#clear() 199 * @see OsmFileCacheTileLoader#clearCache(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader.TileClearController) 200 */ 201 void clearTileCache(ProgressMonitor monitor) { 193 202 tileCache.clear(); 194 203 if (tileLoader instanceof OsmFileCacheTileLoader) { … … 217 226 protected boolean showErrors; 218 227 219 void redraw() 220 { 228 /** 229 * Initiates a repaint of Main.map 230 * 231 * @see Main#map 232 * @see MapFrame#repaint() 233 */ 234 void redraw() { 221 235 needRedraw = true; 222 236 Main.map.repaint(); 223 237 } 224 238 225 static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) 226 { 239 static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts) { 227 240 if(maxZoomLvl > MAX_ZOOM) { 228 241 /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/ … … 239 252 } 240 253 241 public static int getMaxZoomLvl(TileSource ts) 242 { 254 public static int getMaxZoomLvl(TileSource ts) { 243 255 return checkMaxZoomLvl(PROP_MAX_ZOOM_LVL.get(), ts); 244 256 } … … 249 261 } 250 262 251 static int checkMinZoomLvl(int minZoomLvl, TileSource ts) 252 { 263 static int checkMinZoomLvl(int minZoomLvl, TileSource ts) { 253 264 if(minZoomLvl < MIN_ZOOM) { 254 265 /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/ … … 266 277 } 267 278 268 public static int getMinZoomLvl(TileSource ts) 269 { 279 public static int getMinZoomLvl(TileSource ts) { 270 280 return checkMinZoomLvl(PROP_MIN_ZOOM_LVL.get(), ts); 271 281 } … … 317 327 } 318 328 329 /** 330 * Creates and returns a new TileSource instance depending on the {@link ImageryType} 331 * of the passed ImageryInfo object. 332 * 333 * If no appropriate TileSource is found, null is returned. 334 * Currently supported ImageryType are {@link ImageryType#TMS}, 335 * {@link ImageryType#BING}, {@link ImageryType#SCANEX}. 336 * 337 * @param info 338 * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found. 339 * @throws IllegalArgumentException 340 */ 319 341 public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException { 320 342 if (info.getImageryType() == ImageryType.TMS) { … … 351 373 } 352 374 353 private void initTileSource(TileSource tileSource) 354 { 375 private void initTileSource(TileSource tileSource) { 355 376 this.tileSource = tileSource; 356 377 attribution.initialize(tileSource); … … 624 645 } 625 646 626 void zoomChanged() 627 { 647 void zoomChanged() { 628 648 /*if (debug) { 629 649 Main.debug("zoomChanged(): " + currentZoomLevel); … … 634 654 } 635 655 636 int getMaxZoomLvl() 637 { 656 int getMaxZoomLvl() { 638 657 if (info.getMaxZoom() != 0) 639 658 return checkMaxZoomLvl(info.getMaxZoom(), tileSource); … … 642 661 } 643 662 644 int getMinZoomLvl() 645 { 663 int getMinZoomLvl() { 646 664 return getMinZoomLvl(tileSource); 647 665 } … … 652 670 * @return true, if zoom increasing was successfull, false othervise 653 671 */ 654 public boolean zoomIncreaseAllowed() 655 { 672 public boolean zoomIncreaseAllowed() { 656 673 boolean zia = currentZoomLevel < this.getMaxZoomLvl(); 657 674 /*if (debug) { … … 660 677 return zia; 661 678 } 662 public boolean increaseZoomLevel()663 {679 680 public boolean increaseZoomLevel() { 664 681 if (zoomIncreaseAllowed()) { 665 682 currentZoomLevel++; … … 676 693 } 677 694 678 public boolean setZoomLevel(int zoom) 679 { 695 public boolean setZoomLevel(int zoom) { 680 696 if (zoom == currentZoomLevel) return true; 681 697 if (zoom > this.getMaxZoomLvl()) return false; … … 691 707 * @return true, if zoom increasing was successfull, false othervise 692 708 */ 693 public boolean zoomDecreaseAllowed() 694 { 709 public boolean zoomDecreaseAllowed() { 695 710 return currentZoomLevel > this.getMinZoomLvl(); 696 711 } 712 697 713 public boolean decreaseZoomLevel() { 698 714 //int minZoom = this.getMinZoomLvl(); … … 724 740 return new Tile(tileSource, x, y, zoom); 725 741 } 742 726 743 synchronized Tile getOrCreateTile(int x, int y, int zoom) { 727 744 Tile tile = getTile(x, y, zoom); … … 746 763 } 747 764 748 synchronized boolean loadTile(Tile tile, boolean force) 749 { 765 synchronized boolean loadTile(Tile tile, boolean force) { 750 766 if (tile == null) 751 767 return false; … … 803 819 return !done; 804 820 } 821 805 822 boolean imageLoaded(Image i) { 806 823 if (i == null) … … 811 828 return false; 812 829 } 813 Image getLoadedTileImage(Tile tile) 814 { 830 831 /** 832 * Returns the image for the given tile if both tile and image are loaded. 833 * Otherwise returns null. 834 * 835 * @param tile the Tile for which the image should be returned 836 * @return the image of the tile or null. 837 */ 838 Image getLoadedTileImage(Tile tile) { 815 839 if (!tile.isLoaded()) 816 840 return null; … … 821 845 } 822 846 823 LatLon tileLatLon(Tile t) 824 { 847 LatLon tileLatLon(Tile t) { 825 848 int zoom = t.getZoom(); 826 849 return new LatLon(tileSource.tileYToLat(t.getYtile(), zoom), … … 828 851 } 829 852 830 Rectangle tileToRect(Tile t1) 831 { 853 Rectangle tileToRect(Tile t1) { 832 854 /* 833 855 * We need to get a box in which to draw, so advance by one tile in … … 847 869 // 'border' is the screen cordinates that need to be drawn. 848 870 // We must not draw outside of it. 849 void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) 850 { 871 void drawImageInside(Graphics g, Image sourceImg, Rectangle source, Rectangle border) { 851 872 Rectangle target = source; 852 873 … … 899 920 } 900 921 } 922 901 923 // This function is called for several zoom levels, not just 902 924 // the current one. It should not trigger any tiles to be … … 1018 1040 return Main.map.mapView.getPoint(Main.getProjection().latlon2eastNorth(ll).add(getDx(), getDy())); 1019 1041 } 1042 1020 1043 private Point pixelPos(Tile t) { 1021 1044 double lon = tileSource.tileXToLon(t.getXtile(), t.getZoom()); … … 1023 1046 return pixelPos(tmpLL); 1024 1047 } 1048 1025 1049 private LatLon getShiftedLatLon(EastNorth en) { 1026 1050 return Main.getProjection().eastNorth2latlon(en.add(-getDx(), -getDy())); 1027 1051 } 1052 1028 1053 private Coordinate getShiftedCoord(EastNorth en) { 1029 1054 LatLon ll = getShiftedLatLon(en); … … 1080 1105 } 1081 1106 } 1107 1082 1108 boolean tooSmall() { 1083 1109 return this.tilesSpanned() < 2.1; 1084 1110 } 1111 1085 1112 boolean tooLarge() { 1086 1113 return this.tilesSpanned() > 10; 1087 1114 } 1115 1088 1116 boolean insane() { 1089 1117 return this.tilesSpanned() > 100; 1090 1118 } 1119 1091 1120 double tilesSpanned() { 1092 1121 return Math.sqrt(1.0 * this.size()); … … 1103 1132 * already in the tileCache. 1104 1133 */ 1105 List<Tile> allExistingTiles() 1106 { 1134 List<Tile> allExistingTiles() { 1107 1135 return this.__allTiles(false); 1108 1136 } 1109 List<Tile> allTilesCreate()1110 {1137 1138 List<Tile> allTilesCreate() { 1111 1139 return this.__allTiles(true); 1112 1140 } 1113 private List<Tile> __allTiles(boolean create)1114 {1141 1142 private List<Tile> __allTiles(boolean create) { 1115 1143 // Tileset is either empty or too large 1116 1144 if (zoom == 0 || this.insane()) … … 1132 1160 return ret; 1133 1161 } 1134 private List<Tile> allLoadedTiles()1135 {1162 1163 private List<Tile> allLoadedTiles() { 1136 1164 List<Tile> ret = new ArrayList<Tile>(); 1137 1165 for (Tile t : this.allExistingTiles()) { … … 1142 1170 } 1143 1171 1144 void loadAllTiles(boolean force) 1145 { 1172 void loadAllTiles(boolean force) { 1146 1173 if (!autoLoad && !force) 1147 1174 return; … … 1151 1178 } 1152 1179 1153 void loadAllErrorTiles(boolean force) 1154 { 1180 void loadAllErrorTiles(boolean force) { 1155 1181 if (!autoLoad && !force) 1156 1182 return; … … 1224 1250 } 1225 1251 1226 /**1227 */1228 1252 @Override 1229 1253 public void paint(Graphics2D g, MapView mv, Bounds bounds) {
Note:
See TracChangeset
for help on using the changeset viewer.