Changeset 31322 in osm for applications/editors
- Timestamp:
- 2015-07-01T11:52:00+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31284 r31322 12 12 */ 13 13 public class MapillaryImage extends MapillaryAbstractImage { 14 15 16 17 14 /** Unique identifier of the object */ 15 private final String key; 16 /** Sequence of pictures containing this object */ 17 private MapillarySequence sequence; 18 18 19 20 21 22 23 24 19 /** Epoch time when the image was taken. */ 20 /** The user that made the image */ 21 private String user; 22 /** Set of traffic signs in the image */ 23 private List<String> signs; 24 private String location; 25 25 26 27 28 26 public String getLocation() { 27 return location; 28 } 29 29 30 31 32 30 public void setLocation(String location) { 31 this.location = location; 32 } 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 34 /** 35 * Main contructor of the class MapillaryImage 36 * 37 * @param key 38 * The unique identifier of the image. 39 * @param lat 40 * The latitude where it is positioned. 41 * @param lon 42 * The longitude where it is positioned. 43 * @param ca 44 * The direction of the images in degrees, meaning 0 north. 45 */ 46 public MapillaryImage(String key, double lat, double lon, double ca) { 47 super(lat, lon, ca); 48 this.key = key; 49 this.signs = new ArrayList<>(); 50 } 51 51 52 53 54 55 56 57 58 59 52 /** 53 * Returns the unique identifier of the object. 54 * 55 * @return A String containing the unique identifier of the object. 56 */ 57 public String getKey() { 58 return this.key; 59 } 60 60 61 62 63 64 65 66 67 68 61 /** 62 * Adds a new sign to the set of signs. 63 * 64 * @param sign 65 */ 66 public void addSign(String sign) { 67 signs.add(sign); 68 } 69 69 70 71 72 70 public List<String> getSigns() { 71 return signs; 72 } 73 73 74 75 76 74 public void setUser(String user) { 75 this.user = user; 76 } 77 77 78 79 80 78 public String getUser() { 79 return user; 80 } 81 81 82 83 84 85 86 87 88 89 90 82 /** 83 * Sets the MapillarySequence object which contains the MapillaryImage. 84 * 85 * @param sequence 86 * The MapillarySequence that contains the MapillaryImage. 87 */ 88 public void setSequence(MapillarySequence sequence) { 89 this.sequence = sequence; 90 } 91 91 92 93 94 95 96 97 98 99 92 /** 93 * Returns the sequence which contains this image. 94 * 95 * @return The MapillarySequence object that contains this MapillaryImage. 96 */ 97 public MapillarySequence getSequence() { 98 return this.sequence; 99 } 100 100 101 102 103 104 101 public String toString() { 102 return "Image[key=" + this.key + ";lat=" + this.latLon.lat() + ";lon=" 103 + this.latLon.lon() + ";ca=" + this.ca + "]"; 104 } 105 105 106 107 108 109 110 111 112 113 114 115 116 106 /** 107 * If the MapillaryImage belongs to a MapillarySequence, returns the next 108 * MapillarySequence in it. 109 * 110 * @return The following MapillaryImage, or null if there is none. 111 */ 112 public MapillaryImage next() { 113 if (this.getSequence() == null) 114 return null; 115 return this.getSequence().next(this); 116 } 117 117 118 119 120 121 122 123 124 125 126 127 128 118 /** 119 * If the MapillaryImage belongs to a MapillarySequence, returns the 120 * previous MapillarySequence in it. 121 * 122 * @return The previous MapillaryImage, or null if there is none. 123 */ 124 public MapillaryImage previous() { 125 if (this.getSequence() == null) 126 return null; 127 return this.getSequence().previous(this); 128 } 129 129 130 131 132 133 134 135 130 @Override 131 public boolean equals(Object object) { 132 if (object instanceof MapillaryImage) 133 return this.key.equals(((MapillaryImage) object).getKey()); 134 return false; 135 } 136 136 137 138 139 140 137 @Override 138 public int hashCode() { 139 return this.key.hashCode(); 140 } 141 141 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31319 r31322 255 255 */ 256 256 @Override 257 public void paint(Graphics2D g, MapView mv, Bounds box) { 258 synchronized (this) { 259 if (Main.map.mapView.getActiveLayer() == this) { 260 Rectangle b = mv.getBounds(); 261 // on some platforms viewport bounds seem to be offset from the 262 // left, 263 // over-grow it just to be sure 264 b.grow(100, 100); 265 Area a = new Area(b); 266 // now successively subtract downloaded areas 267 for (Bounds bounds : this.bounds) { 268 Point p1 = mv.getPoint(bounds.getMin()); 269 Point p2 = mv.getPoint(bounds.getMax()); 270 Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min( 271 p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y 272 - p1.y)); 273 a.subtract(new Area(r)); 257 public synchronized void paint(Graphics2D g, MapView mv, Bounds box) { 258 if (Main.map.mapView.getActiveLayer() == this) { 259 Rectangle b = mv.getBounds(); 260 // on some platforms viewport bounds seem to be offset from the 261 // left, 262 // over-grow it just to be sure 263 b.grow(100, 100); 264 Area a = new Area(b); 265 // now successively subtract downloaded areas 266 for (Bounds bounds : this.bounds) { 267 Point p1 = mv.getPoint(bounds.getMin()); 268 Point p2 = mv.getPoint(bounds.getMax()); 269 Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min( 270 p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y 271 - p1.y)); 272 a.subtract(new Area(r)); 273 } 274 // paint remainder 275 g.setPaint(hatched); 276 g.fill(a); 277 } 278 279 // Draw colored lines 280 MapillaryLayer.BLUE = null; 281 MapillaryLayer.RED = null; 282 MapillaryToggleDialog.getInstance().blueButton.setEnabled(false); 283 MapillaryToggleDialog.getInstance().redButton.setEnabled(false); 284 285 // Sets blue and red lines and enables/disables the buttons 286 if (data.getSelectedImage() != null) { 287 MapillaryImage[] closestImages = getClosestImagesFromDifferentSequences(); 288 Point selected = mv.getPoint(data.getSelectedImage().getLatLon()); 289 if (closestImages[0] != null) { 290 MapillaryLayer.BLUE = closestImages[0]; 291 g.setColor(Color.BLUE); 292 g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x, 293 mv.getPoint(closestImages[0].getLatLon()).y, 294 selected.x, selected.y); 295 MapillaryToggleDialog.getInstance().blueButton.setEnabled(true); 296 } 297 if (closestImages[1] != null) { 298 MapillaryLayer.RED = closestImages[1]; 299 g.setColor(Color.RED); 300 g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x, 301 mv.getPoint(closestImages[1].getLatLon()).y, 302 selected.x, selected.y); 303 MapillaryToggleDialog.getInstance().redButton.setEnabled(true); 304 } 305 } 306 g.setColor(Color.WHITE); 307 for (MapillaryAbstractImage imageAbs : data.getImages()) { 308 if (!imageAbs.isVisible()) 309 continue; 310 Point p = mv.getPoint(imageAbs.getLatLon()); 311 if (imageAbs instanceof MapillaryImage) { 312 MapillaryImage image = (MapillaryImage) imageAbs; 313 Point nextp = null; 314 // Draw sequence line 315 if (image.getSequence() != null) { 316 MapillaryImage tempImage = image; 317 while (tempImage.next() != null) { 318 tempImage = tempImage.next(); 319 if (tempImage.isVisible()) { 320 nextp = mv.getPoint(tempImage.getLatLon()); 321 break; 322 } 323 } 324 if (nextp != null) 325 g.drawLine(p.x, p.y, nextp.x, nextp.y); 274 326 } 275 // paint remainder 276 g.setPaint(hatched); 277 g.fill(a); 278 } 279 280 // Draw colored lines 281 MapillaryLayer.BLUE = null; 282 MapillaryLayer.RED = null; 283 MapillaryToggleDialog.getInstance().blueButton.setEnabled(false); 284 MapillaryToggleDialog.getInstance().redButton.setEnabled(false); 285 286 // Sets blue and red lines and enables/disables the buttons 287 if (data.getSelectedImage() != null) { 288 MapillaryImage[] closestImages = getClosestImagesFromDifferentSequences(); 289 Point selected = mv.getPoint(data.getSelectedImage() 290 .getLatLon()); 291 if (closestImages[0] != null) { 292 MapillaryLayer.BLUE = closestImages[0]; 293 g.setColor(Color.BLUE); 294 g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x, 295 mv.getPoint(closestImages[0].getLatLon()).y, 296 selected.x, selected.y); 297 MapillaryToggleDialog.getInstance().blueButton 298 .setEnabled(true); 327 328 ImageIcon icon; 329 if (!data.getMultiSelectedImages().contains(image)) 330 icon = MapillaryPlugin.MAP_ICON; 331 else 332 icon = MapillaryPlugin.MAP_ICON_SELECTED; 333 draw(g, image, icon, p); 334 if (!image.getSigns().isEmpty()) { 335 g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(), 336 p.x + icon.getIconWidth() / 2, 337 p.y - icon.getIconHeight() / 2, Main.map.mapView); 299 338 } 300 if (closestImages[1] != null) { 301 MapillaryLayer.RED = closestImages[1]; 302 g.setColor(Color.RED); 303 g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x, 304 mv.getPoint(closestImages[1].getLatLon()).y, 305 selected.x, selected.y); 306 MapillaryToggleDialog.getInstance().redButton 307 .setEnabled(true); 308 } 309 } 310 g.setColor(Color.WHITE); 311 for (MapillaryAbstractImage imageAbs : data.getImages()) { 312 if (!imageAbs.isVisible()) 313 continue; 314 Point p = mv.getPoint(imageAbs.getLatLon()); 315 if (imageAbs instanceof MapillaryImage) { 316 MapillaryImage image = (MapillaryImage) imageAbs; 317 Point nextp = null; 318 // Draw sequence line 319 if (image.getSequence() != null) { 320 MapillaryImage tempImage = image; 321 while (tempImage.next() != null) { 322 tempImage = tempImage.next(); 323 if (tempImage.isVisible()) { 324 nextp = mv.getPoint(tempImage.getLatLon()); 325 break; 326 } 327 } 328 if (nextp != null) 329 g.drawLine(p.x, p.y, nextp.x, nextp.y); 330 } 331 332 ImageIcon icon; 333 if (!data.getMultiSelectedImages().contains(image)) 334 icon = MapillaryPlugin.MAP_ICON; 335 else 336 icon = MapillaryPlugin.MAP_ICON_SELECTED; 337 draw(g, image, icon, p); 338 if (!image.getSigns().isEmpty()) { 339 g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(), p.x 340 + icon.getIconWidth() / 2, 341 p.y - icon.getIconHeight() / 2, 342 Main.map.mapView); 343 } 344 } else if (imageAbs instanceof MapillaryImportedImage) { 345 MapillaryImportedImage image = (MapillaryImportedImage) imageAbs; 346 ImageIcon icon; 347 if (!data.getMultiSelectedImages().contains(image)) 348 icon = MapillaryPlugin.MAP_ICON_IMPORTED; 349 else 350 icon = MapillaryPlugin.MAP_ICON_SELECTED; 351 draw(g, image, icon, p); 352 } 339 } else if (imageAbs instanceof MapillaryImportedImage) { 340 MapillaryImportedImage image = (MapillaryImportedImage) imageAbs; 341 ImageIcon icon; 342 if (!data.getMultiSelectedImages().contains(image)) 343 icon = MapillaryPlugin.MAP_ICON_IMPORTED; 344 else 345 icon = MapillaryPlugin.MAP_ICON_SELECTED; 346 draw(g, image, icon, p); 353 347 } 354 348 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31319 r31322 7 7 8 8 import java.util.concurrent.ConcurrentHashMap; 9 import java.util.concurrent.Executor; 10 import java.util.concurrent.Executors; 9 11 10 12 /** … … 16 18 public class MapillaryDownloader { 17 19 18 public final static String BASE_URL = "https://a.mapillary.com/v2/"; 19 public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm"; 20 public final static String BASE_URL = "https://a.mapillary.com/v2/"; 21 public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm"; 22 public final static Executor EXECUTOR = Executors.newSingleThreadExecutor(); 20 23 21 22 24 private String[] parameters = { "lat", "lon", "distance", "limit", 25 "min_lat", "min_lon", "max_lat", "max_lon" }; 23 26 24 25 27 public MapillaryDownloader() { 28 } 26 29 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 30 /** 31 * Gets all the images in a square. It downloads all the images of all the 32 * sequences that pass through the given rectangle. 33 * 34 * @param minLatLon 35 * The minimum latitude and longitude of the rectangle. 36 * @param maxLatLon 37 * The maximum latitude and longitude of the rectangle 38 */ 39 public void getImages(LatLon minLatLon, LatLon maxLatLon) { 40 String url1 = BASE_URL; 41 String url2 = BASE_URL; 42 String url3 = BASE_URL; 43 url1 += "search/im/"; 44 url2 += "search/s/"; 45 url3 += "search/im/or"; 46 ConcurrentHashMap<String, Double> hash = new ConcurrentHashMap<>(); 47 hash.put("min_lat", minLatLon.lat()); 48 hash.put("min_lon", minLatLon.lon()); 49 hash.put("max_lat", maxLatLon.lat()); 50 hash.put("max_lon", maxLatLon.lon()); 51 url1 += buildParameters(hash); 52 url2 += buildParameters(hash); 53 url3 += buildParameters(hash); 51 54 52 53 54 Main.worker.submit(new MapillarySquareDownloadManagerThread(url1,55 url2,url3, MapillaryLayer.getInstance()));56 57 58 59 55 try { 56 Main.info("GET " + url2 + " (Mapillary plugin)"); 57 EXECUTOR.execute(new MapillarySquareDownloadManagerThread(url1, url2, 58 url3, MapillaryLayer.getInstance())); 59 } catch (Exception e) { 60 Main.error(e); 61 } 62 } 60 63 61 62 63 64 public void getImages(Bounds bounds) { 65 getImages(bounds.getMin(), bounds.getMax()); 66 } 64 67 65 66 67 68 69 70 71 68 private String buildParameters(ConcurrentHashMap<String, Double> hash) { 69 String ret = "?client_id=" + CLIENT_ID; 70 for (int i = 0; i < parameters.length; i++) 71 if (hash.get(parameters[i]) != null) 72 ret += "&" + parameters[i] + "=" + hash.get(parameters[i]); 73 return ret; 74 } 72 75 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31319 r31322 91 91 boolean imagesAdded = false; 92 92 for (MapillaryImage img : finalImages) { 93 if (layer.data.getImages().contains(img)) 93 if (layer.data.getImages().contains(img)) { 94 94 ((MapillaryImage) layer.data.getImages().get( 95 95 layer.data.getImages().indexOf(img))) 96 96 .setSequence(sequence); 97 finalImages.set( 98 finalImages.indexOf(img), 99 (MapillaryImage) layer.data.getImages().get( 100 layer.data.getImages().indexOf(img))); 101 } 102 97 103 else { 98 104 img.setSequence(sequence); … … 101 107 } 102 108 manager.imagesAdded = imagesAdded; 103 layer.data.addWithoutUpdate( 104 new ArrayList<MapillaryAbstractImage>(finalImages)); 109 layer.data 110 .addWithoutUpdate(new ArrayList<MapillaryAbstractImage>( 111 finalImages)); 105 112 sequence.add(finalImages); 106 113 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31319 r31322 14 14 /** 15 15 * This Class is needed to create an indeterminate amount of downloads, because 16 * the Mapillary API has a param page which is needed when the amount of16 * the Mapillary API has a paramameter called page which is needed when the amount of 17 17 * requested images is quite big. 18 18 * … … 28 28 private final MapillaryLayer layer; 29 29 public boolean imagesAdded = false; 30 30 31 31 public MapillarySquareDownloadManagerThread(String urlImages, 32 32 String urlSequences, String urlSigns, MapillaryLayer layer) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31319 r31322 70 70 Shortcut.registerShortcut(tr("Mapillary dialog"), 71 71 tr("Open Mapillary main dialog"), KeyEvent.VK_M, 72 Shortcut.NONE), 200 );72 Shortcut.NONE), 200, false, MapillaryPreferenceSetting.class); 73 73 MapillaryData.getInstance().addListener(this); 74 74 addShortcuts(); … … 146 146 title += " -- " + mapillaryImage.getDate(); 147 147 setTitle(title); 148 // Enables/disables next/previous buttons 148 149 this.nextButton.setEnabled(false); 149 150 this.previousButton.setEnabled(false); 150 // Enables/disables next/previous buttons151 151 if (((MapillaryImage) image).getSequence() != null) { 152 152 MapillaryImage tempImage = (MapillaryImage) image;
Note:
See TracChangeset
for help on using the changeset viewer.