Changeset 7817 in josm


Ignore:
Timestamp:
2014-12-17T13:46:53+01:00 (9 years ago)
Author:
bastiK
Message:

fixed #10861 - Zoom to layer when opening new file (see #10860)

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

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

    r7816 r7817  
    700700     * @param layer the layer
    701701     *
    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)
     702     * @see #addLayer(Layer, ProjectionBounds)
     703     * @see #addLayer(Layer, ViewportData)
    704704     */
    705705    public final void addLayer(final Layer layer) {
     
    715715     *
    716716     * @param layer the layer
    717      * @param bounds the bounds of the layer (target zoom area)
     717     * @param bounds the bounds of the layer (target zoom area); can be null, then
     718     * the viewport isn't changed
    718719     */
    719720    public final synchronized void addLayer(final Layer layer, ProjectionBounds bounds) {
    720         addLayer(layer, new ViewportData(bounds));
     721        addLayer(layer, bounds == null ? null : new ViewportData(bounds));
    721722    }
    722723
     
    727728     *
    728729     * @param layer the layer
    729      * @param viewport the viewport to zoom to
     730     * @param viewport the viewport to zoom to; can be null, then the viewport
     731     * isn't changed
    730732     */
    731733    public final synchronized void addLayer(final Layer layer, ViewportData viewport) {
     
    738740        if (noMap) {
    739741            Main.map.setVisible(true);
     742        } else if (viewport != null) {
     743            Main.map.mapView.zoomTo(viewport);
    740744        }
    741745    }
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r7668 r7817  
    8585        bboxCalculator.enlargeBoundingBox();
    8686        if (bboxCalculator.getBounds() != null) {
    87             Main.map.mapView.recalculateCenterScale(bboxCalculator);
     87            Main.map.mapView.zoomTo(bboxCalculator);
    8888        }
    8989    }
     
    174174                BoundingXYVisitor bbox = getBoundingBox();
    175175                if (bbox != null && bbox.getBounds() != null) {
    176                     Main.map.mapView.recalculateCenterScale(bbox);
     176                    Main.map.mapView.zoomTo(bbox);
    177177                }
    178178            }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r7816 r7817  
    265265            BoundingXYVisitor v = new BoundingXYVisitor();
    266266            v.visit(pb);
    267             Main.map.mapView.recalculateCenterScale(v);
     267            Main.map.mapView.zoomTo(v);
    268268        }
    269269
  • trunk/src/org/openstreetmap/josm/data/ViewportData.java

    r7816 r7817  
    33
    44import org.openstreetmap.josm.data.coor.EastNorth;
     5import org.openstreetmap.josm.tools.CheckParameterUtil;
    56
    67/**
     
    2829     */
    2930    public ViewportData(EastNorth center, Double scale) {
     31        CheckParameterUtil.ensureParameterNotNull(center);
     32        CheckParameterUtil.ensureParameterNotNull(scale);
    3033        this.center = center;
    3134        this.scale = scale;
     
    3437
    3538    public ViewportData(ProjectionBounds bounds) {
     39        CheckParameterUtil.ensureParameterNotNull(bounds);
    3640        this.center = null;
    3741        this.scale = null;
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r7816 r7817  
    529529    @Override public void paint(Graphics g) {
    530530        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             }
     531            zoomTo(initialViewport);
    538532            initialViewport = null;
    539533        }
     
    693687    /**
    694688     * Set the new dimension to the view.
    695      */
     689     *
     690     * @deprecated use #zoomTo(BoundingXYVisitor)
     691     */
     692    @Deprecated
    696693    public void recalculateCenterScale(BoundingXYVisitor box) {
    697         if (box == null) {
    698             box = new BoundingXYVisitor();
    699         }
    700         if (box.getBounds() == null) {
    701             box.visit(getProjection().getWorldBoundsLatLon());
    702         }
    703         if (!box.hasExtend()) {
    704             box.enlargeBoundingBox();
    705         }
    706 
    707         zoomTo(box.getBounds());
     694        zoomTo(box);
    708695    }
    709696
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r7816 r7817  
    4343import org.openstreetmap.josm.data.osm.Way;
    4444import org.openstreetmap.josm.data.osm.WaySegment;
     45import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4546import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    4647import org.openstreetmap.josm.data.preferences.IntegerProperty;
     
    580581        zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.getMin()),
    581582                getProjection().latlon2eastNorth(box.getMax())));
     583    }
     584
     585    public void zoomTo(ViewportData viewport) {
     586        if (viewport == null) return;
     587        if (viewport.getBounds() != null) {
     588            BoundingXYVisitor box = new BoundingXYVisitor();
     589            box.visit(viewport.getBounds());
     590            zoomTo(box);
     591        } else {
     592            zoomTo(viewport.getCenter(), viewport.getScale(), true);
     593        }
     594    }
     595
     596    /**
     597     * Set the new dimension to the view.
     598     */
     599    public void zoomTo(BoundingXYVisitor box) {
     600        if (box == null) {
     601            box = new BoundingXYVisitor();
     602        }
     603        if (box.getBounds() == null) {
     604            box.visit(getProjection().getWorldBoundsLatLon());
     605        }
     606        if (!box.hasExtend()) {
     607            box.enlargeBoundingBox();
     608        }
     609
     610        zoomTo(box.getBounds());
    582611    }
    583612
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r7781 r7817  
    451451                return;
    452452            box.enlargeBoundingBox();
    453             Main.map.mapView.recalculateCenterScale(box);
     453            Main.map.mapView.zoomTo(box);
    454454        }
    455455
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r7578 r7817  
    746746                        BoundingXYVisitor bbox = new BoundingXYVisitor();
    747747                        yLayer.visitBoundingBox(bbox);
    748                         Main.map.mapView.recalculateCenterScale(bbox);
     748                        Main.map.mapView.zoomTo(bbox);
    749749                    }
    750750
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r7521 r7817  
    244244                    BoundingXYVisitor bbox1 = new BoundingXYVisitor();
    245245                    bbox1.visit(bbox);
    246                     Main.map.mapView.recalculateCenterScale(bbox1);
     246                    Main.map.mapView.zoomTo(bbox1);
    247247                }
    248248            });
Note: See TracChangeset for help on using the changeset viewer.