Ignore:
Timestamp:
2015-08-06T16:55:05+02:00 (10 years ago)
Author:
nokutu
Message:

Moved bounds ArrayList from MapillaryLayer to MapillaryData.

Location:
applications/editors/josm/plugins/mapillary
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31457 r31459  
    22
    33import org.openstreetmap.josm.Main;
     4import org.openstreetmap.josm.data.Bounds;
    45import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
    56import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     
    2627
    2728  private CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
     29
     30  /** The bounds of the areas for which the pictures have been downloaded. */
     31  public CopyOnWriteArrayList<Bounds> bounds;
    2832
    2933  /**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31457 r31459  
    7474  public boolean TEMP_SEMIAUTOMATIC = false;
    7575
    76   /** Unique instance of the class */
     76  /** Unique instance of the class. */
    7777  public static MapillaryLayer INSTANCE;
    78   /** The image pointed by the blue line */
     78  /** The image pointed by the blue line. */
    7979  public static MapillaryImage BLUE;
    80   /** The image pointed by the red line */
     80  /** The image pointed by the red line. */
    8181  public static MapillaryImage RED;
    8282
    83   /** {@link MapillaryData} object that stores the database */
     83  /** {@link MapillaryData} object that stores the database. */
    8484  private final MapillaryData data;
    8585
    86   /** The bounds of the areas for which the pictures have been downloaded */
    87   public CopyOnWriteArrayList<Bounds> bounds;
    88 
    89   /** Mode of the layer */
     86  /** Mode of the layer. */
    9087  public AbstractMode mode;
    9188
     
    10097    super(tr("Mapillary Images"));
    10198    this.data = new MapillaryData();
    102     this.bounds = new CopyOnWriteArrayList<>();
     99    this.data.bounds = new CopyOnWriteArrayList<>();
    103100    init();
    104101  }
     
    243240   * Replies background color for downloaded areas.
    244241   *
    245    * @return background color for downloaded areas. Black by default
     242   * @return background color for downloaded areas. Black by default.
    246243   */
    247244  private static Color getBackgroundColor() {
     
    252249   * Replies background color for non-downloaded areas.
    253250   *
    254    * @return background color for non-downloaded areas. Yellow by default
     251   * @return background color for non-downloaded areas. Yellow by default.
    255252   */
    256253  private static Color getOutsideColor() {
     
    259256
    260257  /**
    261    * Initialize the hatch pattern used to paint the non-downloaded area
     258   * Initialize the hatch pattern used to paint the non-downloaded area.
    262259   */
    263260  private void createHatchTexture() {
     
    283280      Area a = new Area(b);
    284281      // now successively subtract downloaded areas
    285       for (Bounds bounds : this.bounds) {
     282      for (Bounds bounds : this.data.bounds) {
    286283        Point p1 = mv.getPoint(bounds.getMin());
    287284        Point p2 = mv.getPoint(bounds.getMax());
     
    508505  }
    509506
    510   // EditDataLayerChanged
    511507  @Override
    512508  public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31455 r31459  
    8282    if (isViewDownloaded(view))
    8383      return;
    84     MapillaryLayer.getInstance().bounds.add(view);
     84    MapillaryLayer.getInstance().getData().bounds.add(view);
    8585    getImages(view);
    8686  }
     
    108108  }
    109109
     110  /**
     111   * Checks if the given {@LatLon} object lies inside the bounds of the
     112   * image.
     113   *
     114   * @param latlon
     115   * @return true if it lies inside the bounds; false otherwise;
     116   */
    110117  private static boolean isInBounds(LatLon latlon) {
    111     for (Bounds bounds : MapillaryLayer.getInstance().bounds) {
     118    for (Bounds bounds : MapillaryLayer.getInstance().getData().bounds) {
    112119      if (bounds.contains(latlon))
    113120        return true;
     
    141148    for (Bounds bounds : Main.map.mapView.getEditLayer().data
    142149        .getDataSourceBounds()) {
    143       if (!layer.bounds.contains(bounds)) {
    144         layer.bounds.add(bounds);
     150      if (!layer.getData().bounds.contains(bounds)) {
     151        layer.getData().bounds.add(bounds);
    145152        MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
    146153      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31451 r31459  
    132132
    133133  private boolean isInside(MapillaryAbstractImage image) {
    134     for (int i = 0; i < this.layer.bounds.size(); i++)
    135       if (this.layer.bounds.get(i).contains(image.getLatLon()))
     134    for (int i = 0; i < this.layer.getData().bounds.size(); i++)
     135      if (this.layer.getData().bounds.get(i).contains(image.getLatLon()))
    136136        return true;
    137137    return false;
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java

    r31454 r31459  
    2121public class MapillarySequenceDownloadThreadTest extends AbstractTest {
    2222
    23     /**
    24      * Test method for {@link org.openstreetmap.josm.plugins.mapillary.downloads.MapillarySequenceDownloadThread#run()}.
    25      *
    26      * This downloads a small area of mapillary-sequences where we know that images already exist.
    27      * When the download-thread finishes, we check if the Mapillary-layer now contains one or more images.
    28      *
    29      * @throws InterruptedException
    30      */
    31     @Test
    32     public void testRun() throws InterruptedException {
    33         System.out.println("[JUnit] MapillarySequenceDownloadThreadTest.testRun()");
    34         //Area around image UjEbeXZYIoyAKOsE-remlg (59.32125452° N 18.06166856° E)
    35         LatLon minLatLon = new LatLon(59.3212545, 18.0616685);
    36         LatLon maxLatLon = new LatLon(59.3212546, 18.0616686);
     23  /**
     24   * Test method for
     25   * {@link org.openstreetmap.josm.plugins.mapillary.downloads.MapillarySequenceDownloadThread#run()}
     26   * .
     27   *
     28   * This downloads a small area of mapillary-sequences where we know that
     29   * images already exist. When the download-thread finishes, we check if the
     30   * Mapillary-layer now contains one or more images.
     31   *
     32   * @throws InterruptedException
     33   */
     34  @Test
     35  public void testRun() throws InterruptedException {
     36    System.out.println("[JUnit] MapillarySequenceDownloadThreadTest.testRun()");
     37    // Area around image UjEbeXZYIoyAKOsE-remlg (59.32125452° N 18.06166856° E)
     38    LatLon minLatLon = new LatLon(59.3212545, 18.0616685);
     39    LatLon maxLatLon = new LatLon(59.3212546, 18.0616686);
    3740
    38         ExecutorService ex = Executors.newSingleThreadExecutor();
    39         String queryString = String.format(
     41    ExecutorService ex = Executors.newSingleThreadExecutor();
     42    String queryString = String
     43        .format(
    4044            Locale.UK,
    4145            "?max_lat=%.8f&max_lon=%.8f&min_lat=%.8f&min_lon=%.8f&limit=10&client_id=%s",
    42             maxLatLon.lat(),
    43             maxLatLon.lon(),
    44             minLatLon.lat(),
    45             minLatLon.lon(),
    46             MapillaryDownloader.CLIENT_ID
    47         );
    48         MapillaryLayer.getInstance().bounds.add(new Bounds(minLatLon, maxLatLon));
     46            maxLatLon.lat(), maxLatLon.lon(), minLatLon.lat(), minLatLon.lon(),
     47            MapillaryDownloader.CLIENT_ID);
     48    MapillaryLayer.getInstance().getData().bounds.add(new Bounds(minLatLon,
     49        maxLatLon));
    4950
    50         int page = 1;
    51         while (!ex.isShutdown() && MapillaryLayer.getInstance().getData().getImages().size() <= 0 && page < 50) {
    52             System.out.println("Sending sequence-request "+page+" to Mapillary-servers…");
    53             Thread downloadThread = new MapillarySequenceDownloadThread(ex, queryString+"&page="+page);
    54             downloadThread.start();
    55             downloadThread.join();
    56             page++;
    57             Thread.sleep(500);
    58         }
    59         assertTrue(MapillaryLayer.getInstance().getData().getImages().size() >= 1);
    60         System.out.println("One or more images were added to the MapillaryLayer within the given bounds.");
     51    int page = 1;
     52    while (!ex.isShutdown()
     53        && MapillaryLayer.getInstance().getData().getImages().size() <= 0
     54        && page < 50) {
     55      System.out.println("Sending sequence-request " + page
     56          + " to Mapillary-servers…");
     57      Thread downloadThread = new MapillarySequenceDownloadThread(ex,
     58          queryString + "&page=" + page);
     59      downloadThread.start();
     60      downloadThread.join();
     61      page++;
     62      Thread.sleep(500);
    6163    }
     64    assertTrue(MapillaryLayer.getInstance().getData().getImages().size() >= 1);
     65    System.out
     66        .println("One or more images were added to the MapillaryLayer within the given bounds.");
     67  }
    6268
    6369}
Note: See TracChangeset for help on using the changeset viewer.