| 1 | ### Eclipse Workspace Patch 1.0
|
|---|
| 2 | #P josm
|
|---|
| 3 | Index: src/org/openstreetmap/josm/gui/MapView.java
|
|---|
| 4 | ===================================================================
|
|---|
| 5 | --- src/org/openstreetmap/josm/gui/MapView.java (revision 996)
|
|---|
| 6 | +++ src/org/openstreetmap/josm/gui/MapView.java (working copy)
|
|---|
| 7 | @@ -8,12 +8,11 @@
|
|---|
| 8 | import java.awt.Graphics;
|
|---|
| 9 | import java.awt.Graphics2D;
|
|---|
| 10 | import java.awt.Point;
|
|---|
| 11 | -import java.awt.Transparency;
|
|---|
| 12 | -import java.awt.event.MouseEvent;
|
|---|
| 13 | -import java.awt.event.MouseMotionListener;
|
|---|
| 14 | import java.awt.event.ComponentAdapter;
|
|---|
| 15 | import java.awt.event.ComponentEvent;
|
|---|
| 16 | import java.awt.event.KeyEvent;
|
|---|
| 17 | +import java.awt.event.MouseEvent;
|
|---|
| 18 | +import java.awt.event.MouseMotionListener;
|
|---|
| 19 | import java.awt.image.BufferedImage;
|
|---|
| 20 | import java.util.ArrayList;
|
|---|
| 21 | import java.util.Collection;
|
|---|
| 22 | @@ -28,11 +27,11 @@
|
|---|
| 23 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
|---|
| 24 | import org.openstreetmap.josm.actions.MoveAction;
|
|---|
| 25 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 26 | -import org.openstreetmap.josm.data.Preferences;
|
|---|
| 27 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
|---|
| 28 | import org.openstreetmap.josm.data.coor.EastNorth;
|
|---|
| 29 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 30 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 31 | +import org.openstreetmap.josm.data.osm.DataSource;
|
|---|
| 32 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 33 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
|---|
| 34 | import org.openstreetmap.josm.data.projection.Projection;
|
|---|
| 35 | @@ -105,7 +104,8 @@
|
|---|
| 36 | @Override public void componentResized(ComponentEvent e) {
|
|---|
| 37 | removeComponentListener(this);
|
|---|
| 38 |
|
|---|
| 39 | - new AutoScaleAction("data").actionPerformed(null);
|
|---|
| 40 | + if (!zoomToEditLayerBoundingBox())
|
|---|
| 41 | + new AutoScaleAction("data").actionPerformed(null);
|
|---|
| 42 |
|
|---|
| 43 | new MapMover(MapView.this, Main.contentPane);
|
|---|
| 44 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, java.awt.event.InputEvent.SHIFT_MASK), "UP");
|
|---|
| 45 | @@ -405,6 +405,35 @@
|
|---|
| 46 | if (oldScale != scale)
|
|---|
| 47 | firePropertyChange("scale", oldScale, scale);
|
|---|
| 48 | }
|
|---|
| 49 | +
|
|---|
| 50 | + /**
|
|---|
| 51 | + * Tries to zoom to the download boundingbox[es] of the current edit layer
|
|---|
| 52 | + * (aka {@link OsmDataLayer}). If the edit layer has multiple download bounding
|
|---|
| 53 | + * boxes it zooms to a large virtual bounding box containing all smaller ones.
|
|---|
| 54 | + * This implementation can be used for resolving ticket #1461.
|
|---|
| 55 | + *
|
|---|
| 56 | + * @return <code>true</code> if a zoom operation has been performed
|
|---|
| 57 | + * @author Jan Peter Stotz
|
|---|
| 58 | + */
|
|---|
| 59 | + public boolean zoomToEditLayerBoundingBox() {
|
|---|
| 60 | + // workaround for #1461 (zoom to download bounding box instead of all data)
|
|---|
| 61 | + // In case we already have an existing data layer ...
|
|---|
| 62 | + Collection<DataSource> dataSources = Main.main.editLayer().data.dataSources;
|
|---|
| 63 | + // ... with bounding box[es] of data loaded from OSM or a file...
|
|---|
| 64 | + BoundingXYVisitor bbox = new BoundingXYVisitor();
|
|---|
| 65 | + for (DataSource ds : dataSources) {
|
|---|
| 66 | + if (ds.bounds != null) {
|
|---|
| 67 | + bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.max));
|
|---|
| 68 | + bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.min));
|
|---|
| 69 | + }
|
|---|
| 70 | + if (bbox.max != null && bbox.min != null && !bbox.max.equals(bbox.min)) {
|
|---|
| 71 | + // ... we zoom to it's bounding box
|
|---|
| 72 | + recalculateCenterScale(bbox);
|
|---|
| 73 | + return true;
|
|---|
| 74 | + }
|
|---|
| 75 | + }
|
|---|
| 76 | + return false;
|
|---|
| 77 | + }
|
|---|
| 78 |
|
|---|
| 79 | public boolean addTemporaryLayer(MapViewPaintable mvp) {
|
|---|
| 80 | if (temporaryLayers.contains(mvp)) return false;
|
|---|