Ticket #4413: fix_zoom_level_v2.patch

File fix_zoom_level_v2.patch, 3.7 KB (added by xeen, 12 years ago)

Updated patch with logarithmic scaling. This patch is not final, as I haven’t updated the description or integrated it nicely. Zooming for large objects should be about the same as the old method, while retaining the higer zoom ins for smaller objects. Can you please see how that works for you?

  • 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();
     145        double diffNorth = bounds.getMax().north() - bounds.getMin().north();
     146
     147        double enlargeEast = Math.min(enlargePercent - 10*Math.log(diffEast), 1);
     148        double enlargeNorth = Math.min(enlargePercent - 10*Math.log(diffNorth), 1);
     149
     150        diffEast *= enlargeEast/100;
     151        diffNorth *= enlargeNorth/100;
     152
     153        EastNorth minEnlarge = Main.getProjection().latlon2eastNorth(new LatLon(0, minDegree));
     154        diffEast = Math.max(diffEast, minEnlarge.east());
     155        diffNorth = Math.max(diffNorth, minEnlarge.north());
     156
     157        visit(bounds.getMin().add(-diffEast/2, -diffNorth/2));
     158        visit(bounds.getMax().add(+diffEast/2, +diffNorth/2));
     159    }
     160
     161    /**
     162     * Enlarges the calculated bounding box by the specified percentage. A factor
     163     * of 100 means that the bounding box will be twice as large.
     164     *
     165     * If the bounding box has not been set (<code>min</code> or <code>max</code>
     166     * equal <code>null</code>) this method does not do anything.
     167     *
     168     * @param enlargePercent
     169     */
     170    public void enlargeBoundingBoxByPercent(double enlargePercent) {
     171        enlargeBoundingBoxByPercent(enlargePercent, 0);
     172    }
     173
     174
    125175    @Override public String toString() {
    126176        return "BoundingXYVisitor["+bounds+"]";
    127177    }