Changeset 26806 in osm for applications


Ignore:
Timestamp:
2011-10-08T13:01:32+02:00 (13 years ago)
Author:
bastik
Message:

rework in order to get attribution for wms layers

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
2 added
5 edited

Legend:

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

    r26794 r26806  
    1616import java.util.HashMap;
    1717
    18 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
     18import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
    1919
    2020public class AttributionSupport {
    2121
    22     private TileSource tileSource;
     22    private Attributed source;
    2323
    2424    private Image attrImage;
     
    3838    }
    3939
    40     public void initialize(TileSource tileSource) {
    41         this.tileSource = tileSource;
    42         boolean requireAttr = tileSource.requiresAttribution();
     40    public void initialize(Attributed source) {
     41        this.source = source;
     42        boolean requireAttr = source.requiresAttribution();
    4343        if (requireAttr) {
    44             attrImage = tileSource.getAttributionImage();
    45             attrTermsText = tileSource.getTermsOfUseText();
    46             attrTermsUrl = tileSource.getTermsOfUseURL();
     44            attrImage = source.getAttributionImage();
     45            attrTermsText = source.getTermsOfUseText();
     46            attrTermsUrl = source.getTermsOfUseURL();
    4747            if (attrTermsUrl != null && attrTermsText == null) {
    4848                attrTermsText = tr("Background Terms of Use");
     
    5555
    5656    public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) {
    57         if (tileSource == null || !tileSource.requiresAttribution())
     57        if (source == null || !source.requiresAttribution())
    5858            return;
    5959        // Draw attribution
     
    9191
    9292        g.setFont(ATTR_FONT);
    93         String attributionText = tileSource.getAttributionText(zoom, topLeft, bottomRight);
     93        String attributionText = source.getAttributionText(zoom, topLeft, bottomRight);
    9494        if (attributionText != null) {
    9595            Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
     
    108108
    109109    public boolean handleAttribution(Point p, boolean click) {
    110         if (tileSource == null || !tileSource.requiresAttribution())
     110        if (source == null || !source.requiresAttribution())
    111111            return false;
    112112
     
    114114
    115115        if (attrTextBounds != null && attrTextBounds.contains(p)) {
    116             String attributionURL = tileSource.getAttributionLinkURL();
     116            String attributionURL = source.getAttributionLinkURL();
    117117            if (attributionURL != null) {
    118118                if (click) {
     
    122122            }
    123123        } else if (attrImageBounds != null && attrImageBounds.contains(p)) {
    124             String attributionImageURL = tileSource.getAttributionImageURL();
     124            String attributionImageURL = source.getAttributionImageURL();
    125125            if (attributionImageURL != null) {
    126126                if (click) {
    127                     FeatureAdapter.openLink(tileSource.getAttributionImageURL());
     127                    FeatureAdapter.openLink(source.getAttributionImageURL());
    128128                }
    129129                return true;
    130130            }
    131131        } else if (attrToUBounds != null && attrToUBounds.contains(p)) {
    132             String termsOfUseURL = tileSource.getTermsOfUseURL();
     132            String termsOfUseURL = source.getTermsOfUseURL();
    133133            if (termsOfUseURL != null) {
    134134                if (click) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r26793 r26806  
    1313 * @author Jan Peter Stotz
    1414 */
    15 public interface TileSource {
     15public interface TileSource extends Attributed {
    1616
    1717    /**
     
    9797    int getTileSize();
    9898
    99     /**
    100      * @return True if the tile source requires attribution in text or image form.
    101      */
    102     boolean requiresAttribution();
    103 
    104     /**
    105      * @param zoom The optional zoom level for the view.
    106      * @param botRight The bottom right of the bounding box for attribution.
    107      * @param topLeft The top left of the bounding box for attribution.
    108      * @return Attribution text for the image source.
    109      */
    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();
    116 
    117     /**
    118      * @return The URL for the attribution image. Null if no image should be displayed.
    119      */
    120     Image getAttributionImage();
    121 
    122     /**
    123      * @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.
    126      */
    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();
    135 
    136     /**
    137      * @return The URL to open when the user clicks the attribution "Terms of Use" text.
    138      */
    139     String getTermsOfUseURL();
    140 
    14199    double latToTileY(double lat, int zoom);
    142100
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java

    r26793 r26806  
    1717    }
    1818
    19     public AbstractOsmTileSource(String name, String base_url, String attr_img_url) {
    20         super(name, base_url, attr_img_url);
    21     }
    2219    public int getMaxZoom() {
    2320        return 18;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTSMTileSource.java

    r26793 r26806  
    1 /**
    2  *
    3  */
    41package org.openstreetmap.gui.jmapviewer.tilesources;
     2
     3//License: GPL.
    54
    65import java.awt.Image;
     
    1211import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    1312
    14 public abstract class AbstractTSMTileSource implements TileSource {
     13public abstract class AbstractTSMTileSource extends AbstractTileSource {
    1514
    1615    protected String name;
    1716    protected String baseUrl;
    18     protected String attrImgUrl;
    1917
    2018    public AbstractTSMTileSource(String name, String base_url) {
    21         this(name, base_url, null);
    22     }
    23 
    24     public AbstractTSMTileSource(String name, String base_url, String attr_img_url) {
    2519        this.name = name;
    2620        this.baseUrl = base_url;
     
    2822            baseUrl = baseUrl.substring(0,baseUrl.length()-1);
    2923        }
    30         attrImgUrl = attr_img_url;
    3124    }
    3225
     
    8275
    8376    @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
    99     public Image getAttributionImage() {
    100         if (attrImgUrl != null)
    101             return new ImageIcon(attrImgUrl).getImage();
    102 
    103         else
    104             return null;
    105     }
    106 
    107     @Override
    108     public String getAttributionImageURL() {
    109         throw new UnsupportedOperationException("no attribution");
    110     }
    111 
    112     @Override
    113     public String getTermsOfUseText() {
    114         throw new UnsupportedOperationException("no attribution");
    115     }
    116 
    117     @Override
    118     public String getTermsOfUseURL() {
    119         throw new UnsupportedOperationException("no attribution");
    120     }
    121 
    122     @Override
    12377    public double latToTileY(double lat, int zoom) {
    12478        double l = lat / 180 * Math.PI;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java

    r26793 r26806  
    88
    99public class TMSTileSource extends AbstractTSMTileSource {
     10
    1011    protected int maxZoom;
    1112    protected int minZoom = 0;
    12     protected String attributionText;
    13     protected String attributionLinkURL;
    14     protected Image attributionImage;
    15     protected String attributionImageURL;
    16     protected String termsOfUseText;
    17     protected String termsOfUseURL;
    1813
    1914    public TMSTileSource(String name, String url, int maxZoom) {
     
    4237    }
    4338
    44     @Override
    45     public boolean requiresAttribution() {
    46         return attributionText != null;
    47     }
    48 
    49     @Override
    50     public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
    51         return attributionText;
    52     }
    53 
    54     @Override
    55     public String getAttributionLinkURL() {
    56         return attributionLinkURL;
    57     }
    58 
    59     @Override
    60     public Image getAttributionImage() {
    61         return attributionImage;
    62     }
    63 
    64     @Override
    65     public String getAttributionImageURL() {
    66         return attributionImageURL;
    67     }
    68 
    69     @Override
    70     public String getTermsOfUseText() {
    71         return termsOfUseText;
    72     }
    73 
    74     @Override
    75     public String getTermsOfUseURL() {
    76         return termsOfUseURL;
    77     }
    78 
    79     public void setAttributionText(String text) {
    80         attributionText = text;
    81     }
    82 
    83     public void setAttributionLinkURL(String text) {
    84         attributionLinkURL = text;
    85     }
    86 
    87     public void setAttributionImage(Image img) {
    88         attributionImage = img;
    89     }
    90 
    91     public void setAttributionImageURL(String text) {
    92         attributionImageURL = text;
    93     }
    94 
    95     public void setTermsOfUseText(String text) {
    96         termsOfUseText = text;
    97     }
    98 
    99     public void setTermsOfUseURL(String text) {
    100         termsOfUseURL = text;
    101     }
    10239}
Note: See TracChangeset for help on using the changeset viewer.