Changeset 31217 in osm for applications/editors/josm/plugins/mapillary/src
- Timestamp:
- 2015-06-04T14:44:29+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31201 r31217 11 11 */ 12 12 public class MapillaryImage { 13 private String key; 14 private LatLon latLon; 15 private Double ca; 13 private final String key; 14 private final LatLon latLon; 15 private final double ca; 16 private MapillarySequence sequence; 17 16 18 private boolean isModified = false; 17 private MapillarySequence sequence; 19 private LatLon tempLatLon; 20 private double tempCa; 18 21 19 22 /** … … 32 35 this.key = key; 33 36 this.latLon = new LatLon(lat, lon); 37 this.tempLatLon = new LatLon(lat, lon); 34 38 this.ca = ca; 39 this.tempCa = ca; 35 40 } 36 41 … … 50 55 */ 51 56 public LatLon getLatLon() { 52 return latLon; 57 return tempLatLon; 58 } 59 60 /** 61 * Moves the image temporally to another position 62 * 63 * @param pos 64 */ 65 public void move(LatLon pos) { 66 this.tempLatLon = pos; 67 this.isModified = true; 68 } 69 70 /** 71 * Turns the image direction. 72 * @param ca 73 */ 74 public void turn(double ca) { 75 this.tempCa = ca; 76 this.isModified = true; 53 77 } 54 78 … … 59 83 */ 60 84 public Double getCa() { 61 return ca;85 return tempCa; 62 86 } 63 87 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31214 r31217 33 33 import java.awt.Image; 34 34 import java.awt.Point; 35 import java.awt.event.MouseAdapter; 35 36 import java.awt.event.MouseEvent; 36 37 import java.awt.event.MouseListener; 38 import java.awt.event.MouseMotionAdapter; 37 39 import java.awt.geom.AffineTransform; 38 40 import java.awt.image.AffineTransformOp; … … 43 45 import javax.swing.Action; 44 46 import javax.swing.Icon; 47 import javax.swing.SwingUtilities; 45 48 46 49 import java.util.List; … … 48 51 49 52 public class MapillaryLayer extends AbstractModifiableLayer implements 50 MouseListener,DataSetListener, EditLayerChangeListener {53 DataSetListener, EditLayerChangeListener { 51 54 52 55 public final static int SEQUENCE_MAX_JUMP_DISTANCE = 100; … … 62 65 private MapillaryToggleDialog tgd; 63 66 67 private MouseAdapter mouseAdapter; 68 64 69 public MapillaryLayer() { 65 70 super(tr("Mapillary Images")); … … 75 80 INSTANCED = true; 76 81 MapillaryLayer.INSTANCE = this; 82 startMouseAdapter(); 77 83 try { 78 84 CACHE = JCSCacheManager.getCache("Mapillary"); … … 81 87 } 82 88 if (Main.map != null && Main.map.mapView != null) { 83 Main.map.mapView.addMouseListener(this); 89 Main.map.mapView.addMouseListener(mouseAdapter); 90 Main.map.mapView.addMouseMotionListener(mouseAdapter); 84 91 Main.map.mapView.addLayer(this); 85 92 MapView.addEditLayerChangeListener(this, false); … … 98 105 } 99 106 107 public void startMouseAdapter() { 108 mouseAdapter = new MouseAdapter() { 109 110 private Point start; 111 private int lastButton; 112 113 @Override 114 public void mousePressed(MouseEvent e) { 115 lastButton = e.getButton(); 116 if (e.getButton() != MouseEvent.BUTTON1) 117 return; 118 if (Main.map.mapView.getActiveLayer() != MapillaryLayer 119 .getInstance()) 120 return; 121 Point clickPoint = e.getPoint(); 122 double snapDistance = 10; 123 double minDistance = Double.MAX_VALUE; 124 MapillaryImage closest = null; 125 for (MapillaryImage image : mapillaryData.getImages()) { 126 Point imagePoint = Main.map.mapView.getPoint(image 127 .getLatLon()); 128 imagePoint 129 .setLocation(imagePoint.getX(), imagePoint.getY()); 130 double dist = clickPoint.distanceSq(imagePoint); 131 if (minDistance > dist 132 && clickPoint.distance(imagePoint) < snapDistance) { 133 minDistance = dist; 134 closest = image; 135 } 136 } 137 start = e.getPoint(); 138 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK)) 139 mapillaryData.addMultiSelectedImage(closest); 140 else 141 mapillaryData.setSelectedImage(closest); 142 } 143 144 @Override 145 public void mouseDragged(MouseEvent e) { 146 if (MapillaryData.getInstance().getSelectedImage() != null) { 147 if (lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) { 148 MapillaryData 149 .getInstance() 150 .getSelectedImage() 151 .move(Main.map.mapView.getLatLon(e.getX(), 152 e.getY())); 153 Main.map.repaint(); 154 } else if (lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) { 155 MapillaryData 156 .getInstance() 157 .getSelectedImage().turn(Math.toDegrees(Math.atan2((e.getX() - start.x), -(e.getY() - start.y)))); 158 Main.map.repaint(); 159 } 160 } 161 } 162 }; 163 } 164 100 165 public synchronized static MapillaryLayer getInstance() { 101 166 if (MapillaryLayer.INSTANCE == null) … … 139 204 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false); 140 205 MapillaryData.INSTANCE = null; 141 Main.map.mapView.removeMouseListener( this);206 Main.map.mapView.removeMouseListener(mouseAdapter); 142 207 MapView.removeEditLayerChangeListener(this); 143 208 if (Main.map.mapView.getEditLayer() != null) … … 287 352 288 353 @Override 289 public void mouseClicked(MouseEvent e) {290 if (e.getButton() != MouseEvent.BUTTON1)291 return;292 if (Main.map.mapView.getActiveLayer() != this)293 return;294 Point clickPoint = e.getPoint();295 double snapDistance = 10;296 double minDistance = Double.MAX_VALUE;297 MapillaryImage closest = null;298 for (MapillaryImage image : mapillaryData.getImages()) {299 Point imagePoint = Main.map.mapView.getPoint(image.getLatLon());300 imagePoint.setLocation(imagePoint.getX(), imagePoint.getY());301 double dist = clickPoint.distanceSq(imagePoint);302 if (minDistance > dist303 && clickPoint.distance(imagePoint) < snapDistance) {304 minDistance = dist;305 closest = image;306 }307 }308 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK))309 mapillaryData.addMultiSelectedImage(closest);310 else311 mapillaryData.setSelectedImage(closest);312 }313 314 @Override315 354 public Object getInfoComponent() { 316 355 StringBuilder sb = new StringBuilder(); … … 333 372 } 334 373 335 // MouseListener336 @Override337 public void visitBoundingBox(BoundingXYVisitor v) {338 }339 340 @Override341 public void mousePressed(MouseEvent e) {342 }343 344 @Override345 public void mouseReleased(MouseEvent e) {346 }347 348 @Override349 public void mouseEntered(MouseEvent e) {350 }351 352 @Override353 public void mouseExited(MouseEvent e) {354 }355 356 374 // EditDataLayerChanged 357 375 @Override … … 411 429 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 412 430 } 431 432 @Override 433 public void visitBoundingBox(BoundingXYVisitor v) { 434 } 413 435 }
Note:
See TracChangeset
for help on using the changeset viewer.