Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r8470 r8510 239 239 } 240 240 241 public boolean hasAutoDownload() {241 public boolean hasAutoDownload() { 242 242 return autoDownloadEnabled; 243 243 } … … 265 265 int maxY = getImageYIndex(maxEn.north()); 266 266 267 for (int x =minX; x<=maxX; x++) {268 for (int y =minY; y<=maxY; y++) {267 for (int x = minX; x <= maxX; x++) { 268 for (int y = minY; y <= maxY; y++) { 269 269 requestedTiles.add(new Point(x, y)); 270 270 } … … 300 300 } 301 301 } 302 for (int x = 0; x<dax; ++x) {303 for (int y = 0; y<day; ++y) {302 for (int x = 0; x < dax; ++x) { 303 for (int y = 0; y < day; ++y) { 304 304 if (images[x][y] == null) { 305 images[x][y] = new GeorefImage(this);305 images[x][y] = new GeorefImage(this); 306 306 } 307 307 } … … 314 314 315 315 @Override public String getToolTipText() { 316 if (autoDownloadEnabled)316 if (autoDownloadEnabled) 317 317 return tr("WMS layer ({0}), automatically downloading in zoom {1}", getName(), resolutionText); 318 318 else … … 321 321 322 322 private int modulo(int a, int b) { 323 return a % b >= 0 ? a %b : a%b+b;323 return a % b >= 0 ? a % b : a % b+b; 324 324 } 325 325 … … 331 331 @Override 332 332 public void paint(Graphics2D g, final MapView mv, Bounds b) { 333 if (info.getUrl() == null || (usesInvalidUrl && !isInvalidUrlConfirmed)) return;333 if (info.getUrl() == null || (usesInvalidUrl && !isInvalidUrlConfirmed)) return; 334 334 335 335 if (autoResolutionEnabled && !Utils.equalsEpsilon(getBestZoom(), mv.getDist100Pixel())) { … … 340 340 341 341 ProjectionBounds bounds = mv.getProjectionBounds(); 342 bminx = getImageXIndex(bounds.minEast);343 bminy = getImageYIndex(bounds.minNorth);344 bmaxx = getImageXIndex(bounds.maxEast);345 bmaxy = getImageYIndex(bounds.maxNorth);346 347 leftEdge = (int) (bounds.minEast * getPPD());348 bottomEdge = (int) (bounds.minNorth * getPPD());342 bminx = getImageXIndex(bounds.minEast); 343 bminy = getImageYIndex(bounds.minNorth); 344 bmaxx = getImageXIndex(bounds.maxEast); 345 bmaxy = getImageYIndex(bounds.maxNorth); 346 347 leftEdge = (int) (bounds.minEast * getPPD()); 348 bottomEdge = (int) (bounds.minNorth * getPPD()); 349 349 350 350 if (zoomIsTooBig()) { 351 for (int x = 0; x<images.length; ++x) {352 for (int y = 0; y<images[0].length; ++y) {351 for (int x = 0; x < images.length; ++x) { 352 for (int y = 0; y < images[0].length; ++y) { 353 353 GeorefImage image = images[x][y]; 354 354 image.paint(g, mv, image.getXIndex(), image.getYIndex(), leftEdge, bottomEdge); … … 369 369 370 370 public int getImageXIndex(double coord) { 371 return (int) Math.floor(((coord - dx) * info.getPixelPerDegree()) / imageSize);371 return (int) Math.floor(((coord - dx) * info.getPixelPerDegree()) / imageSize); 372 372 } 373 373 374 374 public int getImageYIndex(double coord) { 375 return (int) Math.floor(((coord - dy) * info.getPixelPerDegree()) / imageSize);375 return (int) Math.floor(((coord - dy) * info.getPixelPerDegree()) / imageSize); 376 376 } 377 377 378 378 public int getImageX(int imageIndex) { 379 return (int) (imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dx * getPPD());379 return (int) (imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dx * getPPD()); 380 380 } 381 381 382 382 public int getImageY(int imageIndex) { 383 return (int) (imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dy * getPPD());383 return (int) (imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dy * getPPD()); 384 384 } 385 385 … … 442 442 } 443 443 444 protected void downloadAndPaintVisible(Graphics g, final MapView mv, boolean real) {444 protected void downloadAndPaintVisible(Graphics g, final MapView mv, boolean real) { 445 445 446 446 int newDax = dax; … … 461 461 } 462 462 463 for (int x = bminx; x<=bmaxx; ++x) {464 for (int y = bminy; y<=bmaxy; ++y){465 images[modulo(x, dax)][modulo(y,day)].changePosition(x, y);463 for (int x = bminx; x <= bmaxx; ++x) { 464 for (int y = bminy; y <= bmaxy; ++y) { 465 images[modulo(x, dax)][modulo(y, day)].changePosition(x, y); 466 466 } 467 467 } … … 470 470 Set<ProjectionBounds> areaToCache = new HashSet<>(); 471 471 472 for (int x = bminx; x<=bmaxx; ++x) {473 for (int y = bminy; y<=bmaxy; ++y){474 GeorefImage img = images[modulo(x, dax)][modulo(y,day)];472 for (int x = bminx; x <= bmaxx; ++x) { 473 for (int y = bminy; y <= bmaxy; ++y) { 474 GeorefImage img = images[modulo(x, dax)][modulo(y, day)]; 475 475 if (!img.paint(g, mv, x, y, leftEdge, bottomEdge)) { 476 476 addRequest(new WMSRequest(x, y, info.getPixelPerDegree(), real, true)); … … 487 487 } 488 488 489 @Override public void visitBoundingBox(BoundingXYVisitor v) { 490 for(int x = 0; x<dax; ++x) { 491 for(int y = 0; y<day; ++y) 492 if(images[x][y].getImage() != null){ 489 @Override 490 public void visitBoundingBox(BoundingXYVisitor v) { 491 for (int x = 0; x < dax; ++x) { 492 for (int y = 0; y < day; ++y) 493 if (images[x][y].getImage() != null) { 493 494 v.visit(images[x][y].getMin()); 494 495 v.visit(images[x][y].getMax()); … … 497 498 } 498 499 499 @Override public Action[] getMenuEntries() { 500 @Override 501 public Action[] getMenuEntries() { 500 502 return new Action[]{ 501 503 LayerListDialog.getInstance().createActivateLayerAction(this), … … 665 667 try { 666 668 for (WMSRequest request: finishedRequests) { 667 GeorefImage img = images[modulo(request.getXIndex(), dax)][modulo(request.getYIndex(),day)];669 GeorefImage img = images[modulo(request.getXIndex(), dax)][modulo(request.getYIndex(), day)]; 668 670 if (img.equalPosition(request.getXIndex(), request.getYIndex())) { 669 671 WMSException we = request.getException(); … … 684 686 super(tr("Download visible tiles")); 685 687 } 688 686 689 @Override 687 690 public void actionPerformed(ActionEvent ev) { … … 708 711 // the snapLevels, which are in meters per pixel. It works, though. 709 712 double dist = Main.map.mapView.getDist100Pixel(); 710 for (int i = snapLevels.length-2; i >= 0; i--) {711 if (snapLevels[i+1]/3 + snapLevels[i]*2/3 > dist)713 for (int i = snapLevels.length-2; i >= 0; i--) { 714 if (snapLevels[i+1]/3 + snapLevels[i]*2/3 > dist) 712 715 return snapLevels[i+1]; 713 716 } … … 724 727 */ 725 728 private static void updateResolutionSetting(WMSLayer layer, boolean snap) { 726 if (snap) {729 if (snap) { 727 730 layer.resolution = getBestZoom(); 728 731 layer.resolutionText = MapView.getDistText(layer.resolution); … … 751 754 // prevents some flickering when zooming with auto-resolution enabled 752 755 // and instead gradually updates each tile. 753 if (!snap) {754 for (int x = 0; x<layer.dax; ++x) {755 for (int y = 0; y<layer.day; ++y) {756 if (!snap) { 757 for (int x = 0; x < layer.dax; ++x) { 758 for (int y = 0; y < layer.day; ++y) { 756 759 layer.images[x][y].changePosition(-1, -1); 757 760 } … … 800 803 super(tr("Reload erroneous tiles")); 801 804 } 805 802 806 @Override 803 807 public void actionPerformed(ActionEvent ev) { … … 808 812 for (int x = 0; x < dax; ++x) { 809 813 for (int y = 0; y < day; ++y) { 810 GeorefImage img = images[modulo(x, dax)][modulo(y,day)];811 if (img.getState() == State.FAILED){814 GeorefImage img = images[modulo(x, dax)][modulo(y, day)]; 815 if (img.getState() == State.FAILED) { 812 816 addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), true, false)); 813 817 } … … 824 828 super(tr("Alpha channel")); 825 829 } 830 826 831 @Override 827 832 public void actionPerformed(ActionEvent ev) { … … 900 905 super(tr("Set WMS Bookmark")); 901 906 } 907 902 908 @Override 903 909 public void actionPerformed(ActionEvent ev) { … … 930 936 for (int x = 0; x < dax; ++x) { 931 937 for (int y = 0; y < day; ++y) { 932 GeorefImage img = images[modulo(x, dax)][modulo(y,day)];933 if (img.getState() == State.NOT_IN_CACHE){938 GeorefImage img = images[modulo(x, dax)][modulo(y, day)]; 939 if (img.getState() == State.NOT_IN_CACHE) { 934 940 addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), false, true)); 935 941 } … … 982 988 grabbers.clear(); 983 989 grabberThreads.clear(); 984 for (int i =0; i<threadCount; i++) {990 for (int i = 0; i < threadCount; i++) { 985 991 WMSGrabber grabber = getGrabber(i == 0 && threadCount > 1); 986 992 grabbers.add(grabber); … … 1014 1020 || event.getKey().equals(PROP_OVERLAP_EAST.getKey()) 1015 1021 || event.getKey().equals(PROP_OVERLAP_NORTH.getKey())) { 1016 for (int i =0; i<images.length; i++) {1017 for (int k =0; k<images[i].length; k++) {1022 for (int i = 0; i < images.length; i++) { 1023 for (int k = 0; k < images[i].length; k++) { 1018 1024 images[i][k] = new GeorefImage(this); 1019 1025 } … … 1111 1117 imageSize = in.readInt(); 1112 1118 info.setPixelPerDegree(in.readDouble()); 1113 doSetName((String) in.readObject());1114 info.setExtendedUrl((String) in.readObject());1115 images = (GeorefImage[][]) in.readObject();1119 doSetName((String) in.readObject()); 1120 info.setExtendedUrl((String) in.readObject()); 1121 images = (GeorefImage[][]) in.readObject(); 1116 1122 1117 1123 for (GeorefImage[] imgs : images) {
Note:
See TracChangeset
for help on using the changeset viewer.