Changeset 1022 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2008-10-05T16:39:49+02:00 (16 years ago)
Author:
stoecker
Message:

close bug #1461 - initial zoom to download area

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r999 r1022  
    3232import org.openstreetmap.josm.data.coor.LatLon;
    3333import org.openstreetmap.josm.data.osm.DataSet;
     34import org.openstreetmap.josm.data.osm.DataSource;
    3435import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3536import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    104105                                removeComponentListener(this);
    105106
    106                                 new AutoScaleAction("data").actionPerformed(null);
     107                                if (!zoomToEditLayerBoundingBox())
     108                                        new AutoScaleAction("data").actionPerformed(null);
    107109
    108110                                new MapMover(MapView.this, Main.contentPane);
     
    404406                        firePropertyChange("scale", oldScale, scale);
    405407        }
     408
     409        /**
     410         * Tries to zoom to the download boundingbox[es] of the current edit layer
     411         * (aka {@link OsmDataLayer}). If the edit layer has multiple download bounding
     412         * boxes it zooms to a large virtual bounding box containing all smaller ones.
     413         * This implementation can be used for resolving ticket #1461.
     414         *
     415         * @return <code>true</code> if a zoom operation has been performed
     416         * @author Jan Peter Stotz
     417         */
     418        public boolean zoomToEditLayerBoundingBox() {
     419                // workaround for #1461 (zoom to download bounding box instead of all data)
     420                // In case we already have an existing data layer ...
     421                Collection<DataSource> dataSources = Main.main.editLayer().data.dataSources;
     422                // ... with bounding box[es] of data loaded from OSM or a file...
     423                BoundingXYVisitor bbox = new BoundingXYVisitor();
     424                for (DataSource ds : dataSources) {
     425                        if (ds.bounds != null) {
     426                                bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.max));
     427                                bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.min));
     428                        }
     429                        if (bbox.max != null && bbox.min != null && !bbox.max.equals(bbox.min)) {
     430                                // ... we zoom to it's bounding box
     431                                recalculateCenterScale(bbox);
     432                                return true;
     433                        }
     434                }
     435                return false;
     436        }
    406437       
    407438        public boolean addTemporaryLayer(MapViewPaintable mvp) {
Note: See TracChangeset for help on using the changeset viewer.