Changeset 7816 in josm for trunk/src/org
- Timestamp:
- 2014-12-17T01:49:45+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7802 r7816 65 65 import org.openstreetmap.josm.data.Bounds; 66 66 import org.openstreetmap.josm.data.Preferences; 67 import org.openstreetmap.josm.data.ProjectionBounds; 67 68 import org.openstreetmap.josm.data.UndoRedoHandler; 68 69 import org.openstreetmap.josm.data.ViewportData; … … 72 73 import org.openstreetmap.josm.data.osm.OsmPrimitive; 73 74 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; 75 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 74 76 import org.openstreetmap.josm.data.projection.Projection; 75 77 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; … … 692 694 693 695 /** 694 * Add a new layer to the map. If no map exists, create one. 695 */ 696 public final synchronized void addLayer(final Layer layer) { 696 * Add a new layer to the map. 697 * 698 * If no map exists, create one. 699 * 700 * @param layer the layer 701 * 702 * @see #addLayer(org.openstreetmap.josm.gui.layer.Layer, org.openstreetmap.josm.data.ProjectionBounds) 703 * @see #addLayer(org.openstreetmap.josm.gui.layer.Layer, org.openstreetmap.josm.data.ViewportData) 704 */ 705 public final void addLayer(final Layer layer) { 706 BoundingXYVisitor v = new BoundingXYVisitor(); 707 layer.visitBoundingBox(v); 708 addLayer(layer, v.getBounds()); 709 } 710 711 /** 712 * Add a new layer to the map. 713 * 714 * If no map exists, create one. 715 * 716 * @param layer the layer 717 * @param bounds the bounds of the layer (target zoom area) 718 */ 719 public final synchronized void addLayer(final Layer layer, ProjectionBounds bounds) { 720 addLayer(layer, new ViewportData(bounds)); 721 } 722 723 /** 724 * Add a new layer to the map. 725 * 726 * If no map exists, create one. 727 * 728 * @param layer the layer 729 * @param viewport the viewport to zoom to 730 */ 731 public final synchronized void addLayer(final Layer layer, ViewportData viewport) { 697 732 boolean noMap = map == null; 698 733 if (noMap) { 699 createMapFrame(layer, null);734 createMapFrame(layer, viewport); 700 735 } 701 736 layer.hookUpMapView(); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r7749 r7816 15 15 import org.openstreetmap.josm.data.Bounds; 16 16 import org.openstreetmap.josm.data.DataSource; 17 import org.openstreetmap.josm.data.ProjectionBounds; 17 18 import org.openstreetmap.josm.data.coor.LatLon; 18 19 import org.openstreetmap.josm.data.osm.DataSet; … … 250 251 } 251 252 252 protected void computeBboxAndCenterScale(Bounds bounds) {253 protected ProjectionBounds computeBbox(Bounds bounds) { 253 254 BoundingXYVisitor v = new BoundingXYVisitor(); 254 255 if (bounds != null) { … … 257 258 v.computeBoundingBox(dataSet.getNodes()); 258 259 } 260 return v.getBounds(); 261 } 262 263 protected void computeBboxAndCenterScale(Bounds bounds) { 264 ProjectionBounds pb = computeBbox(bounds); 265 BoundingXYVisitor v = new BoundingXYVisitor(); 266 v.visit(pb); 259 267 Main.map.mapView.recalculateCenterScale(v); 260 268 } … … 267 275 // 268 276 final OsmDataLayer layer = createNewLayer(newLayerName); 269 final boolean isDisplayingMapView = Main.isDisplayingMapView(); 270 271 Main.main.addLayer(layer); 272 273 // If the mapView is not there yet, we cannot calculate the bounds (see constructor of MapView). 274 // Otherwise jump to the current download. 275 if (isDisplayingMapView) { 276 computeBboxAndCenterScale(bounds); 277 } 277 Main.main.addLayer(layer, computeBbox(bounds)); 278 278 return layer; 279 279 } -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r6830 r7816 84 84 } 85 85 86 public boolean hasExtend() { 87 return minEast != maxEast || minNorth != maxNorth; 88 } 86 89 } -
trunk/src/org/openstreetmap/josm/data/ViewportData.java
r6992 r7816 5 5 6 6 /** 7 * Simple data class that keeps map center and scale in one object. 7 * Data class to keep viewport information. 8 * 9 * This can be either a combination of map center and map scale or 10 * a rectangle in east-north coordinate space. 11 * 12 * Either of those will be null, so the consumer of the ViewportData 13 * object has to check, which one is set. 14 * 8 15 * @since 5670 (creation) 9 * @since 6992 (extraction in this package) 16 * @since 6992 (extraction in this package) 10 17 */ 11 18 public class ViewportData { 12 private EastNorth center; 13 private Double scale; 19 private final EastNorth center; 20 private final Double scale; 21 22 private final ProjectionBounds bounds; 14 23 15 24 /** … … 21 30 this.center = center; 22 31 this.scale = scale; 32 this.bounds = null; 33 } 34 35 public ViewportData(ProjectionBounds bounds) { 36 this.center = null; 37 this.scale = null; 38 this.bounds = bounds; 23 39 } 24 40 … … 38 54 return scale; 39 55 } 56 57 /** 58 * Return the bounds in east-north coordinate space. 59 * @return the bounds 60 */ 61 public ProjectionBounds getBounds() { 62 return bounds; 63 } 40 64 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r7714 r7816 26 26 import org.openstreetmap.josm.data.Data; 27 27 import org.openstreetmap.josm.data.DataSource; 28 import org.openstreetmap.josm.data.ProjectionBounds; 28 29 import org.openstreetmap.josm.data.SelectionChangedListener; 29 30 import org.openstreetmap.josm.data.coor.EastNorth; … … 39 40 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 40 41 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 42 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 41 43 import org.openstreetmap.josm.data.projection.Projection; 42 44 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; … … 1348 1350 invalidateEastNorthCache(); 1349 1351 } 1352 1353 public ProjectionBounds getDataSourceBoundingBox() { 1354 BoundingXYVisitor bbox = new BoundingXYVisitor(); 1355 for (DataSource source : dataSources) { 1356 bbox.visit(source.bounds); 1357 } 1358 if (bbox.hasExtend()) { 1359 return bbox.getBounds(); 1360 } 1361 return null; 1362 } 1363 1350 1364 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r7509 r7816 85 85 } 86 86 87 public boolean hasExtend() 88 { 89 return bounds != null && !bounds.getMin().equals(bounds.getMax()); 87 public boolean hasExtend() { 88 return bounds != null && bounds.hasExtend(); 90 89 } 91 90 -
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 } -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r7392 r7816 14 14 import org.openstreetmap.josm.actions.ExtensionFileFilter; 15 15 import org.openstreetmap.josm.data.osm.DataSet; 16 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 16 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 18 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 32 33 public static class OsmImporterData { 33 34 34 private OsmDataLayer layer;35 private Runnable postLayerTask;35 private final OsmDataLayer layer; 36 private final Runnable postLayerTask; 36 37 37 38 public OsmImporterData(OsmDataLayer layer, Runnable postLayerTask) { … … 102 103 @Override 103 104 public void run() { 104 Main.main.addLayer(data.layer); 105 data.postLayerTask.run(); 106 data.layer.onPostLoadFromFile(); 105 OsmDataLayer layer = data.getLayer(); 106 BoundingXYVisitor v = new BoundingXYVisitor(); 107 v.visit(layer.data.getDataSourceBoundingBox()); 108 if (!v.hasExtend()) { 109 v.computeBoundingBox(layer.data.getNodes()); 110 } 111 Main.main.addLayer(layer, v.getBounds()); 112 data.getPostLayerTask().run(); 113 data.getLayer().onPostLoadFromFile(); 107 114 } 108 115 });
Note:
See TracChangeset
for help on using the changeset viewer.