Changeset 24530 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-12-02T18:52:49+01:00 (14 years ago)
Author:
upliner
Message:

fix issues with TMS layer shift and attribution displaying

Location:
applications/editors/josm/plugins
Files:
3 edited

Legend:

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

    r24521 r24530  
    1414import java.awt.event.MouseAdapter;
    1515import java.awt.event.MouseEvent;
     16import java.awt.font.TextAttribute;
    1617import java.awt.geom.Rectangle2D;
    1718import java.awt.image.ImageObserver;
     
    2021import java.net.URISyntaxException;
    2122import java.util.ArrayList;
     23import java.util.HashMap;
    2224import java.util.HashSet;
    2325import java.util.LinkedList;
     
    4244import org.openstreetmap.josm.actions.RenameLayerAction;
    4345import org.openstreetmap.josm.data.Bounds;
     46import org.openstreetmap.josm.data.coor.EastNorth;
    4447import org.openstreetmap.josm.data.coor.LatLon;
    4548import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    102105    public int currentZoomLevel;
    103106
    104     LatLon lastTopLeft;
    105     LatLon lastBotRight;
     107    EastNorth lastTopLeft;
     108    EastNorth lastBotRight;
    106109    private Image bufferImage;
    107110    private Tile clickedTile;
     
    114117    private String attrTermsUrl;
    115118    private Rectangle attrImageBounds, attrToUBounds;
    116     private static Font ATTR_FONT = Font.decode("Arial 10");
    117     private static Font ATTR_LINK_FONT = Font.decode("Arial Underline 10");
     119    private static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
     120    private static final Font ATTR_LINK_FONT;
     121    static {
     122        HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>();
     123        aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
     124        ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline);
     125    }
    118126
    119127    protected boolean autoZoom;
     
    479487    void loadAllTiles(boolean force) {
    480488        MapView mv = Main.map.mapView;
    481         LatLon topLeft = mv.getLatLon(0, 0);
    482         LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
     489        EastNorth topLeft = mv.getEastNorth(0, 0);
     490        EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight());
    483491
    484492        TileSet ts = new TileSet(topLeft, botRight, currentZoomLevel);
     
    788796        int tileMax = -1;
    789797
     798        /**
     799         * Create a TileSet by EastNorth bbox taking a layer shift in account
     800         */
     801        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);
     804        }
     805
     806        /**
     807         * Create a TileSet by known LatLon bbox without layer shift correction
     808         */
    790809        TileSet(LatLon topLeft, LatLon botRight, int zoom) {
    791810            this.zoom = zoom;
     811
    792812            z12x0 = lonToTileX(topLeft.lon(),  zoom);
    793813            z12y0 = latToTileY(topLeft.lat(),  zoom);
     
    860880        {
    861881            List<Tile> tiles = this.allTiles(true);
    862             boolean autoload = TMSLayer.this.autoLoad;
    863             if (!autoload && !force)
     882            if (!autoLoad && !force)
    864883               return;
    865884            int nr_queued = 0;
     
    886905    public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    887906        //long start = System.currentTimeMillis();
    888         LatLon topLeft = mv.getLatLon(0, 0);
    889         LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
     907        EastNorth topLeft = mv.getEastNorth(0, 0);
     908        EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight());
    890909        Graphics2D oldg = g;
    891910
    892         if (botRight.lon() == 0.0 || botRight.lat() == 0) {
     911        if (botRight.east() == 0.0 || botRight.north() == 0) {
    893912            Main.debug("still initializing??");
    894913            // probably still initializing
     
    896915        }
    897916
    898         if (lastTopLeft != null && lastBotRight != null && topLeft.equalsEpsilon(lastTopLeft)
    899                 && botRight.equalsEpsilon(lastBotRight) && bufferImage != null
     917        if (lastTopLeft != null && lastBotRight != null && topLeft.equals(lastTopLeft)
     918                && botRight.equals(lastBotRight) && bufferImage != null
    900919                && mv.getWidth() == bufferImage.getWidth(null) && mv.getHeight() == bufferImage.getHeight(null)
    901920                && !needRedraw) {
     
    9901009        if (tileSource.requiresAttribution()) {
    9911010            // Draw attribution
    992             g.setColor(Color.white);
     1011            g.setColor(Color.black);
    9931012            Font font = g.getFont();
    9941013            g.setFont(ATTR_LINK_FONT);
     
    10111030                int x = 2;
    10121031                int height = attrImage.getHeight(this);
    1013                 int y = termsTextY - height;
     1032                int y = termsTextY - height - textHeight - 5;
    10141033                attrImageBounds = new Rectangle(x, y, imgWidth, height);
    10151034                g.drawImage(attrImage, x, y, this);
    10161035            }
    10171036
    1018             String attributionText = tileSource.getAttributionText(currentZoomLevel, topLeft, botRight);
     1037            g.setFont(ATTR_FONT);
     1038            String attributionText = tileSource.getAttributionText(currentZoomLevel,
     1039                    Main.proj.eastNorth2latlon(topLeft), Main.proj.eastNorth2latlon(botRight));
    10191040            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
    10201041            g.drawString(attributionText, mv.getWidth() - (int) stringBounds.getWidth(), mv.getHeight() - textHeight);
     
    10621083        MapView mv = Main.map.mapView;
    10631084        Point clicked = new Point(px, py);
    1064         LatLon topLeft = mv.getLatLon(0, 0);
    1065         LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
     1085        EastNorth topLeft = mv.getEastNorth(0, 0);
     1086        EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight());
    10661087        int z = currentZoomLevel;
    10671088        TileSet ts = new TileSet(topLeft, botRight, z);
  • applications/editors/josm/plugins/imagery/src/org/openstreetmap/josm/plugins/imagery/tms/TMSPreferences.java

    r24521 r24530  
    5959            maxZoomLvl = PROP_MIN_ZOOM_LVL.get();
    6060        }
    61         if (ts != null && ts.getMaxZoom() < PROP_MIN_ZOOM_LVL.get()) {
    62             System.err.println("decreasing maxZoomLvl to match new tile source");
     61        if (ts != null && ts.getMaxZoom() < maxZoomLvl) {
     62            System.err.println("decreasing maxZoomLvl to match tile source");
    6363            maxZoomLvl = ts.getMaxZoom();
    6464        }
     
    8686            minZoomLvl = getMaxZoomLvl(ts);
    8787        }
    88         if (ts != null && ts.getMinZoom() > PROP_MIN_ZOOM_LVL.get()) {
    89             System.err.println("increasomg minZoomLvl to match new tile source");
     88        if (ts != null && ts.getMinZoom() > minZoomLvl) {
     89            System.err.println("increasomg minZoomLvl to match tile source");
    9090            minZoomLvl = ts.getMinZoom();
    9191        }
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java

    r24488 r24530  
    1414import java.awt.event.MouseAdapter;
    1515import java.awt.event.MouseEvent;
     16import java.awt.font.TextAttribute;
    1617import java.awt.geom.Rectangle2D;
    1718import java.awt.image.ImageObserver;
     
    2021import java.net.URISyntaxException;
    2122import java.util.ArrayList;
     23import java.util.HashMap;
    2224import java.util.HashSet;
    2325import java.util.LinkedList;
     
    112114    private String attrTermsUrl;
    113115    private Rectangle attrImageBounds, attrToUBounds;
    114     private static Font ATTR_FONT = Font.decode("Arial 10");
    115     private static Font ATTR_LINK_FONT = Font.decode("Arial Underline 10");
     116    private static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
     117    private static final Font ATTR_LINK_FONT;
     118    static {
     119        HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>();
     120        aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
     121        ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline);
     122    }
    116123
    117124    void redraw()
     
    979986                int x = 2;
    980987                int height = attrImage.getHeight(this);
    981                 int y = termsTextY - height;
     988                int y = termsTextY - height - textHeight - 5;
    982989                attrImageBounds = new Rectangle(x, y, imgWidth, height);
    983990                g.drawImage(attrImage, x, y, this);
    984991            }
    985992           
     993            g.setFont(ATTR_FONT);
    986994            String attributionText = tileSource.getAttributionText(currentZoomLevel, topLeft, botRight);
    987995            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
Note: See TracChangeset for help on using the changeset viewer.