Changeset 14734 in josm
- Timestamp:
- 2019-01-26T09:07:58+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r14628 r14734 164 164 BoundingXYVisitor bboxCalculator = new BoundingXYVisitor(); 165 165 bboxCalculator.computeBoundingBox(sel); 166 // increase bbox. This is required167 // especially if the bbox contains one single node, but helpful168 // in most other cases as well.169 bboxCalculator.enlargeBoundingBox();170 166 if (bboxCalculator.getBounds() != null) { 171 167 MainApplication.getMap().mapView.zoomTo(bboxCalculator); … … 396 392 } 397 393 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); 409 395 } 410 396 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r14676 r14734 28 28 */ 29 29 public class BoundingXYVisitor implements OsmPrimitiveVisitor, PrimitiveVisitor { 30 /** default value for setting "edit.zoom-enlarge-bbox" */ 31 private static final double ENLARGE_DEFAULT = 0.0002; 30 32 31 33 private ProjectionBounds bounds; … … 140 142 141 143 /** 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. 143 146 * If the bounding box has not been set (<code>min</code> or <code>max</code> 144 147 * equal <code>null</code>) this method does not do anything. 145 148 */ 146 149 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); 148 151 enlargeBoundingBox(enlarge, enlarge); 149 152 } … … 171 174 172 175 /** 173 * Enlarges the bounding box up to 0.00 1 degrees, depending on174 * its size. If the bounding box is small, it will be enlarged more in relation176 * 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 175 178 * to its beginning size. The larger the bounding box, the smaller the change, 176 179 * down to 0.0 degrees. … … 188 191 final double deltaLat = max.lat() - min.lat(); 189 192 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 }; 196 205 enlargeBoundingBox(enlargement.applyAsDouble(deltaLon), enlargement.applyAsDouble(deltaLat)); 197 206 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r14628 r14734 811 811 if (viewport == null) return; 812 812 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); 816 816 } else { 817 817 zoomTo(viewport.getCenter(), viewport.getScale(), true); … … 821 821 /** 822 822 * 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 } 837 847 } 838 848 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r14685 r14734 433 433 @Override 434 434 public void actionPerformed(ActionEvent e) { 435 BoundingXYVisitor box= new BoundingXYVisitor();435 BoundingXYVisitor v = new BoundingXYVisitor(); 436 436 Collection<OsmPrimitive> sel = model.getSelected(); 437 437 if (sel.isEmpty()) return; 438 box.computeBoundingBox(sel);439 if ( box.getBounds() == null)438 v.computeBoundingBox(sel); 439 if (v.getBounds() == null) 440 440 return; 441 box.enlargeBoundingBox(); 442 MainApplication.getMap().mapView.zoomTo(box); 441 MainApplication.getMap().mapView.zoomTo(v); 443 442 } 444 443
Note:
See TracChangeset
for help on using the changeset viewer.