Ignore:
Timestamp:
2011-10-07T18:51:36+02:00 (13 years ago)
Author:
bastik
Message:

more options to configure imagery attribution (logo-url & terms-of-use-text)

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java

    r26783 r26793  
    22
    33//License: GPL.
     4
     5import static org.openstreetmap.gui.jmapviewer.FeatureAdapter.tr;
    46
    57import java.awt.Color;
     
    2123
    2224    private Image attrImage;
     25    private String attrTermsText;
    2326    private String attrTermsUrl;
    2427    public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
    2528    public static final Font ATTR_LINK_FONT;
     29   
     30    private static final String DEFAULT_TERMS_OF_USE_TEXT = tr("Background Terms of Use");
    2631
    2732    protected Rectangle attrTextBounds = null;
     
    4045        if (requireAttr) {
    4146            attrImage = tileSource.getAttributionImage();
     47            attrTermsText = tileSource.getTermsOfUseText();
    4248            attrTermsUrl = tileSource.getTermsOfUseURL();
     49            if (attrTermsUrl != null && attrTermsText == null) {
     50                attrTermsText = DEFAULT_TERMS_OF_USE_TEXT;
     51            }
    4352        } else {
    4453            attrImage = null;
     
    4857
    4958    public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) {
    50         if (!tileSource.requiresAttribution())
     59        if (tileSource == null || !tileSource.requiresAttribution())
    5160            return;
    5261        // Draw attribution
     
    5564
    5665        // Draw terms of use text
    57         Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g);
    58         int textRealHeight = (int) termsStringBounds.getHeight();
    59         int textHeight = textRealHeight - 5;
    60         int textWidth = (int) termsStringBounds.getWidth();
    61         int termsTextY = height - textHeight;
    62         if (attrTermsUrl != null) {
     66        int termsTextHeight = 0;
     67        int termsTextY = height;
     68
     69        if (attrTermsText != null) {
     70            Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g);
     71            int textRealHeight = (int) termsStringBounds.getHeight();
     72            termsTextHeight = textRealHeight - 5;
     73            int termsTextWidth = (int) termsStringBounds.getWidth();
     74            termsTextY = height - termsTextHeight;
    6375            int x = 2;
    64             int y = height - textHeight;
    65             attrToUBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight);
     76            int y = height - termsTextHeight;
     77            attrToUBounds = new Rectangle(x, y-termsTextHeight, termsTextWidth, textRealHeight);
    6678            g.setColor(Color.black);
    67             g.drawString("Background Terms of Use", x + 1, y + 1);
     79            g.drawString(attrTermsText, x + 1, y + 1);
    6880            g.setColor(Color.white);
    69             g.drawString("Background Terms of Use", x, y);
     81            g.drawString(attrTermsText, x, y);
    7082        }
    7183
     
    7587            int imgWidth = attrImage.getWidth(observer);
    7688            int imgHeight = attrImage.getHeight(observer);
    77             int y = termsTextY - imgHeight - textHeight - 5;
     89            int y = termsTextY - imgHeight - termsTextHeight - 5;
    7890            attrImageBounds = new Rectangle(x, y, imgWidth, imgHeight);
    7991            g.drawImage(attrImage, x, y, null);
     
    8496        if (attributionText != null) {
    8597            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
     98            int textHeight = (int) stringBounds.getHeight() - 5;
    8699            int x = width - (int) stringBounds.getWidth();
    87100            int y = height - textHeight;
     
    90103            g.setColor(Color.white);
    91104            g.drawString(attributionText, x, y);
    92             attrTextBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight);
     105            attrTextBounds = new Rectangle(x, y-textHeight, (int) stringBounds.getWidth(), (int) stringBounds.getHeight());
    93106        }
    94107
     
    97110
    98111    public boolean handleAttribution(Point p, boolean click) {
    99         if (!tileSource.requiresAttribution())
     112        if (tileSource == null || !tileSource.requiresAttribution())
    100113            return false;
    101114
    102115        /* TODO: Somehow indicate the link is clickable state to user */
    103116
    104         if ((attrImageBounds != null && attrImageBounds.contains(p))
    105                 || (attrTextBounds != null && attrTextBounds.contains(p))) {
    106             if (click) {
    107                 FeatureAdapter.openLink(tileSource.getAttributionLinkURL());
     117        if (attrTextBounds != null && attrTextBounds.contains(p)) {
     118            String attributionURL = tileSource.getAttributionLinkURL();
     119            if (attributionURL != null) {
     120                if (click) {
     121                    FeatureAdapter.openLink(attributionURL);
     122                }
     123                return true;
    108124            }
    109             return true;
     125        } else if (attrImageBounds != null && attrImageBounds.contains(p)) {
     126            String attributionImageURL = tileSource.getAttributionImageURL();
     127            if (attributionImageURL != null) {
     128                if (click) {
     129                    FeatureAdapter.openLink(tileSource.getAttributionImageURL());
     130                }
     131                return true;
     132            }
    110133        } else if (attrToUBounds != null && attrToUBounds.contains(p)) {
    111             if (click) {
    112                 FeatureAdapter.openLink(tileSource.getTermsOfUseURL());
     134            String termsOfUseURL = tileSource.getTermsOfUseURL();
     135            if (termsOfUseURL != null) {
     136                if (click) {
     137                    FeatureAdapter.openLink(termsOfUseURL);
     138                }
     139                return true;
    113140            }
    114             return true;
    115141        }
    116142        return false;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r25369 r26793  
    4848     *         {@link JMapViewer#MAX_ZOOM}
    4949     */
    50     public int getMaxZoom();
     50    int getMaxZoom();
    5151
    5252    /**
     
    5757     * @return minimum zoom value - usually 0
    5858     */
    59     public int getMinZoom();
     59    int getMinZoom();
    6060
    6161    /**
     
    6363     * @see TileUpdate
    6464     */
    65     public TileUpdate getTileUpdate();
     65    TileUpdate getTileUpdate();
    6666
    6767    /**
     
    7171     * @return Name of the tile layer
    7272     */
    73     public String getName();
     73    String getName();
    7474
    7575    /**
     
    8181     * @return fully qualified url for downloading the specified tile image
    8282     */
    83     public String getTileUrl(int zoom, int tilex, int tiley) throws IOException;
     83    String getTileUrl(int zoom, int tilex, int tiley) throws IOException;
    8484
    8585    /**
     
    8989     * @return file extension of the tile image type
    9090     */
    91     public String getTileType();
     91    String getTileType();
    9292
    9393    /**
     
    9595     * @return The size of a single tile in pixels.
    9696     */
    97     public int getTileSize();
     97    int getTileSize();
    9898
    9999    /**
    100100     * @return True if the tile source requires attribution in text or image form.
    101101     */
    102     public boolean requiresAttribution();
     102    boolean requiresAttribution();
    103103
    104104    /**
     
    108108     * @return Attribution text for the image source.
    109109     */
    110     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight);
     110    String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight);
     111
     112    /**
     113     * @return The URL to open when the user clicks the attribution text.
     114     */
     115    String getAttributionLinkURL();
    111116
    112117    /**
    113118     * @return The URL for the attribution image. Null if no image should be displayed.
    114119     */
    115     public Image getAttributionImage();
     120    Image getAttributionImage();
    116121
    117122    /**
    118123     * @return The URL to open when the user clicks the attribution image.
     124     * When return value is null, the image is still displayed (provided getAttributionImage()
     125     * returns a value other than null), but the image does not link to a website.
    119126     */
    120     public String getAttributionLinkURL();
     127    String getAttributionImageURL();
     128
     129    /**
     130     * @return The attribution "Terms of Use" text.
     131     * In case it returns null, but getTermsOfUseURL() is not null, a default
     132     * terms of use text is used.
     133     */
     134    String getTermsOfUseText();
    121135
    122136    /**
    123137     * @return The URL to open when the user clicks the attribution "Terms of Use" text.
    124138     */
    125     public String getTermsOfUseURL();
     139    String getTermsOfUseURL();
    126140
    127     public double latToTileY(double lat, int zoom);
     141    double latToTileY(double lat, int zoom);
    128142
    129     public double lonToTileX(double lon, int zoom);
     143    double lonToTileX(double lon, int zoom);
    130144
    131     public double tileYToLat(int y, int zoom);
     145    double tileYToLat(int y, int zoom);
    132146
    133     public double tileXToLon(int x, int zoom);
     147    double tileXToLon(int x, int zoom);
    134148}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java

    r26253 r26793  
    4040
    4141    @Override
     42    public Image getAttributionImage() {
     43        return null;
     44    }
     45
     46    @Override
     47    public String getAttributionImageURL() {
     48        return null;
     49    }
     50
     51    @Override
     52    public String getTermsOfUseText() {
     53        return null;
     54    }
     55
     56    @Override
    4257    public String getTermsOfUseURL() {
    4358        return "http://www.openstreetmap.org/copyright";
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTSMTileSource.java

    r26249 r26793  
    3131    }
    3232
     33    @Override
    3334    public String getName() {
    3435        return name;
    3536    }
    3637
     38    @Override
    3739    public int getMaxZoom() {
    3840        return 21;
    3941    }
    4042
     43    @Override
    4144    public int getMinZoom() {
    4245        return 0;
     
    5861    }
    5962
     63    @Override
    6064    public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
    6165        return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
     
    6771    }
    6872
     73    @Override
    6974    public String getTileType() {
    7075        return "png";
    7176    }
    7277
     78    @Override
    7379    public int getTileSize() {
    7480        return 256;
    7581    }
    7682
     83    @Override
     84    public boolean requiresAttribution() {
     85        return false;
     86    }
     87
     88    @Override
     89    public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     90        throw new UnsupportedOperationException("no attribution");
     91    }
     92
     93    @Override
     94    public String getAttributionLinkURL() {
     95        throw new UnsupportedOperationException("no attribution");
     96    }
     97
     98    @Override
    7799    public Image getAttributionImage() {
    78100        if (attrImgUrl != null)
    79101            return new ImageIcon(attrImgUrl).getImage();
     102
    80103        else
    81104            return null;
    82105    }
    83106
    84     public boolean requiresAttribution() {
    85         return false;
    86     }
    87 
    88     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
     107    @Override
     108    public String getAttributionImageURL() {
    89109        throw new UnsupportedOperationException("no attribution");
    90110    }
    91111
    92     public String getAttributionLinkURL() {
     112    @Override
     113    public String getTermsOfUseText() {
    93114        throw new UnsupportedOperationException("no attribution");
    94115    }
    95116
     117    @Override
    96118    public String getTermsOfUseURL() {
    97119        throw new UnsupportedOperationException("no attribution");
    98120    }
    99121
     122    @Override
    100123    public double latToTileY(double lat, int zoom) {
    101124        double l = lat / 180 * Math.PI;
     
    104127    }
    105128
     129    @Override
    106130    public double lonToTileX(double lon, int zoom) {
    107131        return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;
    108132    }
    109133
     134    @Override
    110135    public double tileYToLat(int y, int zoom) {
    111136        return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, zoom - 1)))) * 180 / Math.PI;
    112137    }
    113138
     139    @Override
    114140    public double tileXToLon(int x, int zoom) {
    115141        return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r26249 r26793  
    11package org.openstreetmap.gui.jmapviewer.tilesources;
     2
     3//License: GPL.
    24
    35import java.awt.Image;
     
    177179
    178180    @Override
     181    public String getAttributionLinkURL() {
     182        //return "http://bing.com/maps"
     183        // FIXME: I've set attributionLinkURL temporarily to ToU URL to comply with bing ToU
     184        // (the requirement is that we have such a link at the bottom of the window)
     185        return "http://go.microsoft.com/?linkid=9710837";
     186    }
     187
     188    @Override
    179189    public Image getAttributionImage() {
    180190        try {
     
    186196
    187197    @Override
    188     public String getAttributionLinkURL() {
    189         //return "http://bing.com/maps"
    190         // FIXME: I've set attributionLinkURL temporarily to ToU URL to comply with bing ToU
    191         // (the requirement is that we have such a link at the bottom of the window)
    192         return "http://go.microsoft.com/?linkid=9710837";
     198    public String getAttributionImageURL() {
     199        return "http://opengeodata.org/microsoft-imagery-details";
     200    }
     201
     202    @Override
     203    public String getTermsOfUseText() {
     204        return null;
    193205    }
    194206
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

    r26253 r26793  
    11package org.openstreetmap.gui.jmapviewer.tilesources;
     2
     3//License: GPL.
    24
    35import java.awt.Image;
     
    911    protected int minZoom = 0;
    1012    protected String attributionText;
     13    protected String attributionLinkURL;
    1114    protected Image attributionImage;
    12     protected String attributionLinkURL;
     15    protected String attributionImageURL;
     16    protected String termsOfUseText;
    1317    protected String termsOfUseURL;
    1418
     
    4953
    5054    @Override
     55    public String getAttributionLinkURL() {
     56        return attributionLinkURL;
     57    }
     58
     59    @Override
    5160    public Image getAttributionImage() {
    5261        return attributionImage;
     
    5463
    5564    @Override
    56     public String getAttributionLinkURL() {
    57         return attributionLinkURL;
     65    public String getAttributionImageURL() {
     66        return attributionImageURL;
     67    }
     68
     69    @Override
     70    public String getTermsOfUseText() {
     71        return termsOfUseText;
    5872    }
    5973
     
    6781    }
    6882
     83    public void setAttributionLinkURL(String text) {
     84        attributionLinkURL = text;
     85    }
     86
    6987    public void setAttributionImage(Image img) {
    7088        attributionImage = img;
    7189    }
    7290
    73     public void setAttributionLinkURL(String text) {
    74         attributionLinkURL = text;
     91    public void setAttributionImageURL(String text) {
     92        attributionImageURL = text;
     93    }
     94
     95    public void setTermsOfUseText(String text) {
     96        termsOfUseText = text;
    7597    }
    7698
Note: See TracChangeset for help on using the changeset viewer.