Changeset 7816 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2014-12-17T01:49:45+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r7575 r7816 37 37 38 38 import org.openstreetmap.josm.Main; 39 import org.openstreetmap.josm.actions.AutoScaleAction;40 39 import org.openstreetmap.josm.actions.mapmode.MapMode; 41 40 import org.openstreetmap.josm.data.Bounds; 42 41 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 43 42 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 44 import org.openstreetmap.josm.data.DataSource;45 43 import org.openstreetmap.josm.data.SelectionChangedListener; 46 44 import org.openstreetmap.josm.data.ViewportData; … … 233 231 */ 234 232 public MapView(final JPanel contentPane, final ViewportData viewportData) { 233 initialViewport = viewportData; 235 234 Main.pref.addPreferenceChangeListener(this); 236 235 final boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0)!=null; … … 250 249 251 250 mapMover = new MapMover(MapView.this, contentPane); 252 if (viewportData != null) {253 zoomTo(viewportData.getCenter(), viewportData.getScale());254 } else {255 OsmDataLayer layer = getEditLayer();256 if (layer != null) {257 if (!zoomToDataSetBoundingBox(layer.data)) {258 // no bounding box defined259 AutoScaleAction.autoScale("data");260 }261 } else {262 AutoScaleAction.autoScale("layer");263 }264 }265 251 } 266 252 }); … … 542 528 */ 543 529 @Override public void paint(Graphics g) { 530 if (initialViewport != null) { 531 if (initialViewport.getBounds() != null) { 532 BoundingXYVisitor box = new BoundingXYVisitor(); 533 box.visit(initialViewport.getBounds()); 534 recalculateCenterScale(box); 535 } else { 536 zoomTo(initialViewport.getCenter(), initialViewport.getScale(), true); 537 } 538 initialViewport = null; 539 } 544 540 if (BugReportExceptionHandler.exceptionHandlingInProgress()) 545 541 return; … … 868 864 } 869 865 870 /**871 * Tries to zoom to the download boundingbox[es] of the current edit layer872 * (aka {@link OsmDataLayer}). If the edit layer has multiple download bounding873 * boxes it zooms to a large virtual bounding box containing all smaller ones.874 *875 * @return <code>true</code> if a zoom operation has been performed876 */877 public boolean zoomToDataSetBoundingBox(DataSet ds) {878 // In case we already have an existing data layer ...879 OsmDataLayer layer= getEditLayer();880 if (layer == null)881 return false;882 Collection<DataSource> dataSources = ds.dataSources;883 // ... with bounding box[es] of data loaded from OSM or a file...884 BoundingXYVisitor bbox = new BoundingXYVisitor();885 for (DataSource source : dataSources) {886 bbox.visit(source.bounds);887 }888 if (bbox.hasExtend()) {889 // ... we zoom to it's bounding box890 recalculateCenterScale(bbox);891 return true;892 }893 return false;894 }895 896 866 public boolean addTemporaryLayer(MapViewPaintable mvp) { 897 867 if (temporaryLayers.contains(mvp)) return false; -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r7448 r7816 32 32 import org.openstreetmap.josm.data.ProjectionBounds; 33 33 import org.openstreetmap.josm.data.SystemOfMeasurement; 34 import org.openstreetmap.josm.data.ViewportData; 34 35 import org.openstreetmap.josm.data.coor.CachedLatLon; 35 36 import org.openstreetmap.josm.data.coor.EastNorth; … … 182 183 private Polygon paintPoly = null; 183 184 185 protected ViewportData initialViewport; 186 184 187 /** 185 188 * Constructs a new {@code NavigatableComponent}. … … 406 409 407 410 /** 408 * Zoom to the given coordinate. 411 * Zoom to the given coordinate and scale. 412 * 409 413 * @param newCenter The center x-value (easting) to zoom to. 410 414 * @param newScale The scale to use. 411 415 */ 412 416 public void zoomTo(EastNorth newCenter, double newScale) { 417 zoomTo(newCenter, newScale, false); 418 } 419 420 /** 421 * Zoom to the given coordinate and scale. 422 * 423 * @param newCenter The center x-value (easting) to zoom to. 424 * @param newScale The scale to use. 425 * @param initial true if this call initializes the viewport. 426 */ 427 public void zoomTo(EastNorth newCenter, double newScale, boolean initial) { 413 428 Bounds b = getProjection().getWorldBoundsLatLon(); 414 429 LatLon cl = Projections.inverseProject(newCenter); … … 446 461 447 462 if (!newCenter.equals(center) || (scale != newScale)) { 448 pushZoomUndo(center, scale); 449 zoomNoUndoTo(newCenter, newScale); 463 if (!initial) { 464 pushZoomUndo(center, scale); 465 } 466 zoomNoUndoTo(newCenter, newScale, initial); 450 467 } 451 468 } … … 453 470 /** 454 471 * Zoom to the given coordinate without adding to the zoom undo buffer. 472 * 455 473 * @param newCenter The center x-value (easting) to zoom to. 456 474 * @param newScale The scale to use. 457 */ 458 private void zoomNoUndoTo(EastNorth newCenter, double newScale) { 475 * @param initial true if this call initializes the viewport. 476 */ 477 private void zoomNoUndoTo(EastNorth newCenter, double newScale, boolean intial) { 459 478 if (!newCenter.equals(center)) { 460 479 EastNorth oldCenter = center; 461 480 center = newCenter; 462 firePropertyChange(PROPNAME_CENTER, oldCenter, newCenter); 481 if (!intial) { 482 firePropertyChange(PROPNAME_CENTER, oldCenter, newCenter); 483 } 463 484 } 464 485 if (scale != newScale) { 465 486 double oldScale = scale; 466 487 scale = newScale; 467 firePropertyChange(PROPNAME_SCALE, oldScale, newScale); 468 } 469 470 repaint(); 471 fireZoomChanged(); 488 if (!intial) { 489 firePropertyChange(PROPNAME_SCALE, oldScale, newScale); 490 } 491 } 492 493 if (!intial) { 494 repaint(); 495 fireZoomChanged(); 496 } 472 497 } 473 498 … … 595 620 ZoomData zoom = zoomUndoBuffer.pop(); 596 621 zoomRedoBuffer.push(new ZoomData(center, scale)); 597 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale() );622 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale(), false); 598 623 } 599 624 } … … 603 628 ZoomData zoom = zoomRedoBuffer.pop(); 604 629 zoomUndoBuffer.push(new ZoomData(center, scale)); 605 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale() );630 zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale(), false); 606 631 } 607 632 }
Note:
See TracChangeset
for help on using the changeset viewer.