Ticket #10894: GeoImageLayer_direction_arrow.patch
File GeoImageLayer_direction_arrow.patch, 7.8 KB (added by , 9 years ago) |
---|
-
src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 7 import java.awt.AlphaComposite; 8 import java.awt.BasicStroke; 8 9 import java.awt.Color; 9 10 import java.awt.Composite; 10 11 import java.awt.Dimension; … … 12 13 import java.awt.Image; 13 14 import java.awt.Point; 14 15 import java.awt.Rectangle; 16 import java.awt.RenderingHints; 15 17 import java.awt.event.MouseAdapter; 16 18 import java.awt.event.MouseEvent; 17 19 import java.awt.image.BufferedImage; … … 495 497 if (e.getPos() != null) { 496 498 Point p = mv.getPoint(e.getPos()); 497 499 500 int imgWidth = 100; 501 int imgHeight = 100; 498 502 if (useThumbs && e.thumbnail != null) { 499 503 Dimension d = scaledDimension(e.thumbnail); 500 g.setColor(new Color(128, 0, 0, 122)); 501 g.fillRect(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height); 502 } else { 503 if (e.getExifImgDir() != null) { 504 double arrowlength = 25; 505 double arrowwidth = 18; 504 imgWidth = d.width; 505 imgHeight = d.height; 506 } 507 else { 508 imgWidth = selectedIcon.getIconWidth(); 509 imgHeight = selectedIcon.getIconHeight(); 510 } 506 511 507 double dir = e.getExifImgDir(); 508 // Rotate 90 degrees CCW 509 double headdir = ( dir < 90 ) ? dir + 270 : dir - 90; 510 double leftdir = ( headdir < 90 ) ? headdir + 270 : headdir - 90; 511 double rightdir = ( headdir > 270 ) ? headdir - 270 : headdir + 90; 512 if (e.getExifImgDir() != null) { 513 // Multiplier must be larger than sqrt(2)/2=0.71. 514 double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85); 515 double arrowwidth = arrowlength / 1.4; 512 516 513 double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength; 514 double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength; 517 double dir = e.getExifImgDir(); 518 // Rotate 90 degrees CCW 519 double headdir = ( dir < 90 ) ? dir + 270 : dir - 90; 520 double leftdir = ( headdir < 90 ) ? headdir + 270 : headdir - 90; 521 double rightdir = ( headdir > 270 ) ? headdir - 270 : headdir + 90; 515 522 516 double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth/2;517 double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth/2;523 double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength; 524 double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength; 518 525 519 double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth/2;520 double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth/2;526 double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth/2; 527 double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth/2; 521 528 522 g.setColor(Color.white); 523 int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; 524 int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; 525 g.fillPolygon(xar, yar, 4); 526 } 529 double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth/2; 530 double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth/2; 527 531 532 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 533 g.setColor(new Color(255, 255, 255, 192)); 534 int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx}; 535 int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty}; 536 g.fillPolygon(xar, yar, 4); 537 g.setColor(Color.black); 538 g.setStroke(new BasicStroke(1.2f)); 539 g.drawPolyline(xar, yar, 3); 540 } 541 542 if (useThumbs && e.thumbnail != null) { 543 g.setColor(new Color(128, 0, 0, 122)); 544 g.fillRect(p.x - imgWidth / 2, p.y - imgHeight / 2, imgWidth, imgHeight); 545 } else { 528 546 selectedIcon.paintIcon(mv, g, 529 p.x - selectedIcon.getIconWidth()/ 2,530 p.y - selectedIcon.getIconHeight()/ 2);547 p.x - imgWidth / 2, 548 p.y - imgHeight / 2); 531 549 532 550 } 533 551 } … … 578 596 } 579 597 580 598 try { 599 double speed = dirGps.getDouble(GpsDirectory.TAG_GPS_SPEED); 600 String speedRef = dirGps.getString(GpsDirectory.TAG_GPS_SPEED_REF); 601 if (speedRef != null) { 602 if (speedRef.equalsIgnoreCase("M")) { 603 // miles per hour 604 speed *= 1.609344; 605 } else if (speedRef.equalsIgnoreCase("N")) { 606 // knots == nautical miles per hour 607 speed *= 1.852; 608 } 609 // default is K (km/h) 610 } 611 e.setSpeed(speed); 612 } catch (Exception ex) { 613 Main.debug(ex.getMessage()); 614 } 615 616 try { 581 617 double ele = dirGps.getDouble(GpsDirectory.TAG_GPS_ALTITUDE); 582 618 int d = dirGps.getInt(GpsDirectory.TAG_GPS_ALTITUDE_REF); 583 619 if (d == 1) { -
src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
468 468 469 469 public void setOsdText(String text) { 470 470 this.osdText = text; 471 repaint(); 471 472 } 472 473 473 474 @Override -
src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java
32 32 * or extracted from the image EXIF data. 33 33 */ 34 34 private CachedLatLon pos; 35 /** Speed in kilometer per second*/35 /** Speed in kilometer per hour */ 36 36 private Double speed; 37 37 /** Elevation (altitude) in meters */ 38 38 private Double elevation; -
src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
302 302 osd.append(tr("\nAltitude: {0} m", entry.getElevation().longValue())); 303 303 } 304 304 if (entry.getSpeed() != null) { 305 osd.append(tr("\n {0} km/h", Math.round(entry.getSpeed())));305 osd.append(tr("\nSpeed: {0} km/h", Math.round(entry.getSpeed()))); 306 306 } 307 307 if (entry.getExifImgDir() != null) { 308 308 osd.append(tr("\nDirection {0}\u00b0", Math.round(entry.getExifImgDir())));