Ignore:
Timestamp:
2010-12-02T23:27:32+01:00 (14 years ago)
Author:
upliner
Message:

add TMS zoomlevel detection

Location:
applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/ImageryLayer.java

    r24536 r24541  
    66import javax.swing.ImageIcon;
    77
     8import org.openstreetmap.josm.Main;
    89import org.openstreetmap.josm.data.ProjectionBounds;
    910import org.openstreetmap.josm.gui.MapView;
     
    2324    public ImageryLayer(String name) {
    2425        super(name);
     26        mv = Main.map.mapView;
    2527    }
    2628
  • applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSLayer.java

    r24537 r24541  
    5353import org.openstreetmap.josm.gui.layer.Layer;
    5454import org.openstreetmap.josm.plugins.imagery.ImageryInfo;
     55import org.openstreetmap.josm.plugins.imagery.ImageryLayer;
    5556import org.openstreetmap.josm.plugins.imagery.ImageryInfo.ImageryType;
    56 import org.openstreetmap.josm.plugins.imagery.ImageryLayer;
    5757
    5858/**
     
    134134    }
    135135
    136     private void setTileStorage(TileSource tileSource)
    137     {
    138         int origZoom = currentZoomLevel;
     136    private void initTileSource(TileSource tileSource)
     137    {
    139138        this.tileSource = tileSource;
    140139        boolean requireAttr = tileSource.requiresAttribution();
     
    150149        }
    151150
    152         // The minimum should also take care of integer parsing
    153         // errors which would leave us with a zoom of -1 otherwise
     151        currentZoomLevel = getBestZoom();
    154152        if (tileSource.getMaxZoom() < currentZoomLevel)
    155153            currentZoomLevel = tileSource.getMaxZoom();
    156154        if (tileSource.getMinZoom() > currentZoomLevel)
    157155            currentZoomLevel = tileSource.getMinZoom();
    158         if (currentZoomLevel != origZoom) {
    159             out("changed currentZoomLevel loading new tile store from " + origZoom + " to " + currentZoomLevel);
    160             out("tileSource.getMinZoom(): " + tileSource.getMinZoom());
    161             out("tileSource.getMaxZoom(): " + tileSource.getMaxZoom());
    162         }
    163156        clearTileCache();
    164157        //tileloader = new OsmTileLoader(this);
     
    172165    }
    173166
     167    private double getPPDeg() {
     168        return mv.getWidth()/(mv.getLatLon(mv.getWidth(), mv.getHeight()/2).lon()-mv.getLatLon(0, mv.getHeight()/2).lon());
     169    }
     170
     171    private int getBestZoom() {
     172        double ret = Math.log(getPPDeg()*360/tileSource.getTileSize())/Math.log(2);
     173        System.out.println("Detected best zoom " + ret);
     174        return (int)Math.round(ret);
     175    }
     176
    174177    @SuppressWarnings("serial")
    175178    public TMSLayer(ImageryInfo info) {
     
    179182        this.setVisible(true);
    180183
    181         currentZoomLevel = TMSPreferences.getMinZoomLvl(null); //FIXME: detect current zoom level
    182 
    183184        if (info.getImageryType() == ImageryType.TMS) {
    184             setTileStorage(new TMSTileSource(info.getName(),info.getURL()));
     185            initTileSource(new TMSTileSource(info.getName(),info.getURL()));
    185186        } else if (info.getImageryType() == ImageryType.BING) {
    186             setTileStorage(new BingAerialTileSource());
     187            initTileSource(new BingAerialTileSource());
    187188        } else throw new AssertionError();
    188189
    189190        tileOptionMenu = new JPopupMenu();
    190 
    191191
    192192        autoZoom = TMSPreferences.PROP_DEFAULT_AUTOZOOM.get();
     
    783783    }
    784784
    785     public Point pixelPos(LatLon ll) {
     785    private Point pixelPos(LatLon ll) {
    786786        return Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(ll).add(getDx(), getDy()));
    787787    }
    788     public Point pixelPos(Tile t) {
     788    private Point pixelPos(Tile t) {
    789789        double lon = tileXToLon(t.getXtile(), t.getZoom());
    790790        LatLon tmpLL = new LatLon(tileYToLat(t.getYtile(), t.getZoom()), lon);
    791791        return pixelPos(tmpLL);
     792    }
     793    private LatLon getShiftedLatLon(EastNorth en) {
     794        return Main.proj.eastNorth2latlon(en.add(-getDx(), -getDy()));
    792795    }
    793796    private class TileSet {
     
    800803         */
    801804        TileSet(EastNorth topLeft, EastNorth botRight, int zoom) {
    802             this(Main.proj.eastNorth2latlon(topLeft.add(-getDx(), -getDy())),
    803                  Main.proj.eastNorth2latlon(botRight.add(-getDx(), -getDy())),zoom);
     805            this(getShiftedLatLon(topLeft), getShiftedLatLon(botRight),zoom);
    804806        }
    805807
     
    10391041            g.setFont(ATTR_FONT);
    10401042            String attributionText = tileSource.getAttributionText(currentZoomLevel,
    1041                     Main.proj.eastNorth2latlon(topLeft), Main.proj.eastNorth2latlon(botRight));
     1043                    getShiftedLatLon(topLeft), getShiftedLatLon(botRight));
    10421044            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
    10431045            {
  • applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/wms/WMSLayer.java

    r24501 r24541  
    105105        initializeImages();
    106106        this.info = new ImageryInfo(info);
    107         mv = Main.map.mapView;
    108107        if(this.info.getPixelPerDegree() == 0.0)
    109108            this.info.setPixelPerDegree(getPPD());
Note: See TracChangeset for help on using the changeset viewer.