Changeset 24488 in osm for applications


Ignore:
Timestamp:
2010-12-01T06:06:51+01:00 (14 years ago)
Author:
yellowbkpk
Message:

Adding the terms of use text and link support.

Location:
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java

    r24487 r24488  
    1414import java.awt.event.MouseAdapter;
    1515import java.awt.event.MouseEvent;
     16import java.awt.geom.Rectangle2D;
    1617import java.awt.image.ImageObserver;
    1718import java.io.IOException;
     
    109110    Tile showMetadataTile;
    110111    private Image attrImage;
    111     private Rectangle attrImageBounds;
    112     private Font attrFont = Font.decode("Arial-10");
     112    private String attrTermsUrl;
     113    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");
    113116
    114117    void redraw()
     
    130133                System.out.println("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this));
    131134            }
     135           
     136            attrTermsUrl = tileSource.getTermsOfUseURL();
    132137        }
    133138       
     
    264269                            tileOptionMenu.show(e.getComponent(), e.getX(), e.getY());
    265270                        } else if (e.getButton() == MouseEvent.BUTTON1) {
    266                             if(attrImageBounds.contains(e.getPoint()) && tileSource.requiresAttribution()) {
     271                            if(!tileSource.requiresAttribution()) {
     272                                return;
     273                            }
     274                           
     275                            if(attrImageBounds.contains(e.getPoint())) {
    267276                                try {
    268277                                    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    269278                                    desktop.browse(new URI(tileSource.getAttributionLinkURL()));
     279                                } catch (IOException e1) {
     280                                    e1.printStackTrace();
     281                                } catch (URISyntaxException e1) {
     282                                    e1.printStackTrace();
     283                                }
     284                            } else if(attrToUBounds.contains(e.getPoint())) {
     285                                try {
     286                                    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
     287                                    desktop.browse(new URI(tileSource.getTermsOfUseURL()));
    270288                                } catch (IOException e1) {
    271289                                    e1.printStackTrace();
     
    942960            g.setColor(Color.white);
    943961            Font font = g.getFont();
    944             g.setFont(attrFont);
    945             g.drawString(tileSource.getAttributionText(currentZoomLevel, topLeft, botRight), 5 + attrImage.getWidth(this) + 2, mv.getHeight() - 5);
    946             g.setFont(font);
     962            g.setFont(ATTR_LINK_FONT);
     963           
     964            // Draw terms of use text
     965            Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g);
     966            int textHeight = (int) termsStringBounds.getHeight() - 5;
     967            int textWidth = (int) termsStringBounds.getWidth();
     968            int termsTextY = mv.getHeight() - textHeight;
     969            if(attrTermsUrl != null) {
     970                int x = 2;
     971                int y = mv.getHeight() - textHeight;
     972                attrToUBounds = new Rectangle(x, y, textWidth, textHeight);
     973                g.drawString("Background Terms of Use", x, y);
     974            }
    947975           
    948976            // Draw attribution logo
     977            int imgWidth = attrImage.getWidth(this);
    949978            if(attrImage != null) {
    950                 int x = 5;
    951                 int y = mv.getHeight() - attrImage.getHeight(this) - 5;
    952                 attrImageBounds = new Rectangle(x, y, attrImage.getWidth(this), attrImage.getHeight(this));
     979                int x = 2;
     980                int height = attrImage.getHeight(this);
     981                int y = termsTextY - height;
     982                attrImageBounds = new Rectangle(x, y, imgWidth, height);
    953983                g.drawImage(attrImage, x, y, this);
    954984            }
     985           
     986            String attributionText = tileSource.getAttributionText(currentZoomLevel, topLeft, botRight);
     987            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
     988            g.drawString(attributionText, mv.getWidth() - (int) stringBounds.getWidth(), mv.getHeight() - textHeight);
     989           
     990            g.setFont(font);
    955991        }
    956992
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java

    r24487 r24488  
    410410        }
    411411       
     412        public String getTermsOfUseURL() {
     413            return "http://opengeodata.org/microsoft-imagery-details";
     414        }
     415       
    412416        public String getAttributionText(int zoom, LatLon topLeft, LatLon botRight) {
    413417            Bounds windowBounds = new Bounds(topLeft, botRight);
Note: See TracChangeset for help on using the changeset viewer.