Ignore:
Timestamp:
2015-12-16T17:16:48+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Improve the calculation of zoom bounds for a given set of images

File:
1 edited

Legend:

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

    r31799 r31836  
    384384   *          Whether the added images must be selected or not.
    385385   */
    386   public static void showPictures(final List<MapillaryAbstractImage> images,
    387       final boolean select) {
     386  public static void showPictures(final List<MapillaryAbstractImage> images, final boolean select) {
    388387    if (!SwingUtilities.isEventDispatchThread()) {
    389388      SwingUtilities.invokeLater(new Runnable() {
     
    394393      });
    395394    } else {
    396       double minLat = 90;
    397       double minLon = 180;
    398       double maxLat = -90;
    399       double maxLon = -180;
    400       for (MapillaryAbstractImage img : images) {
    401         if (img.getLatLon().lat() < minLat)
    402           minLat = img.getLatLon().lat();
    403         if (img.getLatLon().lon() < minLon)
    404           minLon = img.getLatLon().lon();
    405         if (img.getLatLon().lat() > maxLat)
    406           maxLat = img.getLatLon().lat();
    407         if (img.getLatLon().lon() > maxLon)
    408           maxLon = img.getLatLon().lon();
     395      Bounds zoomBounds;
     396      if (images.isEmpty()) {
     397        zoomBounds = new Bounds(new LatLon(0, 0));
     398      } else {
     399        zoomBounds = new Bounds(images.get(0).getLatLon());
     400        for (MapillaryAbstractImage img : images) {
     401          zoomBounds.extend(img.getLatLon());
     402        }
    409403      }
    410       Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon),
    411           new LatLon(maxLat, maxLon));
    412404      // The zoom rectangle must have a minimum size.
    413       double latExtent = zoomBounds.getMaxLat()
    414           - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE
    415               ? zoomBounds.getMaxLat() - zoomBounds.getMinLat()
    416               : MIN_ZOOM_SQUARE_SIDE;
    417       double lonExtent = zoomBounds.getMaxLon()
    418           - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE
    419               ? zoomBounds.getMaxLon() - zoomBounds.getMinLon()
    420               : MIN_ZOOM_SQUARE_SIDE;
     405      double latExtent = Math.max(zoomBounds.getMaxLat() - zoomBounds.getMinLat(), MIN_ZOOM_SQUARE_SIDE);
     406      double lonExtent = Math.max(zoomBounds.getMaxLon() - zoomBounds.getMinLon(), MIN_ZOOM_SQUARE_SIDE);
    421407      zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
    422408
Note: See TracChangeset for help on using the changeset viewer.