Changeset 4188 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-07-01T09:27:15+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r3974 r4188 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.regex.Matcher; 7 import java.util.regex.Pattern; 6 8 7 9 import org.openstreetmap.josm.io.OsmApi; … … 38 40 double pixelPerDegree = 0.0; 39 41 int maxZoom = 0; 42 int defaultMaxZoom = 0; 43 int defaultMinZoom = 0; 40 44 41 45 public ImageryInfo(String name) { … … 135 139 this.cookies=i.cookies; 136 140 this.imageryType=i.imageryType; 141 this.defaultMaxZoom=i.defaultMaxZoom; 137 142 this.pixelPerDegree=i.pixelPerDegree; 138 143 this.eulaAcceptanceRequired = null; … … 169 174 170 175 for (ImageryType type : ImageryType.values()) { 171 if (url.startsWith(type.getUrlString() + ":")) { 172 this.url = url.substring(type.getUrlString().length() + 1); 176 Matcher m = Pattern.compile(type.getUrlString()+"(?:\\[(?:(\\d+),)?(\\d+)\\])?:(.*)").matcher(url); 177 if(m.matches()) { 178 this.url = m.group(3); 173 179 this.imageryType = type; 180 if(m.group(2) != null) { 181 defaultMaxZoom = Integer.valueOf(m.group(2)); 182 maxZoom = defaultMaxZoom; 183 } 184 if(m.group(1) != null) { 185 defaultMinZoom = Integer.valueOf(m.group(1)); 186 } 174 187 return; 175 188 } … … 205 218 } 206 219 220 public int getMinZoom() { 221 return this.defaultMinZoom; 222 } 223 207 224 public String getFullUrl() { 208 return imageryType.getUrlString() + ":" + url; 225 return imageryType.getUrlString() + (defaultMaxZoom != 0 226 ? "["+(defaultMinZoom != 0 ? defaultMinZoom+",":"")+defaultMaxZoom+"]" : "") + ":" + url; 209 227 } 210 228 … … 223 241 if(pixelPerDegree != 0.0) { 224 242 res += " ("+pixelPerDegree+")"; 225 } else if(maxZoom != 0 ) {243 } else if(maxZoom != 0 && maxZoom != defaultMaxZoom) { 226 244 res += " (z"+maxZoom+")"; 227 245 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4183 r4188 92 92 public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", DEFAULT_MIN_ZOOM); 93 93 public static final IntegerProperty PROP_MAX_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".max_zoom_lvl", DEFAULT_MAX_ZOOM); 94 public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false);94 //public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false); 95 95 public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER = new BooleanProperty(PREFERENCE_PREFIX + ".add_to_slippymap_chooser", true); 96 96 public static final StringProperty PROP_TILECACHE_DIR; … … 105 105 } 106 106 107 boolean debug = false; 108 void out(String s) 109 { 110 Main.debug(s); 111 } 107 /*boolean debug = false;*/ 112 108 113 109 protected MemoryTileCache tileCache; … … 131 127 Main.map.repaint(100); 132 128 tileRequestsOutstanding.remove(tile); 133 if (debug) {134 out("tileLoadingFinished() tile: " + tile + " success: " + success);135 } 129 /*if (debug) { 130 Main.debug("tileLoadingFinished() tile: " + tile + " success: " + success); 131 }*/ 136 132 } 137 133 @Override … … 142 138 void clearTileCache() 143 139 { 144 if (debug) {145 out("clearing tile storage");146 } 140 /*if (debug) { 141 Main.debug("clearing tile storage"); 142 }*/ 147 143 tileCache = new MemoryTileCache(); 148 144 tileCache.setCacheSize(200); … … 185 181 { 186 182 if(maxZoomLvl > MAX_ZOOM) { 187 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30.");183 /*Main.debug("Max. zoom level should not be more than 30! Setting to 30.");*/ 188 184 maxZoomLvl = MAX_ZOOM; 189 185 } 190 186 if(maxZoomLvl < PROP_MIN_ZOOM_LVL.get()) { 191 System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl.");187 /*Main.debug("Max. zoom level should not be more than min. zoom level! Setting to min.");*/ 192 188 maxZoomLvl = PROP_MIN_ZOOM_LVL.get(); 193 189 } … … 211 207 { 212 208 if(minZoomLvl < MIN_ZOOM) { 213 System.err.println("minZoomLvl shouldnt be lees than "+MIN_ZOOM+"! Setting to that.");209 /*Main.debug("Min. zoom level should not be less than "+MIN_ZOOM+"! Setting to that.");*/ 214 210 minZoomLvl = MIN_ZOOM; 215 211 } 216 212 if(minZoomLvl > PROP_MAX_ZOOM_LVL.get()) { 217 System.err.println("minZoomLvl shouldnt be more than maxZoomLvl! Setting to maxZoomLvl.");213 /*Main.debug("Min. zoom level should not be more than Max. zoom level! Setting to Max.");*/ 218 214 minZoomLvl = getMaxZoomLvl(ts); 219 215 } 220 216 if (ts != null && ts.getMinZoom() > minZoomLvl) { 221 System.err.println("increasomg minZoomLvl to match tile source");217 /*Main.debug("Increasing min. zoom level to match tile source");*/ 222 218 minZoomLvl = ts.getMinZoom(); 223 219 } … … 238 234 if (info.getImageryType() == ImageryType.TMS) { 239 235 if(ImageryInfo.isUrlWithPatterns(info.getUrl())) 240 return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getM axZoom());236 return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 241 237 else 242 return new TMSTileSource(info.getName(),info.getUrl(), info.getM axZoom());238 return new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 243 239 } else if (info.getImageryType() == ImageryType.BING) 244 240 return new BingAerialTileSource(); … … 254 250 if(requireAttr) { 255 251 attrImage = tileSource.getAttributionImage(); 256 if(attrImage == null) {257 System.out.println("Attribution image was null.");252 /*if(attrImage == null) { 253 Main.debug("Attribution image was null."); 258 254 } else { 259 System.out.println("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this));260 } 255 Main.debug("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this)); 256 }*/ 261 257 262 258 attrTermsUrl = tileSource.getTermsOfUseURL(); … … 374 370 @Override 375 371 public void actionPerformed(ActionEvent ae) { 376 out("info tile: " + clickedTile);372 //Main.debug("info tile: " + clickedTile); 377 373 if (clickedTile != null) { 378 374 showMetadataTile = clickedTile; … … 438 434 @Override 439 435 public void actionPerformed(ActionEvent ae) { 440 System.out.print("flushing all tiles...");436 //Main.debug("flushing all tiles..."); 441 437 clearTileCache(); 442 System.out.println("done");438 //Main.debug("done"); 443 439 } 444 440 })); … … 508 504 void zoomChanged() 509 505 { 510 if (debug) {511 out("zoomChanged(): " + currentZoomLevel);512 } 506 /*if (debug) { 507 Main.debug("zoomChanged(): " + currentZoomLevel); 508 }*/ 513 509 needRedraw = true; 514 510 jobDispatcher.cancelOutstandingJobs(); … … 537 533 { 538 534 boolean zia = currentZoomLevel < this.getMaxZoomLvl(); 539 if (debug) {540 out("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() );541 } 535 /*if (debug) { 536 Main.debug("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() ); 537 }*/ 542 538 return zia; 543 539 } … … 546 542 if (zoomIncreaseAllowed()) { 547 543 currentZoomLevel++; 548 if (debug) {549 out("increasing zoom level to: " + currentZoomLevel);550 } 544 /*if (debug) { 545 Main.debug("increasing zoom level to: " + currentZoomLevel); 546 }*/ 551 547 zoomChanged(); 552 548 } else { 553 System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+554 "Max ZoomLvl ("+this.getMaxZoomLvl()+")reached.");549 Main.warn("Current zoom level ("+currentZoomLevel+") could not be increased. "+ 550 "Max.zZoom Level "+this.getMaxZoomLvl()+" reached."); 555 551 return false; 556 552 } … … 580 576 int minZoom = this.getMinZoomLvl(); 581 577 if (zoomDecreaseAllowed()) { 582 if (debug) {583 out("decreasing zoom level to: " + currentZoomLevel);584 } 578 /*if (debug) { 579 Main.debug("decreasing zoom level to: " + currentZoomLevel); 580 }*/ 585 581 currentZoomLevel--; 586 582 zoomChanged(); 587 583 } else { 588 System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl("+minZoom+") reached.");584 /*Main.debug("Current zoom level could not be decreased. Min. zoom level "+minZoom+" reached.");*/ 589 585 return false; 590 586 } … … 671 667 boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0); 672 668 needRedraw = true; 673 if (debug) {674 out("imageUpdate() done: " + done + " calling repaint");675 } 669 /*if (debug) { 670 Main.debug("imageUpdate() done: " + done + " calling repaint"); 671 }*/ 676 672 Main.map.repaint(done ? 0 : 100); 677 673 return !done; … … 730 726 if (border != null) { 731 727 target = source.intersection(border); 732 if (debug) {733 out("source: " + source + "\nborder: " + border + "\nintersection: " + target);734 } 728 /*if (debug) { 729 Main.debug("source: " + source + "\nborder: " + border + "\nintersection: " + target); 730 }*/ 735 731 } 736 732 … … 757 753 int img_y_end = img_y_offset + (int)(target.getHeight() * imageYScaling); 758 754 759 if (debug) {760 out("drawing image into target rect: " + target);761 } 755 /*if (debug) { 756 Main.debug("drawing image into target rect: " + target); 757 }*/ 762 758 g.drawImage(sourceImg, 763 759 target.x, target.y, … … 792 788 Image img = getLoadedTileImage(tile); 793 789 if (img == null || tile.hasError()) { 794 if (debug) {795 out("missed tile: " + tile);796 } 790 /*if (debug) { 791 Main.debug("missed tile: " + tile); 792 }*/ 797 793 missedTiles.add(tile); 798 794 continue; … … 822 818 int texty = p.y + 2 + fontHeight; 823 819 824 if (PROP_DRAW_DEBUG.get()) {820 /*if (PROP_DRAW_DEBUG.get()) { 825 821 myDrawString(g, "x=" + t.getXtile() + " y=" + t.getYtile() + " z=" + zoom + "", p.x + 2, texty); 826 822 texty += 1 + fontHeight; … … 829 825 texty += 1 + fontHeight; 830 826 } 831 } // end of if draw debug827 }*/// end of if draw debug 832 828 833 829 if (tile == showMetadataTile) { … … 847 843 848 844 String tileStatus = tile.getStatus(); 849 if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) {845 /*if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) { 850 846 myDrawString(g, tr("image " + tileStatus), p.x + 2, texty); 851 847 texty += 1 + fontHeight; 852 } 848 }*/ 853 849 854 850 if (tile.hasError()) { … … 857 853 } 858 854 859 int xCursor = -1;855 /*int xCursor = -1; 860 856 int yCursor = -1; 861 857 if (PROP_DRAW_DEBUG.get()) { … … 880 876 xCursor = t.getXtile(); 881 877 } 882 } 878 }*/ 883 879 } 884 880 … … 1007 1003 } 1008 1004 } 1009 if (debug)1005 /*if (debug) 1010 1006 if (nr_queued > 0) { 1011 out("queued to load: " + nr_queued + "/" + tiles.size() + " tiles at zoom: " + zoom);1012 } 1007 Main.debug("queued to load: " + nr_queued + "/" + tiles.size() + " tiles at zoom: " + zoom); 1008 }*/ 1013 1009 } 1014 1010 } … … 1084 1080 1085 1081 if (botRight.east() == 0.0 || botRight.north() == 0) { 1086 Main.debug("still initializing??");1082 /*Main.debug("still initializing??");*/ 1087 1083 // probably still initializing 1088 1084 return; … … 1143 1139 // Too many tiles... refuse to download 1144 1140 if (!ts.tooLarge()) { 1145 // out("size: " + ts.size() + " spanned: " + ts.tilesSpanned());1141 //Main.debug("size: " + ts.size() + " spanned: " + ts.tilesSpanned()); 1146 1142 ts.loadAllTiles(false); 1147 1143 } … … 1184 1180 missedTiles = newlyMissedTiles; 1185 1181 } 1186 if (debug && missedTiles.size() > 0) {1187 out("still missed "+missedTiles.size()+" in the end");1188 } 1182 /*if (debug && missedTiles.size() > 0) { 1183 Main.debug("still missed "+missedTiles.size()+" in the end"); 1184 }*/ 1189 1185 g.setColor(Color.red); 1190 1186 g.setFont(InfoFont); … … 1251 1247 myDrawString(g, tr("No tiles at this zoom level"), 120, 120); 1252 1248 } 1253 if (debug) {1249 /*if (debug) { 1254 1250 myDrawString(g, tr("Current zoom: {0}", currentZoomLevel), 50, 140); 1255 1251 myDrawString(g, tr("Display zoom: {0}", displayZoomLevel), 50, 155); 1256 1252 myDrawString(g, tr("Pixel scale: {0}", getScaleFactor(currentZoomLevel)), 50, 170); 1257 1253 myDrawString(g, tr("Best zoom: {0}", Math.log(getScaleFactor(1))/Math.log(2)/2+1), 50, 185); 1258 } 1254 }*/ 1259 1255 }// end of paint method 1260 1256 … … 1264 1260 */ 1265 1261 Tile getTileForPixelpos(int px, int py) { 1266 if (debug) {1267 out("getTileForPixelpos("+px+", "+py+")");1268 } 1262 /*if (debug) { 1263 Main.debug("getTileForPixelpos("+px+", "+py+")"); 1264 }*/ 1269 1265 MapView mv = Main.map.mapView; 1270 1266 Point clicked = new Point(px, py); … … 1282 1278 Rectangle r = new Rectangle(pixelPos(t1)); 1283 1279 r.add(pixelPos(t2)); 1284 if (debug) {1285 out("r: " + r + " clicked: " + clicked);1286 } 1280 /*if (debug) { 1281 Main.debug("r: " + r + " clicked: " + clicked); 1282 }*/ 1287 1283 if (!r.contains(clicked)) { 1288 1284 continue; … … 1293 1289 if (clickedTile == null) 1294 1290 return null; 1295 System.out.println("clicked on tile: " + clickedTile.getXtile() + " " + clickedTile.getYtile() +1296 " currentZoomLevel: " + currentZoomLevel); 1291 /*Main.debug("Clicked on tile: " + clickedTile.getXtile() + " " + clickedTile.getYtile() + 1292 " currentZoomLevel: " + currentZoomLevel);*/ 1297 1293 return clickedTile; 1298 1294 } -
trunk/src/org/openstreetmap/josm/gui/preferences/AddWMSLayerPanel.java
r4164 r4188 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trc; 5 6 6 7 import java.awt.Component; … … 79 80 private boolean previouslyShownUnsupportedCrsError = false; 80 81 private JTextArea tmsURL; 82 private JTextField tmsZoom; 81 83 82 84 public AddWMSLayerPanel() { … … 200 202 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 201 203 tmsView.add(tmsUrlScrollPane, GBC.eop().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 204 tmsView.add(new JLabel(trc("layer", "Zoom")), GBC.std().insets(0,0,5,0)); 205 tmsZoom = new JTextField(3); 206 tmsZoom.addKeyListener(new KeyAdapter() { 207 @Override 208 public void keyReleased(KeyEvent e) { 209 resultingLayerField.setText(buildTMSUrl()); 210 } 211 }); 212 tmsView.add(tmsZoom, GBC.eop().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 202 213 tabbedPane.addTab(tr("TMS"), tmsView); 203 214 … … 229 240 230 241 private String buildTMSUrl() { 231 StringBuilder a = new StringBuilder("tms:"); 242 StringBuilder a = new StringBuilder("tms"); 243 String z = sanitize(tmsZoom.getText()); 244 if(!z.isEmpty()) 245 a.append("["+z+"]"); 246 a.append(":"); 232 247 a.append(sanitize(tmsURL.getText())); 233 248 return a.toString();
Note:
See TracChangeset
for help on using the changeset viewer.