Changeset 14734 in josm


Ignore:
Timestamp:
2019-01-26T09:07:58+01:00 (6 years ago)
Author:
GerdP
Message:

fix #16706 (16706-improve-v2.patch)

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r14628 r14734  
    164164        BoundingXYVisitor bboxCalculator = new BoundingXYVisitor();
    165165        bboxCalculator.computeBoundingBox(sel);
    166         // increase bbox. This is required
    167         // especially if the bbox contains one single node, but helpful
    168         // in most other cases as well.
    169         bboxCalculator.enlargeBoundingBox();
    170166        if (bboxCalculator.getBounds() != null) {
    171167            MainApplication.getMap().mapView.zoomTo(bboxCalculator);
     
    396392        }
    397393
    398         // Do not zoom if the current scale covers the selection, #16706
    399         final MapView mapView = MainApplication.getMap().mapView;
    400         final double mapScale = mapView.getScale();
    401         final double minScale = v.getBounds().getScale(mapView.getWidth(), mapView.getHeight());
    402         v.enlargeBoundingBoxLogarithmically();
    403         final double maxScale = v.getBounds().getScale(mapView.getWidth(), mapView.getHeight());
    404         if (minScale <= mapScale && mapScale < maxScale) {
    405             mapView.zoomTo(v.getBounds().getCenter());
    406         } else {
    407             mapView.zoomTo(v);
    408         }
     394        MainApplication.getMap().mapView.zoomTo(v);
    409395    }
    410396
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r14676 r14734  
    2828 */
    2929public class BoundingXYVisitor implements OsmPrimitiveVisitor, PrimitiveVisitor {
     30    /** default value for setting "edit.zoom-enlarge-bbox" */
     31    private static final double ENLARGE_DEFAULT = 0.0002;
    3032
    3133    private ProjectionBounds bounds;
     
    140142
    141143    /**
    142      * Enlarges the calculated bounding box by 0.001 degrees.
     144     * Enlarges the calculated bounding box by 0.0002 degrees or user value
     145     * given in edit.zoom-enlarge-bbox.
    143146     * If the bounding box has not been set (<code>min</code> or <code>max</code>
    144147     * equal <code>null</code>) this method does not do anything.
    145148     */
    146149    public void enlargeBoundingBox() {
    147         final double enlarge = Config.getPref().getDouble("edit.zoom-enlarge-bbox", 0.001);
     150        final double enlarge = Config.getPref().getDouble("edit.zoom-enlarge-bbox", ENLARGE_DEFAULT);
    148151        enlargeBoundingBox(enlarge, enlarge);
    149152    }
     
    171174
    172175    /**
    173      * Enlarges the bounding box up to 0.001 degrees, depending on
    174      * its size. If the bounding box is small, it will be enlarged more in relation
     176     * Enlarges the bounding box up to 0.0002 degrees, depending on its size and user
     177     * settings in edit.zoom-enlarge-bbox. If the bounding box is small, it will be enlarged more in relation
    175178     * to its beginning size. The larger the bounding box, the smaller the change,
    176179     * down to 0.0 degrees.
     
    188191        final double deltaLat = max.lat() - min.lat();
    189192        final double deltaLon = max.lon() - min.lon();
    190         // [0.001, 0.1] degree -> [0.001, 0.0] degree enlargement
    191         final DoubleUnaryOperator enlargement = deg -> deg < 0.001
    192                 ? 0.001
    193                 : deg < 0.1
    194                 ? 0.001 - deg / 100
    195                 : 0.0;
     193        final double enlarge = Config.getPref().getDouble("edit.zoom-enlarge-bbox", ENLARGE_DEFAULT);
     194
     195        final DoubleUnaryOperator enlargement = deltaDegress -> {
     196            if (deltaDegress < enlarge) {
     197                // delta is very small, use configured minimum value
     198                return enlarge;
     199            }
     200            if (deltaDegress < 0.1) {
     201                return enlarge - deltaDegress / 100;
     202            }
     203            return 0.0;
     204        };
    196205        enlargeBoundingBox(enlargement.applyAsDouble(deltaLon), enlargement.applyAsDouble(deltaLat));
    197206    }
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r14628 r14734  
    811811        if (viewport == null) return;
    812812        if (viewport.getBounds() != null) {
    813             BoundingXYVisitor box = new BoundingXYVisitor();
    814             box.visit(viewport.getBounds());
    815             zoomTo(box);
     813            BoundingXYVisitor v = new BoundingXYVisitor();
     814            v.visit(viewport.getBounds());
     815            zoomTo(v);
    816816        } else {
    817817            zoomTo(viewport.getCenter(), viewport.getScale(), true);
     
    821821    /**
    822822     * Set the new dimension to the view.
    823      * @param box box to zoom to
    824      */
    825     public void zoomTo(BoundingXYVisitor box) {
    826         if (box == null) {
    827             box = new BoundingXYVisitor();
    828         }
    829         if (box.getBounds() == null) {
    830             box.visit(getProjection().getWorldBoundsLatLon());
    831         }
    832         if (!box.hasExtend()) {
    833             box.enlargeBoundingBox();
    834         }
    835 
    836         zoomTo(box.getBounds());
     823     * @param v box to zoom to
     824     */
     825    public void zoomTo(BoundingXYVisitor v) {
     826        if (v == null) {
     827            v = new BoundingXYVisitor();
     828        }
     829        if (v.getBounds() == null) {
     830            v.visit(getProjection().getWorldBoundsLatLon());
     831        }
     832
     833        // increase bbox. This is required
     834        // especially if the bbox contains one single node, but helpful
     835        // in most other cases as well.
     836        // Do not zoom if the current scale covers the selection, #16706
     837        final MapView mapView = MainApplication.getMap().mapView;
     838        final double mapScale = mapView.getScale();
     839        final double minScale = v.getBounds().getScale(mapView.getWidth(), mapView.getHeight());
     840        v.enlargeBoundingBoxLogarithmically();
     841        final double maxScale = v.getBounds().getScale(mapView.getWidth(), mapView.getHeight());
     842        if (minScale <= mapScale && mapScale < maxScale) {
     843            mapView.zoomTo(v.getBounds().getCenter());
     844        } else {
     845            zoomTo(v.getBounds());
     846        }
    837847    }
    838848
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r14685 r14734  
    433433        @Override
    434434        public void actionPerformed(ActionEvent e) {
    435             BoundingXYVisitor box = new BoundingXYVisitor();
     435            BoundingXYVisitor v = new BoundingXYVisitor();
    436436            Collection<OsmPrimitive> sel = model.getSelected();
    437437            if (sel.isEmpty()) return;
    438             box.computeBoundingBox(sel);
    439             if (box.getBounds() == null)
     438            v.computeBoundingBox(sel);
     439            if (v.getBounds() == null)
    440440                return;
    441             box.enlargeBoundingBox();
    442             MainApplication.getMap().mapView.zoomTo(box);
     441            MainApplication.getMap().mapView.zoomTo(v);
    443442        }
    444443
Note: See TracChangeset for help on using the changeset viewer.