Ignore:
Timestamp:
2015-07-23T17:40:03+02:00 (9 years ago)
Author:
nokutu
Message:

Creted semiautomatic download mode. The plugins behaves like continuous download plugin, downloading the signs of the areas you are watching.
When in automatic mode, if the download area is too big, it is changed to semiautomatic instead of manual.
In settings you can choose the download mode out of the three possible ones.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
9 edited

Legend:

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

    r31398 r31399  
    1818import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    1919import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     20import org.openstreetmap.josm.gui.NavigatableComponent;
    2021import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    2122import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    6364 *
    6465 */
    65 public class MapillaryLayer extends AbstractModifiableLayer implements DataSetListener, EditLayerChangeListener,
    66     LayerChangeListener {
     66public class MapillaryLayer extends AbstractModifiableLayer implements
     67    DataSetListener, EditLayerChangeListener, LayerChangeListener {
    6768
    6869  /** Maximum distance for the red/blue lines. */
    69   public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref
    70       .getInteger("mapillary.sequence-max-jump-distance", 100);
    71 
    72   private boolean TEMP_MANUAL = false;
     70  public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref.getInteger(
     71      "mapillary.sequence-max-jump-distance", 100);
     72
     73  /** If the download is in manual mode during the rest of the session */
     74  public boolean TEMP_SEMIAUTOMATIC = false;
    7375
    7476  /** Unique instance of the class */
     
    105107   */
    106108  private void init() {
    107     mode = new SelectMode();
    108109    if (Main.map != null && Main.map.mapView != null) {
    109       Main.map.mapView.addMouseListener(mode);
    110       Main.map.mapView.addMouseMotionListener(mode);
     110      setMode(new SelectMode());
    111111      Main.map.mapView.addLayer(this);
    112112      MapView.addEditLayerChangeListener(this, false);
     
    130130   *
    131131   * @param mode
    132    *        The mode that is going to be activated.
     132   *          The mode that is going to be activated.
    133133   */
    134134  public void setMode(AbstractMode mode) {
    135     Main.map.mapView.removeMouseListener(this.mode);
    136     Main.map.mapView.removeMouseMotionListener(this.mode);
     135    if (this.mode != null) {
     136      Main.map.mapView.removeMouseListener(this.mode);
     137      Main.map.mapView.removeMouseMotionListener(this.mode);
     138      NavigatableComponent.removeZoomChangeListener(this.mode);
     139    }
    137140    this.mode = mode;
    138141    Main.map.mapView.setNewCursor(mode.cursor, this);
    139142    Main.map.mapView.addMouseListener(mode);
    140143    Main.map.mapView.addMouseMotionListener(mode);
     144    NavigatableComponent.addZoomChangeListener(mode);
    141145    updateHelpText();
    142146  }
     
    145149   * Returns the unique instance of this class.
    146150   *
    147    * @return The unique isntance of this class.
     151   * @return The unique instance of this class.
    148152   */
    149153  public synchronized static MapillaryLayer getInstance() {
     
    159163  public void download() {
    160164    checkAreaTooBig();
    161     if (Main.pref.getBoolean("mapillary.download-manually") || TEMP_MANUAL)
     165    if (!Main.pref.get("mapillary.download-mode").equals(
     166        MapillaryDownloader.MODES[0])
     167        || TEMP_SEMIAUTOMATIC)
    162168      return;
    163169    for (Bounds bounds : Main.map.mapView.getEditLayer().data
     
    165171      if (!this.bounds.contains(bounds)) {
    166172        this.bounds.add(bounds);
    167         new MapillaryDownloader().getImages(bounds.getMin(), bounds.getMax());
     173        MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
    168174      }
    169175    }
     
    183189    }
    184190    if (area > MapillaryDownloadViewAction.MAX_AREA) {
    185       TEMP_MANUAL = true;
     191      TEMP_SEMIAUTOMATIC = true;
    186192      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
    187193      JOptionPane
     
    223229
    224230  /**
    225    * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map view.
     231   * Zooms to fit all the {@link MapillaryAbstractImage} icons into the map
     232   * view.
    226233   */
    227234  public void showAllPictures() {
     
    240247        maxLon = img.getLatLon().lon();
    241248    }
    242     Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon (maxLat, maxLon)));
     249    Main.map.mapView.zoomTo(new Bounds(new LatLon(minLat, minLon), new LatLon(
     250        maxLat, maxLon)));
    243251  }
    244252
     
    437445    double locationX = width / 2;
    438446    double locationY = height / 2;
    439     AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
    440     AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
    441 
    442     g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), Main.map.mapView);
     447    AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired,
     448        locationX, locationY);
     449    AffineTransformOp op = new AffineTransformOp(tx,
     450        AffineTransformOp.TYPE_BILINEAR);
     451
     452    g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2),
     453        Main.map.mapView);
    443454    if (data.getHighlighted() == image) {
    444455      drawPointHighlight(g, p, 16);
     
    458469  @Override
    459470  public void mergeFrom(Layer from) {
    460     throw new UnsupportedOperationException("This layer does not support merging yet");
     471    throw new UnsupportedOperationException(
     472        "This layer does not support merging yet");
    461473  }
    462474
     
    480492    MapillaryImage selected = (MapillaryImage) data.getSelectedImage();
    481493    MapillaryImage[] ret = new MapillaryImage[2];
    482     double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, SEQUENCE_MAX_JUMP_DISTANCE };
     494    double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE,
     495        SEQUENCE_MAX_JUMP_DISTANCE };
    483496    LatLon selectedCoords = data.getSelectedImage().getLatLon();
    484497    for (MapillaryAbstractImage imagePrev : data.getImages()) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31396 r31399  
    1515import org.openstreetmap.josm.plugins.Plugin;
    1616import org.openstreetmap.josm.plugins.PluginInformation;
     17import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    1718import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    1819import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryHistoryDialog;
     
    134135      Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);
    135136      setMenuEnabled(DOWNLOAD_MENU, true);
    136       if (Main.pref.getBoolean("mapillary.download-manually"))
     137      if (Main.pref.get("mapillary.download-mode").equals(
     138          MapillaryDownloader.MODES[2]))
    137139        setMenuEnabled(DOWNLOAD_VIEW_MENU, true);
    138140      setMenuEnabled(IMPORT_MENU, true);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java

    r31386 r31399  
    2727  /** Max area to be downloaded */
    2828  public static final double MAX_AREA = Main.pref.getDouble(
    29       "mapillary.max-download-area", 0.020);
     29      "mapillary.max-download-area", 0.015);
    3030
    3131  /**
     
    4545    MapillaryLayer.getInstance().bounds.add(Main.map.mapView.getRealBounds());
    4646    if (Main.map.mapView.getRealBounds().getArea() <= MAX_AREA) {
    47       new MapillaryDownloader().getImages(Main.map.mapView.getRealBounds());
     47      MapillaryDownloader.getImages(Main.map.mapView.getRealBounds());
    4848    } else {
    4949      JOptionPane.showMessageDialog(Main.parent,
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31387 r31399  
    99import org.openstreetmap.josm.data.coor.LatLon;
    1010import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     11import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction;
    1112
    1213/**
     
    1920public class MapillaryDownloader {
    2021
     22  /** Possible download modes.*/
     23  public static final String[] MODES = new String[] { "Automatic", "Semiautomatic",
     24  "Manual" };
     25
    2126  /** Base URL of the Mapillary API. */
    2227  public final static String BASE_URL = "https://a.mapillary.com/v2/";
     
    2530  /** Executor that will run the petitions */
    2631  public final static Executor EXECUTOR = Executors.newSingleThreadExecutor();
    27 
    2832
    2933  /**
     
    3640   *          The maximum latitude and longitude of the rectangle
    3741   */
    38   public void getImages(LatLon minLatLon, LatLon maxLatLon) {
     42  public static void getImages(LatLon minLatLon, LatLon maxLatLon) {
    3943    ConcurrentHashMap<String, Double> queryStringParts = new ConcurrentHashMap<>();
    4044    queryStringParts.put("min_lat", minLatLon.lat());
     
    4448
    4549    try {
    46       EXECUTOR.execute(new MapillarySquareDownloadManagerThread(queryStringParts, MapillaryLayer.getInstance()));
     50      EXECUTOR.execute(new MapillarySquareDownloadManagerThread(
     51          queryStringParts, MapillaryLayer.getInstance()));
    4752    } catch (Exception e) {
    4853      Main.error(e);
    4954    }
     55  }
     56
     57  /**
     58   * If some part of the current view has not been downloaded, it is downloaded.
     59   *
     60   */
     61  public static void completeView() {
     62    Bounds view = Main.map.mapView.getRealBounds();
     63    if (view.getArea() > MapillaryDownloadViewAction.MAX_AREA)
     64      return;
     65    for (Bounds bound : MapillaryLayer.getInstance().bounds) {
     66      if (!view.intersects(bound))
     67        continue;
     68      if (bound.equals(view)) {
     69        // Already downloaded
     70        return;
     71      }
     72    }
     73    MapillaryLayer.getInstance().bounds.add(view);
     74    getImages(view);
    5075  }
    5176
     
    5580   * @param bounds
    5681   */
    57   public void getImages(Bounds bounds) {
     82  public static void getImages(Bounds bounds) {
    5883    getImages(bounds.getMin(), bounds.getMax());
    5984  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31391 r31399  
    4040  /**
    4141   * Main constructor.
    42    * 
     42   *
    4343   * @param ex
    4444   * @param queryString
     
    9090            jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at")
    9191                .longValue());
    92 
    9392        List<MapillaryImage> finalImages = new ArrayList<>(images);
    9493        // Here it gets only those images which are in the downloaded
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31391 r31399  
    3636  /**
    3737   * Main constructor.
    38    * 
     38   *
    3939   * @param queryStringParts
    4040   * @param layer
    41    * 
     41   *
    4242   */
    4343  public MapillarySquareDownloadManagerThread(
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31390 r31399  
    4747  @Override
    4848  public void setText(String text) {
    49     super.setText("<html><font color=\"#0000CF\" size=\"2\">" + text + "</font></html>"); //$NON-NLS-1$ //$NON-NLS-2$
     49    super
     50        .setText("<html><font color=\"#0000CF\" size=\"2\">" + text + "</font></html>"); //$NON-NLS-1$ //$NON-NLS-2$
    5051    this.text = text;
    5152  }
     
    7071  /**
    7172   * Returns the text set by the user.
    72    * 
     73   *
    7374   * @return The plain-text written in the label.
    7475   */
     
    8485    super.processMouseEvent(evt);
    8586    if (evt.getID() == MouseEvent.MOUSE_CLICKED)
    86       fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getNormalText()));
     87      fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
     88          getNormalText()));
    8789  }
    8890
     
    9092   * Adds an ActionListener to the list of listeners receiving notifications
    9193   * when the label is clicked.
    92    * 
     94   *
    9395   * @param listener
    9496   */
     
    100102   * Removes the given ActionListener from the list of listeners receiving
    101103   * notifications when the label is clicked.
    102    * 
     104   *
    103105   * @param listener
    104106   */
     
    109111  /**
    110112   * Fires an ActionEvent to all interested listeners.
    111    * @param evt
     113   *
     114   * @param evt
    112115   */
    113116  protected void fireActionPerformed(ActionEvent evt) {
     
    126129      return;
    127130    Desktop desktop = Desktop.getDesktop();
    128     try {
    129       desktop.browse(url.toURI());
    130     } catch (IOException | URISyntaxException ex) {
    131       ex.printStackTrace();
    132     } catch (UnsupportedOperationException ex) {
     131    if (desktop.isSupported(Desktop.Action.BROWSE)) {
     132      try {
     133        desktop.browse(url.toURI());
     134      } catch (IOException | URISyntaxException e1) {
     135        Main.error(e1);
     136      }
     137    } else {
    133138      Runtime runtime = Runtime.getRuntime();
    134139      try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31396 r31399  
    1313import javax.swing.JButton;
    1414import javax.swing.JCheckBox;
     15import javax.swing.JComboBox;
     16import javax.swing.JLabel;
    1517import javax.swing.JPanel;
    1618
     
    2022import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
    2123import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     24import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    2225import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener;
    2326
     
    3235  private JCheckBox reverseButtons = new JCheckBox(
    3336      tr("Reverse buttons position when displaying images."));
    34   private JCheckBox downloadMode = new JCheckBox(tr("Download images manually"));
     37  private JComboBox<String> downloadMode = new JComboBox<>(
     38      MapillaryDownloader.MODES);
    3539  private JCheckBox displayHour = new JCheckBox(
    3640      tr("Display hour when the picture was taken"));
     
    5054    reverseButtons.setSelected(Main.pref
    5155        .getBoolean("mapillary.reverse-buttons"));
    52     downloadMode.setSelected(Main.pref
    53         .getBoolean("mapillary.download-manually"));
    5456    displayHour.setSelected(Main.pref
    5557        .getBoolean("mapillary.display-hour", true));
     
    5961    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    6062    panel.add(reverseButtons);
    61     panel.add(downloadMode);
     63
     64    JPanel downloadModePanel = new JPanel();
     65    downloadModePanel.add(new JLabel(tr("Download mode: ")));
     66    downloadModePanel.add(downloadMode);
     67    panel.add(downloadModePanel);
     68
    6269    panel.add(displayHour);
    6370    panel.add(format24);
     
    6774      oauth.setText("Login");
    6875    else
    69        oauth.setText("Already loged in, click to relogin.");
     76      oauth.setText("Already loged in, click to relogin.");
    7077    panel.add(oauth);
    7178    gui.getDisplayPreference().addSubTab(this, "Mapillary", panel);
     
    7683    boolean mod = false;
    7784    Main.pref.put("mapillary.reverse-buttons", reverseButtons.isSelected());
    78     Main.pref.put("mapillary.download-manually", downloadMode.isSelected());
    79     MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU,
    80         downloadMode.isSelected());
     85
     86    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false);
     87    if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0]))
     88      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]);
     89    if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1]))
     90      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]);
     91    if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) {
     92      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]);
     93      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
     94    }
    8195
    8296    Main.pref.put("mapillary.display-hour", displayHour.isSelected());
     
    108122      String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email";
    109123      Desktop desktop = Desktop.getDesktop();
    110       try {
    111         desktop.browse(new URI(url));
    112       } catch (IOException | URISyntaxException ex) {
    113         ex.printStackTrace();
    114       } catch (UnsupportedOperationException ex) {
     124      if (desktop.isSupported(Desktop.Action.BROWSE)) {
     125        try {
     126          desktop.browse(new URI(url));
     127        } catch (IOException | URISyntaxException e1) {
     128          Main.error(e1);
     129        }
     130      } else {
    115131        Runtime runtime = Runtime.getRuntime();
    116132        try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31389 r31399  
    55import java.awt.Point;
    66import java.awt.event.MouseAdapter;
     7import java.util.Calendar;
    78
    89import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.Bounds;
    1011import org.openstreetmap.josm.gui.MapView;
     12import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
    1113import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    1214import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     15import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     16import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    1317
    1418/**
     
    1923 *
    2024 */
    21 public abstract class AbstractMode extends MouseAdapter {
     25public abstract class AbstractMode extends MouseAdapter implements
     26    ZoomChangeListener {
    2227
    2328  protected MapillaryData data = MapillaryData.getInstance();
     29
     30  private long lastDownload;
    2431
    2532  /**
     
    5461  public abstract void paint(Graphics2D g, MapView mv, Bounds box);
    5562
     63  @Override
     64  public synchronized void zoomChanged() {
     65    if (Main.pref.get("mapillary.download-mode").equals(
     66        MapillaryDownloader.MODES[1])
     67        || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC) {
     68      if (Calendar.getInstance().getTimeInMillis() - lastDownload >= 2000) {
     69        lastDownload = Calendar.getInstance().getTimeInMillis();
     70        MapillaryDownloader.completeView();
     71      } else {
     72        new Thread() {
     73          @Override
     74          public synchronized void run() {
     75            try {
     76              wait(100);
     77            } catch (InterruptedException e) {
     78            }
     79            zoomChanged();
     80          }
     81        }.start();
     82      }
     83    }
     84  }
    5685}
Note: See TracChangeset for help on using the changeset viewer.