Changeset 31255 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-06-09T11:58:30+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31252 r31255 103 103 return tempCa; 104 104 } 105 105 106 @Override 107 public boolean equals(Object object) { 108 if (object instanceof MapillaryAbstractImage) 109 return this.getLatLon().equalsEpsilon(((MapillaryAbstractImage) object).getLatLon()); 110 return false; 111 } 112 113 @Override 114 public int hashCode() { 115 return this.getLatLon().hashCode(); 116 } 106 117 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31252 r31255 65 65 } 66 66 67 @Override68 public boolean equals(Object image) {69 if (image instanceof MapillaryImage)70 return this.key.equals(((MapillaryImage) image).getKey());71 return false;72 }73 74 @Override75 public int hashCode() {76 return this.key.hashCode();77 }78 79 67 /** 80 68 * If the MapillaryImage belongs to a MapillarySequence, returns the next -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31254 r31255 5 5 import org.apache.commons.jcs.access.CacheAccess; 6 6 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 7 import org.openstreetmap.josm.plugins.mapillary.commands.CommandMoveImage;8 import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage;9 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;10 7 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 11 8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog; … … 39 36 import java.awt.Point; 40 37 import java.awt.event.MouseAdapter; 41 import java.awt.event.MouseEvent;42 38 import java.awt.geom.AffineTransform; 43 39 import java.awt.image.AffineTransformOp; … … 64 60 65 61 private final MapillaryData mapillaryData = MapillaryData.getInstance(); 66 private final MapillaryRecord record = MapillaryRecord.getInstance();67 62 68 63 private List<Bounds> bounds; … … 111 106 112 107 public void startMouseAdapter() { 113 mouseAdapter = new MouseAdapter() { 114 115 private Point start; 116 private int lastButton; 117 private MapillaryAbstractImage closest; 118 private MapillaryAbstractImage lastClicked; 119 120 @Override 121 public void mousePressed(MouseEvent e) { 122 lastButton = e.getButton(); 123 if (e.getButton() != MouseEvent.BUTTON1) 124 return; 125 if (Main.map.mapView.getActiveLayer() != MapillaryLayer 126 .getInstance()) 127 return; 128 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 129 if (closestTemp instanceof MapillaryImage 130 || closestTemp == null) { 131 MapillaryImage closest = (MapillaryImage) closestTemp; 132 if (e.getClickCount() == 2 133 && mapillaryData.getSelectedImage() != null 134 && closest != null) { 135 for (MapillaryAbstractImage img : closest.getSequence() 136 .getImages()) { 137 mapillaryData.addMultiSelectedImage(img); 138 } 139 } 140 this.start = e.getPoint(); 141 this.lastClicked = this.closest; 142 this.closest = closest; 143 if (mapillaryData.getMultiSelectedImages() 144 .contains(closest)) 145 return; 146 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 147 && closest != null) 148 mapillaryData.addMultiSelectedImage(closest); 149 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK) 150 && this.closest instanceof MapillaryImage 151 && this.lastClicked instanceof MapillaryImage) { 152 if (this.closest != null 153 && this.lastClicked != null 154 && ((MapillaryImage) this.closest).getSequence() == ((MapillaryImage) this.lastClicked) 155 .getSequence()) { 156 int i = ((MapillaryImage) this.closest).getSequence().getImages() 157 .indexOf(this.closest); 158 int j = ((MapillaryImage) this.lastClicked).getSequence().getImages() 159 .indexOf(this.lastClicked); 160 if (i < j) 161 mapillaryData 162 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 163 ((MapillaryImage) this.closest).getSequence() 164 .getImages() 165 .subList(i, j + 1))); 166 else 167 mapillaryData 168 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 169 ((MapillaryImage) this.closest).getSequence() 170 .getImages() 171 .subList(j, i + 1))); 172 } 173 } else 174 mapillaryData.setSelectedImage(closest); 175 } else if (closestTemp instanceof MapillaryImportedImage) { 176 MapillaryImportedImage closest = (MapillaryImportedImage) closestTemp; 177 this.start = e.getPoint(); 178 this.lastClicked = this.closest; 179 this.closest = closest; 180 if (mapillaryData.getMultiSelectedImages() 181 .contains(closest)) 182 return; 183 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 184 && closest != null) 185 mapillaryData.addMultiSelectedImage(closest); 186 else 187 mapillaryData.setSelectedImage(closest); 188 } 189 } 190 191 private MapillaryAbstractImage getClosest(Point clickPoint) { 192 double snapDistance = 10; 193 double minDistance = Double.MAX_VALUE; 194 MapillaryAbstractImage closest = null; 195 for (MapillaryAbstractImage image : mapillaryData.getImages()) { 196 Point imagePoint = Main.map.mapView.getPoint(image 197 .getLatLon()); 198 imagePoint 199 .setLocation(imagePoint.getX(), imagePoint.getY()); 200 double dist = clickPoint.distanceSq(imagePoint); 201 if (minDistance > dist 202 && clickPoint.distance(imagePoint) < snapDistance) { 203 minDistance = dist; 204 closest = image; 205 } 206 } 207 return closest; 208 } 209 210 @Override 211 public void mouseDragged(MouseEvent e) { 212 if (Main.map.mapView.getActiveLayer() != MapillaryLayer 213 .getInstance()) 214 return; 215 if (MapillaryData.getInstance().getSelectedImage() != null) { 216 if (lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) { 217 LatLon to = Main.map.mapView.getLatLon(e.getX(), 218 e.getY()); 219 LatLon from = Main.map.mapView.getLatLon(start.getX(), 220 start.getY()); 221 for (MapillaryAbstractImage img : MapillaryData 222 .getInstance().getMultiSelectedImages()) { 223 img.move(to.getX() - from.getX(), 224 to.getY() - from.getY()); 225 } 226 Main.map.repaint(); 227 } else if (lastButton == MouseEvent.BUTTON1 228 && e.isShiftDown()) { 229 this.closest.turn(Math.toDegrees(Math.atan2( 230 (e.getX() - start.x), -(e.getY() - start.y))) 231 - closest.getTempCa()); 232 for (MapillaryAbstractImage img : MapillaryData 233 .getInstance().getMultiSelectedImages()) { 234 img.turn(Math.toDegrees(Math.atan2( 235 (e.getX() - start.x), -(e.getY() - start.y))) 236 - closest.getTempCa()); 237 } 238 Main.map.repaint(); 239 } 240 } 241 } 242 243 @Override 244 public void mouseReleased(MouseEvent e) { 245 if (mapillaryData.getSelectedImage() == null) 246 return; 247 if (mapillaryData.getSelectedImage().getTempCa() != mapillaryData 248 .getSelectedImage().getCa()) { 249 double from = mapillaryData.getSelectedImage().getTempCa(); 250 double to = mapillaryData.getSelectedImage().getCa(); 251 record.addCommand(new CommandTurnImage(mapillaryData 252 .getMultiSelectedImages(), to - from)); 253 } else if (mapillaryData.getSelectedImage().getTempLatLon() != mapillaryData 254 .getSelectedImage().getLatLon()) { 255 LatLon from = mapillaryData.getSelectedImage() 256 .getTempLatLon(); 257 LatLon to = mapillaryData.getSelectedImage().getLatLon(); 258 record.addCommand(new CommandMoveImage(mapillaryData 259 .getMultiSelectedImages(), to.getX() - from.getX(), 260 to.getY() - from.getY())); 261 } 262 for (MapillaryAbstractImage img : mapillaryData 263 .getMultiSelectedImages()) { 264 if (img != null) 265 img.stopMoving(); 266 } 267 } 268 }; 269 } 270 108 mouseAdapter = new MapillaryMouseAdapter(); 109 } 110 111 271 112 public synchronized static MapillaryLayer getInstance() { 272 113 if (MapillaryLayer.INSTANCE == null) -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31252 r31255 20 20 import org.openstreetmap.josm.Main; 21 21 import org.openstreetmap.josm.actions.JosmAction; 22 import org.openstreetmap.josm.data.coor.LatLon; 22 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 23 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; … … 63 64 try { 64 65 readJPG(file); 65 } catch (ImageReadException e1) { 66 // TODO Auto-generated catch block 67 e1.printStackTrace(); 68 } catch (IOException e1) { 69 // TODO Auto-generated catch block 70 e1.printStackTrace(); 66 } catch (ImageReadException ex) { 67 Main.error(ex); 68 } catch (IOException ex) { 69 Main.error(ex); 71 70 } 71 } 72 else if (file.getPath().substring(file.getPath().length() - 4) 73 .equals(".png")) { 74 readPNG(file); 72 75 } 73 76 } … … 110 113 new MapillaryImportedImage(latValue, lonValue, caValue, 111 114 file)); 115 } else { 116 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 117 Main.map.mapView.getCenter()); 118 MapillaryData.getInstance().add( 119 new MapillaryImportedImage(pos.lat(), pos.lon(), 0, 120 file)); 112 121 } 113 122 } 123 } 124 125 private void readPNG(File file) { 126 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 127 Main.map.mapView.getCenter()); 128 MapillaryData.getInstance().add( 129 new MapillaryImportedImage(pos.lat(), pos.lon(), 0, 130 file)); 114 131 } 115 132 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31252 r31255 24 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 25 25 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 26 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 26 27 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 27 28 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; … … 131 132 MapillaryCache.Type.FULL_IMAGE); 132 133 imageCache.submit(this, false); 134 } 135 else if (image instanceof MapillaryImportedImage) { 136 this.nextButton.setEnabled(false); 137 this.previousButton.setEnabled(false); 138 MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image; 139 try { 140 mapillaryImageDisplay.setImage(mapillaryImage.getImage()); 141 } catch (IOException e) { 142 Main.error(e); 143 } 133 144 } 134 145 }
Note:
See TracChangeset
for help on using the changeset viewer.