Changeset 14628 in josm for trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
- Timestamp:
- 2019-01-03T20:06:44+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r14397 r14628 292 292 mapView.zoomNext(); 293 293 break; 294 default: 295 BoundingXYVisitor bbox = getBoundingBox(); 296 if (bbox != null && bbox.getBounds() != null) { 297 mapView.zoomTo(bbox); 298 } 299 } 300 } 301 putValue("active", Boolean.TRUE); 294 case PROBLEM: 295 modeProblem(new ValidatorBoundingXYVisitor()); 296 break; 297 case DATA: 298 modeData(new BoundingXYVisitor()); 299 break; 300 case LAYER: 301 modeLayer(new BoundingXYVisitor()); 302 break; 303 case SELECTION: 304 case CONFLICT: 305 modeSelectionOrConflict(new BoundingXYVisitor()); 306 break; 307 case DOWNLOAD: 308 modeDownload(new BoundingXYVisitor()); 309 break; 310 } 311 putValue("active", Boolean.TRUE); 312 } 302 313 } 303 314 … … 328 339 } 329 340 330 private BoundingXYVisitor getBoundingBox() { 331 switch (mode) { 332 case PROBLEM: 333 return modeProblem(new ValidatorBoundingXYVisitor()); 334 case DATA: 335 return modeData(new BoundingXYVisitor()); 336 case LAYER: 337 return modeLayer(new BoundingXYVisitor()); 338 case SELECTION: 339 case CONFLICT: 340 return modeSelectionOrConflict(new BoundingXYVisitor()); 341 case DOWNLOAD: 342 return modeDownload(new BoundingXYVisitor()); 343 default: 344 return new BoundingXYVisitor(); 345 } 346 } 347 348 private static BoundingXYVisitor modeProblem(ValidatorBoundingXYVisitor v) { 341 private static void modeProblem(ValidatorBoundingXYVisitor v) { 349 342 TestError error = MainApplication.getMap().validatorDialog.getSelectedError(); 350 343 if (error == null) 351 return null;344 return; 352 345 v.visit(error); 353 346 if (v.getBounds() == null) 354 return null; 355 v.enlargeBoundingBox(Config.getPref().getDouble("validator.zoom-enlarge-bbox", 0.0002)); 356 return v; 357 } 358 359 private static BoundingXYVisitor modeData(BoundingXYVisitor v) { 347 return; 348 MainApplication.getMap().mapView.zoomTo(v); 349 } 350 351 private static void modeData(BoundingXYVisitor v) { 360 352 for (Layer l : MainApplication.getLayerManager().getLayers()) { 361 353 l.visitBoundingBox(v); 362 354 } 363 return v;364 } 365 366 private BoundingXYVisitormodeLayer(BoundingXYVisitor v) {355 MainApplication.getMap().mapView.zoomTo(v); 356 } 357 358 private void modeLayer(BoundingXYVisitor v) { 367 359 // try to zoom to the first selected layer 368 360 Layer l = getFirstSelectedLayer(); 369 361 if (l == null) 370 return null;362 return; 371 363 l.visitBoundingBox(v); 372 return v;373 } 374 375 private BoundingXYVisitormodeSelectionOrConflict(BoundingXYVisitor v) {364 MainApplication.getMap().mapView.zoomTo(v); 365 } 366 367 private void modeSelectionOrConflict(BoundingXYVisitor v) { 376 368 Collection<IPrimitive> sel = new HashSet<>(); 377 369 if (AutoScaleMode.SELECTION == mode) { … … 395 387 tr("Information"), 396 388 JOptionPane.INFORMATION_MESSAGE); 397 return null;389 return; 398 390 } 399 391 for (IPrimitive osm : sel) { 400 392 osm.accept(v); 401 393 } 402 403 // Increase the bounding box by up to 100% to give more context. 404 v.enlargeBoundingBoxLogarithmically(100); 405 // Make the bounding box at least 100 meter wide to 406 // ensure reasonable zoom level when zooming onto single nodes. 407 v.enlargeToMinSize(Config.getPref().getDouble("zoom_to_selection_min_size_in_meter", 100)); 408 return v; 409 } 410 411 private BoundingXYVisitor modeDownload(BoundingXYVisitor v) { 394 if (v.getBounds() == null) { 395 return; 396 } 397 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 } 409 } 410 411 private void modeDownload(BoundingXYVisitor v) { 412 412 if (lastZoomTime > 0 && 413 413 System.currentTimeMillis() - lastZoomTime > Config.getPref().getLong("zoom.bounds.reset.time", TimeUnit.SECONDS.toMillis(10))) { … … 438 438 } 439 439 } 440 return v;440 MainApplication.getMap().mapView.zoomTo(v); 441 441 } 442 442
Note:
See TracChangeset
for help on using the changeset viewer.