Ignore:
Timestamp:
2011-02-12T17:40:58+01:00 (13 years ago)
Author:
upliner
Message:

ext_tools: add {TZoom} token for TMS zoom

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ext_tools/src/ext_tools/ExtTool.java

    r23327 r25274  
    2828import org.openstreetmap.josm.gui.JMultilineLabel;
    2929import org.openstreetmap.josm.gui.MainMenu;
     30import org.openstreetmap.josm.gui.MapView;
    3031import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3132import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     
    116117    }
    117118
     119    private double latToTileY(double lat, int zoom) {
     120        double l = lat / 180 * Math.PI;
     121        double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));
     122        return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI;
     123    }
     124
     125    private double lonToTileX(double lon, int zoom) {
     126        return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;
     127    }
     128
     129    private double getTMSZoom() {
     130        if (Main.map == null || Main.map.mapView == null) return 1;
     131        MapView mv = Main.map.mapView;
     132        LatLon topLeft = mv.getLatLon(0, 0);
     133        LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
     134        double x1 = lonToTileX(topLeft.lon(), 1);
     135        double y1 = latToTileY(topLeft.lat(), 1);
     136        double x2 = lonToTileX(botRight.lon(), 1);
     137        double y2 = latToTileY(botRight.lat(), 1);
     138
     139        int screenPixels = mv.getWidth()*mv.getHeight();
     140        double tilePixels = Math.abs((y2-y1)*(x2-x1)*65536);
     141        if (screenPixels == 0 || tilePixels == 0) return 1;
     142        return Math.log(screenPixels/tilePixels)/Math.log(2)/2+1;
     143    }
     144
    118145    protected void showErrorMessage(String message, String details) {
    119146        final JPanel p = new JPanel(new GridBagLayout());
     
    140167        replace.put("{lon}", "" + pos.lon());
    141168        replace.put("{PPD}", "" + getPPD());
     169        replace.put("{TZoom}", "" + getTMSZoom());
    142170
    143171        ArrayList<String> cmdParams = new ArrayList<String>();
Note: See TracChangeset for help on using the changeset viewer.