Changeset 18263 in josm
- Timestamp:
- 2021-10-09T20:42:32+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer/geoimage
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r18248 r18263 63 63 import org.openstreetmap.josm.gui.layer.Layer; 64 64 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 65 import org.openstreetmap.josm.gui.util.imagery.Vector3D; 65 66 import org.openstreetmap.josm.tools.ImageProvider; 66 67 import org.openstreetmap.josm.tools.Utils; … … 452 453 if (e != null && e.getPos() != null) { 453 454 Point p = mv.getPoint(e.getPos()); 454 455 int imgWidth; 456 int imgHeight; 457 if (useThumbs && e.hasThumbnail()) { 458 Dimension d = scaledDimension(e.getThumbnail()); 459 if (d != null) { 460 imgWidth = d.width; 461 imgHeight = d.height; 462 } else { 463 imgWidth = -1; 464 imgHeight = -1; 465 } 466 } else { 467 imgWidth = selectedIcon.getIconWidth(); 468 imgHeight = selectedIcon.getIconHeight(); 469 } 455 Dimension imgDim = getImageDimension(e); 470 456 471 457 if (e.getExifImgDir() != null) { 472 // Multiplier must be larger than sqrt(2)/2=0.71. 473 double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85); 474 double arrowwidth = arrowlength / 1.4; 475 476 double dir = e.getExifImgDir(); 477 // Rotate 90 degrees CCW 478 double headdir = (dir < 90) ? dir + 270 : dir - 90; 479 double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90; 480 double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90; 481 482 double ptx = p.x + Math.cos(Utils.toRadians(headdir)) * arrowlength; 483 double pty = p.y + Math.sin(Utils.toRadians(headdir)) * arrowlength; 484 485 double ltx = p.x + Math.cos(Utils.toRadians(leftdir)) * arrowwidth/2; 486 double lty = p.y + Math.sin(Utils.toRadians(leftdir)) * arrowwidth/2; 487 488 double rtx = p.x + Math.cos(Utils.toRadians(rightdir)) * arrowwidth/2; 489 double rty = p.y + Math.sin(Utils.toRadians(rightdir)) * arrowwidth/2; 490 491 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 492 g.setColor(new Color(255, 255, 255, 192)); 493 int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; 494 int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; 495 g.fillPolygon(xar, yar, 4); 496 g.setColor(Color.black); 497 g.setStroke(new BasicStroke(1.2f)); 498 g.drawPolyline(xar, yar, 3); 458 Vector3D imgRotation = ImageViewerDialog.getInstance().getRotation(e); 459 drawDirectionArrow(g, p, e.getExifImgDir() 460 + (imgRotation != null ? Utils.toDegrees(imgRotation.getPolarAngle()) : 0d), imgDim); 499 461 } 500 462 501 463 if (useThumbs && e.hasThumbnail()) { 502 464 g.setColor(new Color(128, 0, 0, 122)); 503 g.fillRect(p.x - img Width / 2, p.y - imgHeight / 2, imgWidth, imgHeight);465 g.fillRect(p.x - imgDim.width / 2, p.y - imgDim.height / 2, imgDim.width, imgDim.height); 504 466 } else { 505 467 selectedIcon.paintIcon(mv, g, 506 p.x - imgWidth / 2, 507 p.y - imgHeight / 2); 508 } 509 } 510 } 468 p.x - imgDim.width / 2, 469 p.y - imgDim.height / 2); 470 } 471 } 472 } 473 } 474 475 protected Dimension getImageDimension(ImageEntry e) { 476 if (useThumbs && e.hasThumbnail()) { 477 Dimension d = scaledDimension(e.getThumbnail()); 478 return d != null ? d : new Dimension(-1, -1); 479 } else { 480 return new Dimension(selectedIcon.getIconWidth(), selectedIcon.getIconHeight()); 481 } 482 } 483 484 protected static void drawDirectionArrow(Graphics2D g, Point p, double dir, Dimension imgDim) { 485 System.out.println(dir); 486 // Multiplier must be larger than sqrt(2)/2=0.71. 487 double arrowlength = Math.max(25, Math.max(imgDim.width, imgDim.height) * 0.85); 488 double arrowwidth = arrowlength / 1.4; 489 490 // Rotate 90 degrees CCW 491 double headdir = (dir < 90) ? dir + 270 : dir - 90; 492 double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90; 493 double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90; 494 495 double ptx = p.x + Math.cos(Utils.toRadians(headdir)) * arrowlength; 496 double pty = p.y + Math.sin(Utils.toRadians(headdir)) * arrowlength; 497 498 double ltx = p.x + Math.cos(Utils.toRadians(leftdir)) * arrowwidth/2; 499 double lty = p.y + Math.sin(Utils.toRadians(leftdir)) * arrowwidth/2; 500 501 double rtx = p.x + Math.cos(Utils.toRadians(rightdir)) * arrowwidth/2; 502 double rty = p.y + Math.sin(Utils.toRadians(rightdir)) * arrowwidth/2; 503 504 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 505 g.setColor(new Color(255, 255, 255, 192)); 506 int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; 507 int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; 508 g.fillPolygon(xar, yar, 4); 509 g.setColor(Color.black); 510 g.setStroke(new BasicStroke(1.2f)); 511 g.drawPolyline(xar, yar, 3); 511 512 } 512 513 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r18246 r18263 32 32 import org.openstreetmap.josm.data.preferences.IntegerProperty; 33 33 import org.openstreetmap.josm.gui.MainApplication; 34 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 34 35 import org.openstreetmap.josm.gui.layer.geoimage.viewers.projections.IImageViewer; 35 36 import org.openstreetmap.josm.gui.layer.geoimage.viewers.projections.ImageProjectionRegistry; … … 37 38 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings.FilterChangeListener; 38 39 import org.openstreetmap.josm.gui.util.GuiHelper; 40 import org.openstreetmap.josm.gui.util.imagery.Vector3D; 39 41 import org.openstreetmap.josm.spi.preferences.Config; 40 42 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; … … 510 512 } 511 513 } 512 // We have to update the mousePointInImg for 360 image panning, as otherwise the panning 513 // never stops. 514 // We have to update the mousePointInImg for 360 image panning, as otherwise the panning never stops. 514 515 // This does not work well with the perspective viewer at this time (2021-08-26). 515 if (entry != null && Projections.EQUIRECTANGULAR == entry.getProjectionType()) { 516 boolean is360panning = entry != null && Projections.EQUIRECTANGULAR == entry.getProjectionType(); 517 if (is360panning) { 516 518 this.mousePointInImg = p; 517 519 } 518 520 ImageDisplay.this.repaint(); 521 if (is360panning) { 522 // repaint direction arrow 523 MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class).forEach(AbstractMapViewPaintable::invalidate); 524 } 519 525 } 520 526 … … 983 989 984 990 /** 991 * Get the rotation in the image viewer for an entry 992 * @param entry The entry to get the rotation for. May be {@code null}. 993 * @return the current rotation in the image viewer, or {@code null} 994 * @since 18263 995 */ 996 public Vector3D getRotation(IImageEntry<?> entry) { 997 return entry != null ? getIImageViewer(entry).getRotation() : null; 998 } 999 1000 /** 985 1001 * Ensure that a rectangle isn't zoomed in too much 986 1002 * @param rectangle The rectangle to get (typically the visible area) -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r18247 r18263 22 22 import java.util.concurrent.Future; 23 23 import java.util.stream.Collectors; 24 24 25 import javax.swing.AbstractAction; 25 26 import javax.swing.Box; … … 49 50 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 50 51 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings; 52 import org.openstreetmap.josm.gui.util.imagery.Vector3D; 51 53 import org.openstreetmap.josm.tools.ImageProvider; 52 54 import org.openstreetmap.josm.tools.Logging; … … 123 125 JButton btn = new JButton(action); 124 126 btn.setPreferredSize(buttonDim); 125 btn.addPropertyChangeListener("enabled", propertyChangeEvent -> action.setEnabled(Boolean.TRUE.equals(propertyChangeEvent.getNewValue())));127 btn.addPropertyChangeListener("enabled", e -> action.setEnabled(Boolean.TRUE.equals(e.getNewValue()))); 126 128 return btn; 127 129 } … … 626 628 627 629 /** 630 * Returns the rotation of the currently displayed image. 631 * @param entry The entry to get the rotation for. May be {@code null}. 632 * @return the rotation of the currently displayed image, or {@code null} 633 * @since 18263 634 */ 635 public Vector3D getRotation(IImageEntry<?> entry) { 636 return imgDisplay.getRotation(entry); 637 } 638 639 /** 628 640 * Returns whether the center view is currently active. 629 641 * @return {@code true} if the center view is active, {@code false} otherwise -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/viewers/projections/Equirectangular.java
r18246 r18263 56 56 57 57 @Override 58 public doublegetRotation() {59 return this.cameraPlane.getRotation() .getAzimuthalAngle();58 public Vector3D getRotation() { 59 return this.cameraPlane.getRotation(); 60 60 } 61 61 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/viewers/projections/IImageViewer.java
r18246 r18263 13 13 import org.openstreetmap.josm.data.imagery.street_level.Projections; 14 14 import org.openstreetmap.josm.gui.layer.geoimage.ImageDisplay; 15 import org.openstreetmap.josm.gui.util.imagery.Vector3D; 15 16 16 17 /** … … 45 46 * Get the current rotation in the image viewer 46 47 * @return The rotation 48 * @since 18263 47 49 */ 48 default doublegetRotation() {49 return 0;50 default Vector3D getRotation() { 51 return null; 50 52 } 51 53
Note:
See TracChangeset
for help on using the changeset viewer.