Changeset 31319 in osm for applications/editors
- Timestamp:
- 2015-06-30T11:56:41+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31311 r31319 25 25 super(lat, lon, ca); 26 26 this.file = file; 27 this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy /MM/dd hh:mm:ss");27 this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss"); 28 28 } 29 29 … … 57 57 Calendar cal = Calendar.getInstance(); 58 58 59 SimpleDateFormat formatter = new SimpleDateFormat("yyyy /MM/dd hh:mm:ss");59 SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss"); 60 60 return formatter.format(cal.getTime()); 61 61 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31313 r31319 69 69 public static MapillaryImage RED; 70 70 71 p rivatefinal MapillaryData data = MapillaryData.getInstance();71 public final MapillaryData data = MapillaryData.getInstance(); 72 72 73 73 public ArrayList<Bounds> bounds; … … 105 105 MapView.addEditLayerChangeListener(this, false); 106 106 MapView.addLayerChangeListener(this); 107 Main.map.mapView.getEditLayer().data.addDataSetListener(this); 107 if (Main.map.mapView.getEditLayer() != null) 108 Main.map.mapView.getEditLayer().data.addDataSetListener(this); 108 109 } 109 110 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true); 110 111 if (!MapillaryToggleDialog.getInstance().isShowing()) 111 112 MapillaryToggleDialog.getInstance().getButton().doClick(); 112 113 createHatchTexture(); 113 114 data.dataUpdated(); … … 500 501 @Override 501 502 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 503 if (oldLayer == null && newLayer != null) { 504 newLayer.data.addDataSetListener(this); 505 506 } else if (oldLayer != null && newLayer == null) { 507 oldLayer.data.removeDataSetListener(this); 508 } 502 509 } 503 510 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31313 r31319 33 33 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener { 34 34 35 36 37 38 39 40 41 42 43 44 45 46 47 35 public static final ImageIcon ICON24 = new ImageProvider("icon24.png") 36 .get(); 37 public static final ImageIcon ICON16 = new ImageProvider("icon16.png") 38 .get(); 39 public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png") 40 .get(); 41 public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider( 42 "mapiconselected.png").get(); 43 public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider( 44 "mapiconimported.png").get(); 45 public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png") 46 .get(); 47 public static final int ICON_SIZE = 24; 48 48 49 49 public static CacheAccess<String, BufferedImageCacheEntry> CACHE; 50 50 51 52 53 54 55 51 private final MapillaryDownloadAction downloadAction; 52 private final MapillaryExportAction exportAction; 53 private final MapillaryImportAction importAction; 54 private final MapillaryZoomAction zoomAction; 55 private final MapillaryDownloadViewAction downloadViewAction; 56 56 57 58 59 60 61 57 public static JMenuItem DOWNLOAD_MENU; 58 public static JMenuItem EXPORT_MENU; 59 public static JMenuItem IMPORT_MENU; 60 public static JMenuItem ZOOM_MENU; 61 public static JMenuItem DOWNLOAD_VIEW_MENU; 62 62 63 64 65 66 67 68 69 63 public MapillaryPlugin(PluginInformation info) { 64 super(info); 65 downloadAction = new MapillaryDownloadAction(); 66 exportAction = new MapillaryExportAction(); 67 importAction = new MapillaryImportAction(); 68 zoomAction = new MapillaryZoomAction(); 69 downloadViewAction = new MapillaryDownloadViewAction(); 70 70 71 72 73 74 75 76 77 78 79 80 71 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, 72 downloadAction, false); 73 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, 74 false, 14); 75 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, 76 false, 14); 77 ZOOM_MENU = MainMenu 78 .add(Main.main.menu.viewMenu, zoomAction, false, 15); 79 DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu, 80 downloadViewAction, false, 14); 81 81 82 83 84 85 86 82 EXPORT_MENU.setEnabled(false); 83 DOWNLOAD_MENU.setEnabled(false); 84 IMPORT_MENU.setEnabled(false); 85 ZOOM_MENU.setEnabled(false); 86 DOWNLOAD_VIEW_MENU.setEnabled(false); 87 87 88 89 90 91 92 93 94 95 88 MapView.addEditLayerChangeListener(this); 89 try { 90 CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, 91 this.getPluginDir() + "/cache/"); 92 } catch (IOException e) { 93 Main.error(e); 94 } 95 } 96 96 97 /** 98 * Called when the JOSM map frame is created or destroyed. 99 */ 100 @Override 101 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 102 if (oldFrame == null && newFrame != null) { // map frame added 103 Main.map.addToggleDialog(MapillaryToggleDialog.getInstance(), false); 104 Main.map.addToggleDialog(MapillaryHistoryDialog.getInstance(), 105 false); 106 Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false); 107 } 108 if (oldFrame != null && newFrame == null) { // map frame destroyed 109 MapillaryToggleDialog.destroyInstance(); 110 MapillaryHistoryDialog.destroyInstance(); 111 MapillaryFilterDialog.destroyInstance(); 112 } 113 } 97 /** 98 * Called when the JOSM map frame is created or destroyed. 99 */ 100 @Override 101 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 102 if (oldFrame == null && newFrame != null) { // map frame added 103 Main.map.addToggleDialog(MapillaryToggleDialog.getInstance(), false); 104 Main.map.addToggleDialog(MapillaryHistoryDialog.getInstance(), 105 false); 106 Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false); 107 setMenuEnabled(DOWNLOAD_MENU, true); 108 if (Main.pref.getBoolean("mapillary.download-manually")) 109 setMenuEnabled(DOWNLOAD_VIEW_MENU, true); 110 setMenuEnabled(IMPORT_MENU, true); 111 } 112 if (oldFrame != null && newFrame == null) { // map frame destroyed 113 MapillaryToggleDialog.destroyInstance(); 114 MapillaryHistoryDialog.destroyInstance(); 115 MapillaryFilterDialog.destroyInstance(); 116 setMenuEnabled(DOWNLOAD_MENU, false); 117 setMenuEnabled(DOWNLOAD_VIEW_MENU, false); 118 setMenuEnabled(IMPORT_MENU, false); 119 } 120 } 114 121 115 116 117 118 122 public static void setMenuEnabled(JMenuItem menu, boolean value) { 123 menu.setEnabled(value); 124 menu.getAction().setEnabled(value); 125 } 119 126 120 121 122 123 127 @Override 128 public PreferenceSetting getPreferenceSetting() { 129 return new MapillaryPreferenceSetting(); 130 } 124 131 125 @Override 126 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 127 if (oldLayer == null && newLayer != null) { 128 setMenuEnabled(DOWNLOAD_MENU, true); 129 setMenuEnabled(IMPORT_MENU, true); 130 if (Main.pref.getBoolean("mapillary.download-manually")) 131 setMenuEnabled(DOWNLOAD_VIEW_MENU, true); 132 } else if (oldLayer != null && newLayer == null) { 133 setMenuEnabled(DOWNLOAD_MENU, false); 134 setMenuEnabled(IMPORT_MENU, false); 135 setMenuEnabled(DOWNLOAD_VIEW_MENU, false); 136 } 137 } 132 @Override 133 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 134 if (oldLayer == null && newLayer != null) { 135 } else if (oldLayer != null && newLayer == null) { 136 } 137 } 138 138 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java
r31313 r31319 23 23 public class MapillaryDownloadAction extends JosmAction { 24 24 25 26 27 28 29 30 31 32 25 public MapillaryDownloadAction() { 26 super(tr("Mapillary"), new ImageProvider("icon24.png"), 27 tr("Create Mapillary layer"), Shortcut.registerShortcut( 28 "Mapillary", tr("Start Mapillary layer"), 29 KeyEvent.VK_COMMA, Shortcut.SHIFT), false, 30 "mapillaryDownload", false); 31 this.setEnabled(false); 32 } 33 33 34 @Override 35 public void actionPerformed(ActionEvent arg0) { 36 if (MapillaryLayer.INSTANCE == null) 37 MapillaryLayer.getInstance().download(); 38 else { 39 if (Main.map.mapView.getActiveLayer() != MapillaryLayer 40 .getInstance()) 41 Main.map.mapView.setActiveLayer(MapillaryLayer.getInstance()); 42 else 43 Main.map.mapView 44 .setActiveLayer(Main.map.mapView.getEditLayer()); 45 } 46 } 34 @Override 35 public void actionPerformed(ActionEvent arg0) { 36 if (MapillaryLayer.INSTANCE == null) { 37 if (Main.map.mapView.getEditLayer() != null) 38 MapillaryLayer.getInstance().download(); 39 } else { 40 if (Main.map.mapView.getActiveLayer() != MapillaryLayer 41 .getInstance()) 42 Main.map.mapView.setActiveLayer(MapillaryLayer.getInstance()); 43 else 44 Main.map.mapView 45 .setActiveLayer(Main.map.mapView.getEditLayer()); 46 } 47 } 47 48 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31317 r31319 120 120 || lon_ref == null) { 121 121 readNoTags(file); 122 return; 122 123 } 123 124 double latValue = 0; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31306 r31319 4 4 import org.openstreetmap.josm.data.Bounds; 5 5 import org.openstreetmap.josm.data.coor.LatLon; 6 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 6 7 7 8 import java.util.concurrent.ConcurrentHashMap; … … 52 53 Main.info("GET " + url2 + " (Mapillary plugin)"); 53 54 Main.worker.submit(new MapillarySquareDownloadManagerThread(url1, 54 url2, url3 ));55 url2, url3, MapillaryLayer.getInstance())); 55 56 } catch (Exception e) { 56 57 Main.error(e); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java
r31282 r31319 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;18 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 19 19 20 20 /** … … 25 25 */ 26 26 public class MapillaryImageInfoDownloaderThread implements Runnable { 27 private final String url; 28 private final ExecutorService ex; 27 private final String url; 28 private final ExecutorService ex; 29 private final MapillaryLayer layer; 29 30 30 public MapillaryImageInfoDownloaderThread(ExecutorService ex, String url) { 31 this.ex = ex; 32 this.url = url; 33 } 31 public MapillaryImageInfoDownloaderThread(ExecutorService ex, String url, 32 MapillaryLayer layer) { 33 this.ex = ex; 34 this.url = url; 35 this.layer = layer; 36 } 34 37 35 36 37 38 39 40 41 42 43 44 45 46 47 for (MapillaryAbstractImage image : MapillaryData.getInstance() 48 .getImages()) {49 if (image instanceof MapillaryImage) { 50 if (((MapillaryImage) image).getKey().equals(key)) {51 52 53 54 55 56 57 58 59 60 61 62 63 64 38 public void run() { 39 try { 40 BufferedReader br = new BufferedReader(new InputStreamReader( 41 new URL(url).openStream())); 42 JsonObject jsonobj = Json.createReader(br).readObject(); 43 if (!jsonobj.getBoolean("more")) 44 ex.shutdown(); 45 JsonArray jsonarr = jsonobj.getJsonArray("ims"); 46 JsonObject data; 47 for (int i = 0; i < jsonarr.size(); i++) { 48 data = jsonarr.getJsonObject(i); 49 String key = data.getString("key"); 50 for (MapillaryAbstractImage image : layer.data.getImages()) { 51 if (image instanceof MapillaryImage) { 52 if (((MapillaryImage) image).getKey().equals(key) 53 && ((MapillaryImage) image).getUser() == null) { 54 ((MapillaryImage) image).setUser(data 55 .getString("user")); 56 ((MapillaryImage) image).setCapturedAt(data 57 .getJsonNumber("captured_at").longValue()); 58 } 59 } 60 } 61 } 62 } catch (MalformedURLException e) { 63 Main.error(e); 64 } catch (IOException e) { 65 Main.error(e); 66 } 67 } 65 68 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31298 r31319 17 17 import org.openstreetmap.josm.data.Bounds; 18 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;20 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 21 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; … … 32 31 public class MapillarySequenceDownloadThread implements Runnable { 33 32 34 private String url; 35 private ExecutorService ex; 36 private List<Bounds> bounds; 33 private final String url; 34 private final ExecutorService ex; 35 private final List<Bounds> bounds; 36 private final MapillaryLayer layer; 37 private final MapillarySquareDownloadManagerThread manager; 37 38 38 public MapillarySequenceDownloadThread(ExecutorService ex, String url) { 39 this.url = url; 40 this.ex = ex; 41 this.bounds = MapillaryLayer.getInstance().bounds; 42 } 39 public MapillarySequenceDownloadThread(ExecutorService ex, String url, 40 MapillaryLayer layer, MapillarySquareDownloadManagerThread manager) { 41 this.url = url; 42 this.ex = ex; 43 this.bounds = layer.bounds; 44 this.layer = layer; 45 this.manager = manager; 46 } 43 47 44 45 46 47 48 49 48 public void run() { 49 try { 50 BufferedReader br; 51 br = new BufferedReader(new InputStreamReader( 52 new URL(url).openStream())); 53 JsonObject jsonall = Json.createReader(br).readObject(); 50 54 51 if (!jsonall.getBoolean("more") && !ex.isShutdown()) 52 ex.shutdown(); 53 JsonArray jsonseq = jsonall.getJsonArray("ss"); 54 // At the moment there is a bug with some sequences at Mapillay API, 55 // so if they are wrong he use this variable to skip them. 56 boolean isSequenceWrong = false; 57 for (int i = 0; i < jsonseq.size(); i++) { 58 JsonObject jsonobj = jsonseq.getJsonObject(i); 59 JsonArray cas = jsonobj.getJsonArray("cas"); 60 JsonArray coords = jsonobj.getJsonArray("coords"); 61 JsonArray keys = jsonobj.getJsonArray("keys"); 62 ArrayList<MapillaryImage> images = new ArrayList<>(); 63 for (int j = 0; j < cas.size(); j++) { 64 try { 65 images.add(new MapillaryImage(keys.getString(j), 66 coords.getJsonArray(j).getJsonNumber(1) 67 .doubleValue(), coords.getJsonArray(j) 68 .getJsonNumber(0).doubleValue(), cas 69 .getJsonNumber(j).doubleValue())); 70 } catch (IndexOutOfBoundsException e) { 71 Main.warn("Mapillary bug at " + url); 72 isSequenceWrong = true; 73 } 74 } 75 if (isSequenceWrong) 76 break; 77 MapillarySequence sequence = new MapillarySequence( 78 jsonobj.getString("key"), jsonobj.getJsonNumber( 79 "captured_at").longValue()); 55 if (!jsonall.getBoolean("more") && !ex.isShutdown()) 56 ex.shutdown(); 57 JsonArray jsonseq = jsonall.getJsonArray("ss"); 58 boolean isSequenceWrong = false; 59 for (int i = 0; i < jsonseq.size(); i++) { 60 JsonObject jsonobj = jsonseq.getJsonObject(i); 61 JsonArray cas = jsonobj.getJsonArray("cas"); 62 JsonArray coords = jsonobj.getJsonArray("coords"); 63 JsonArray keys = jsonobj.getJsonArray("keys"); 64 ArrayList<MapillaryImage> images = new ArrayList<>(); 65 for (int j = 0; j < cas.size(); j++) { 66 try { 67 images.add(new MapillaryImage(keys.getString(j), 68 coords.getJsonArray(j).getJsonNumber(1) 69 .doubleValue(), coords.getJsonArray(j) 70 .getJsonNumber(0).doubleValue(), cas 71 .getJsonNumber(j).doubleValue())); 72 } catch (IndexOutOfBoundsException e) { 73 Main.warn("Mapillary bug at " + url); 74 isSequenceWrong = true; 75 } 76 } 77 if (isSequenceWrong) 78 break; 79 MapillarySequence sequence = new MapillarySequence( 80 jsonobj.getString("key"), jsonobj.getJsonNumber( 81 "captured_at").longValue()); 80 82 81 83 List<MapillaryImage> finalImages = new ArrayList<>(images); 84 // Here it gets only those images which are in the downloaded 85 // area. 86 for (MapillaryAbstractImage img : images) { 87 if (!isInside(img)) 88 finalImages.remove(img); 89 } 82 90 83 List<MapillaryImage> finalImages = new ArrayList<>(images);84 // Here it gets only those images which are in the downloaded 85 // area. 86 for (MapillaryAbstractImage img : images) { 87 if (!isInside(img))88 finalImages.remove(img);89 } 90 91 for (MapillaryImage img : finalImages) { 92 MapillaryData.getInstance().getImages().remove(img); 93 img.setSequence(sequence); 94 } 95 MapillaryData.getInstance().addWithoutUpdate(96 97 98 99 100 101 102 103 91 boolean imagesAdded = false; 92 for (MapillaryImage img : finalImages) { 93 if (layer.data.getImages().contains(img)) 94 ((MapillaryImage) layer.data.getImages().get( 95 layer.data.getImages().indexOf(img))) 96 .setSequence(sequence); 97 else { 98 img.setSequence(sequence); 99 imagesAdded = true; 100 } 101 } 102 manager.imagesAdded = imagesAdded; 103 layer.data.addWithoutUpdate( 104 new ArrayList<MapillaryAbstractImage>(finalImages)); 105 sequence.add(finalImages); 106 } 107 } catch (IOException e) { 108 Main.error("Error reading the url " + url 109 + " might be a Mapillary problem."); 110 } 111 } 104 112 105 106 107 108 109 110 111 113 private boolean isInside(MapillaryAbstractImage image) { 114 for (int i = 0; i < bounds.size(); i++) { 115 if (bounds.get(i).contains(image.getLatLon())) 116 return true; 117 } 118 return false; 119 } 112 120 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySignDownloaderThread.java
r31278 r31319 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;17 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 18 18 19 19 public class MapillarySignDownloaderThread implements Runnable { 20 20 21 private final String url; 22 private final ExecutorService ex; 21 private final String url; 22 private final ExecutorService ex; 23 private final MapillaryLayer layer; 23 24 24 public MapillarySignDownloaderThread(ExecutorService ex, String url) { 25 this.ex = ex; 26 this.url = url; 27 } 25 public MapillarySignDownloaderThread(ExecutorService ex, String url, 26 MapillaryLayer layer) { 27 this.ex = ex; 28 this.url = url; 29 this.layer = layer; 30 } 28 31 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 for (MapillaryAbstractImage image : MapillaryData53 .getInstance().getImages())54 55 56 57 58 59 60 61 32 @Override 33 public void run() { 34 BufferedReader br; 35 try { 36 br = new BufferedReader(new InputStreamReader( 37 new URL(url).openStream())); 38 JsonObject jsonobj = Json.createReader(br).readObject(); 39 if (!jsonobj.getBoolean("more")) { 40 ex.shutdown(); 41 } 42 JsonArray jsonarr = jsonobj.getJsonArray("ims"); 43 for (int i = 0; i < jsonarr.size(); i++) { 44 JsonArray rects = jsonarr.getJsonObject(i) 45 .getJsonArray("rects"); 46 JsonArray rectversions = jsonarr.getJsonObject(i).getJsonArray( 47 "rectversions"); 48 String key = jsonarr.getJsonObject(i).getString("key"); 49 if (rectversions != null) { 50 for (int j = 0; j < rectversions.size(); j++) { 51 rects = rectversions.getJsonObject(j).getJsonArray( 52 "rects"); 53 for (int k = 0; k < rects.size(); k++) { 54 JsonObject data = rects.getJsonObject(k); 55 for (MapillaryAbstractImage image : layer.data 56 .getImages()) 57 if (image instanceof MapillaryImage 58 && ((MapillaryImage) image).getKey() 59 .equals(key)) 60 ((MapillaryImage) image).addSign(data 61 .getString("type")); 62 } 63 } 64 } 62 65 63 // Just one sign on the picture 64 else if (rects != null) { 65 for (int j = 0; j < rects.size(); j++) { 66 JsonObject data = rects.getJsonObject(j); 67 for (MapillaryAbstractImage image : MapillaryData 68 .getInstance().getImages()) 69 if (image instanceof MapillaryImage 70 && ((MapillaryImage) image).getKey() 71 .equals(key)) 72 ((MapillaryImage) image).addSign(data 73 .getString("type")); 74 } 75 } 76 } 77 } catch (MalformedURLException e) { 78 Main.error(e); 79 } catch (IOException e) { 80 Main.error(e); 81 } 82 } 66 // Just one sign on the picture 67 else if (rects != null) { 68 for (int j = 0; j < rects.size(); j++) { 69 JsonObject data = rects.getJsonObject(j); 70 for (MapillaryAbstractImage image : layer.data.getImages()) 71 if (image instanceof MapillaryImage 72 && ((MapillaryImage) image).getKey() 73 .equals(key)) 74 ((MapillaryImage) image).addSign(data 75 .getString("type")); 76 } 77 } 78 } 79 } catch (MalformedURLException e) { 80 Main.error(e); 81 } catch (IOException e) { 82 Main.error(e); 83 } 84 } 83 85 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31313 r31319 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.plugins.mapillary.Mapillary Data;10 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 11 11 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; 12 12 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog; … … 23 23 public class MapillarySquareDownloadManagerThread implements Runnable { 24 24 25 private final String urlImages; 26 private final String urlSequences; 27 private final String urlSigns; 25 private final String urlImages; 26 private final String urlSequences; 27 private final String urlSigns; 28 private final MapillaryLayer layer; 29 public boolean imagesAdded = false; 28 30 29 public MapillarySquareDownloadManagerThread(String urlImages, 30 String urlSequences, String urlSigns) { 31 this.urlImages = urlImages; 32 this.urlSequences = urlSequences; 33 this.urlSigns = urlSigns; 34 } 31 public MapillarySquareDownloadManagerThread(String urlImages, 32 String urlSequences, String urlSigns, MapillaryLayer layer) { 33 this.urlImages = urlImages; 34 this.urlSequences = urlSequences; 35 this.urlSigns = urlSigns; 36 this.layer = layer; 37 } 35 38 36 public void run() { 37 Main.map.statusLine.setHelpText("Downloading images from Mapillary"); 38 try { 39 downloadSequences(); 40 Main.map.statusLine.setHelpText("Downloading image's information"); 41 completeImages(); 42 Main.map.statusLine.setHelpText("Downloading signs"); 43 downloadSigns(); 44 } catch (InterruptedException e) { 45 Main.error(e); 46 } 47 if (MapillaryData.getInstance().getImages().size() > 0) 48 Main.map.statusLine.setHelpText(tr("Total images: ") 49 + MapillaryData.getInstance().getImages().size()); 50 else 51 Main.map.statusLine.setHelpText(tr("No images found")); 52 MapillaryData.getInstance().dataUpdated(); 53 MapillaryFilterDialog.getInstance().refresh(); 54 MapillaryToggleDialog.getInstance().updateImage(); 55 } 39 public void run() { 40 Main.map.statusLine.setHelpText("Downloading images from Mapillary"); 41 try { 42 downloadSequences(); 43 if (imagesAdded) { 44 Main.map.statusLine 45 .setHelpText("Downloading image's information"); 46 completeImages(); 47 Main.map.statusLine.setHelpText("Downloading signs"); 48 downloadSigns(); 49 } 50 } catch (InterruptedException e) { 51 Main.error(e); 52 } 53 if (layer.data.getImages().size() > 0) 54 Main.map.statusLine.setHelpText(tr("Total images: ") 55 + layer.data.getImages().size()); 56 else 57 Main.map.statusLine.setHelpText(tr("No images found")); 58 layer.data.dataUpdated(); 59 MapillaryFilterDialog.getInstance().refresh(); 60 MapillaryToggleDialog.getInstance().updateImage(); 61 } 56 62 57 58 59 60 61 62 63 + "&page=" + page + "&limit=1"));64 65 66 67 68 69 MapillaryData.getInstance().dataUpdated();70 63 private void downloadSequences() throws InterruptedException { 64 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, 65 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 66 int page = 0; 67 while (!ex.isShutdown()) { 68 ex.execute(new MapillarySequenceDownloadThread(ex, urlSequences 69 + "&page=" + page + "&limit=1", layer, this)); 70 while (ex.getQueue().remainingCapacity() == 0) 71 Thread.sleep(100); 72 page++; 73 } 74 ex.awaitTermination(15, TimeUnit.SECONDS); 75 layer.data.dataUpdated(); 76 } 71 77 72 73 74 75 76 77 78 + "&page=" + page + "&limit=20"));79 80 81 82 83 84 78 private void completeImages() throws InterruptedException { 79 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, 80 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 81 int page = 0; 82 while (!ex.isShutdown()) { 83 ex.execute(new MapillaryImageInfoDownloaderThread(ex, urlImages 84 + "&page=" + page + "&limit=20", layer)); 85 while (ex.getQueue().remainingCapacity() == 0) 86 Thread.sleep(100); 87 page++; 88 } 89 ex.awaitTermination(15, TimeUnit.SECONDS); 90 } 85 91 86 87 88 89 90 91 92 + "&page=" + page + "&limit=20"));93 94 95 96 97 98 92 private void downloadSigns() throws InterruptedException { 93 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, 94 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 95 int page = 0; 96 while (!ex.isShutdown()) { 97 ex.execute(new MapillarySignDownloaderThread(ex, urlSigns 98 + "&page=" + page + "&limit=20", layer)); 99 while (ex.getQueue().remainingCapacity() == 0) 100 Thread.sleep(100); 101 page++; 102 } 103 ex.awaitTermination(15, TimeUnit.SECONDS); 104 } 99 105 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java
r31315 r31319 144 144 } 145 145 146 public void refresh() {146 public synchronized void refresh() { 147 147 boolean imported = this.imported.isSelected(); 148 148 boolean downloaded = this.downloaded.isSelected(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31313 r31319 9 9 import java.awt.Color; 10 10 import java.awt.Component; 11 import java.awt.Event;12 11 import java.awt.FlowLayout; 13 12 import java.awt.GridLayout;
Note:
See TracChangeset
for help on using the changeset viewer.