Ticket #4413: fix_zoom_level.patch

File fix_zoom_level.patch, 3.5 KB (added by xeen, 10 years ago)

v1

  • src/org/openstreetmap/josm/actions/AutoScaleAction.java

     
    238238            for (OsmPrimitive osm : sel) {
    239239                osm.accept(v);
    240240            }
    241             // increase bbox by 0.001 degrees on each side. this is required
    242             // especially if the bbox contains one single node, but helpful
    243             // in most other cases as well.
    244             v.enlargeBoundingBox();
     241
     242            // Increase the bounding box by 100% to give more context. Make the bounding box
     243            // at least 0.0007 degrees wide to ensure reasonable zoom level when zooming onto
     244            // single nodes.
     245            v.enlargeBoundingBoxByPercent(100, 0.0007);
    245246        }
    246247        else if (mode.equals("download")) {
    247248            Bounds bounds = DownloadDialog.getSavedDownloadBounds();
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

     
    122122                Main.getProjection().latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree)));
    123123    }
    124124
     125    /**
     126     * Enlarges the calculated bounding box by the specified percentage. A factor
     127     * of 100 means that the bounding box will be twice as large.
     128     *
     129     * Specify a degree larger than 0 in order to make the bounding box at least
     130     * the specified amount of degrees high and wide. The minimum is applied after
     131     * enlarging the bounding box by percentage. The value is ignored if the
     132     * bounding box is already larger than the specified amount.
     133     *
     134     * If the bounding box has not been set (<code>min</code> or <code>max</code>
     135     * equal <code>null</code>) this method does not do anything.
     136     *
     137     * @param enlargePercent
     138     * @param minEnlargeEastNorth
     139     */
     140    public void enlargeBoundingBoxByPercent(double enlargePercent, double minDegree) {
     141        if (bounds == null)
     142            return;
     143
     144        double diffEast = (bounds.getMax().east() - bounds.getMin().east()) * enlargePercent/100;
     145        double diffNorth = (bounds.getMax().north() - bounds.getMin().north()) * enlargePercent/100;
     146
     147        EastNorth minEnlarge = Main.getProjection().latlon2eastNorth(new LatLon(0, minDegree));
     148        diffEast = Math.max(diffEast, minEnlarge.east());
     149        diffNorth = Math.max(diffNorth, minEnlarge.north());
     150
     151        visit(bounds.getMin().add(-diffEast/2, -diffNorth/2));
     152        visit(bounds.getMax().add(+diffEast/2, +diffNorth/2));
     153    }
     154
     155    /**
     156     * Enlarges the calculated bounding box by the specified percentage. A factor
     157     * of 100 means that the bounding box will be twice as large.
     158     *
     159     * If the bounding box has not been set (<code>min</code> or <code>max</code>
     160     * equal <code>null</code>) this method does not do anything.
     161     *
     162     * @param enlargePercent
     163     */
     164    public void enlargeBoundingBoxByPercent(double enlargePercent) {
     165        enlargeBoundingBoxByPercent(enlargePercent, 0);
     166    }
     167
     168
    125169    @Override public String toString() {
    126170        return "BoundingXYVisitor["+bounds+"]";
    127171    }