Changeset 26793 in osm for applications/viewer/jmapviewer/src/org/openstreetmap
- Timestamp:
- 2011-10-07T18:51:36+02:00 (13 years ago)
- 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 2 2 3 3 //License: GPL. 4 5 import static org.openstreetmap.gui.jmapviewer.FeatureAdapter.tr; 4 6 5 7 import java.awt.Color; … … 21 23 22 24 private Image attrImage; 25 private String attrTermsText; 23 26 private String attrTermsUrl; 24 27 public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); 25 28 public static final Font ATTR_LINK_FONT; 29 30 private static final String DEFAULT_TERMS_OF_USE_TEXT = tr("Background Terms of Use"); 26 31 27 32 protected Rectangle attrTextBounds = null; … … 40 45 if (requireAttr) { 41 46 attrImage = tileSource.getAttributionImage(); 47 attrTermsText = tileSource.getTermsOfUseText(); 42 48 attrTermsUrl = tileSource.getTermsOfUseURL(); 49 if (attrTermsUrl != null && attrTermsText == null) { 50 attrTermsText = DEFAULT_TERMS_OF_USE_TEXT; 51 } 43 52 } else { 44 53 attrImage = null; … … 48 57 49 58 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()) 51 60 return; 52 61 // Draw attribution … … 55 64 56 65 // 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; 63 75 int x = 2; 64 int y = height - te xtHeight;65 attrToUBounds = new Rectangle(x, y-te xtHeight, textWidth, textRealHeight);76 int y = height - termsTextHeight; 77 attrToUBounds = new Rectangle(x, y-termsTextHeight, termsTextWidth, textRealHeight); 66 78 g.setColor(Color.black); 67 g.drawString( "Background Terms of Use", x + 1, y + 1);79 g.drawString(attrTermsText, x + 1, y + 1); 68 80 g.setColor(Color.white); 69 g.drawString( "Background Terms of Use", x, y);81 g.drawString(attrTermsText, x, y); 70 82 } 71 83 … … 75 87 int imgWidth = attrImage.getWidth(observer); 76 88 int imgHeight = attrImage.getHeight(observer); 77 int y = termsTextY - imgHeight - te xtHeight - 5;89 int y = termsTextY - imgHeight - termsTextHeight - 5; 78 90 attrImageBounds = new Rectangle(x, y, imgWidth, imgHeight); 79 91 g.drawImage(attrImage, x, y, null); … … 84 96 if (attributionText != null) { 85 97 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); 98 int textHeight = (int) stringBounds.getHeight() - 5; 86 99 int x = width - (int) stringBounds.getWidth(); 87 100 int y = height - textHeight; … … 90 103 g.setColor(Color.white); 91 104 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()); 93 106 } 94 107 … … 97 110 98 111 public boolean handleAttribution(Point p, boolean click) { 99 if ( !tileSource.requiresAttribution())112 if (tileSource == null || !tileSource.requiresAttribution()) 100 113 return false; 101 114 102 115 /* TODO: Somehow indicate the link is clickable state to user */ 103 116 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; 108 124 } 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 } 110 133 } 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; 113 140 } 114 return true;115 141 } 116 142 return false; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r25369 r26793 48 48 * {@link JMapViewer#MAX_ZOOM} 49 49 */ 50 publicint getMaxZoom();50 int getMaxZoom(); 51 51 52 52 /** … … 57 57 * @return minimum zoom value - usually 0 58 58 */ 59 publicint getMinZoom();59 int getMinZoom(); 60 60 61 61 /** … … 63 63 * @see TileUpdate 64 64 */ 65 publicTileUpdate getTileUpdate();65 TileUpdate getTileUpdate(); 66 66 67 67 /** … … 71 71 * @return Name of the tile layer 72 72 */ 73 publicString getName();73 String getName(); 74 74 75 75 /** … … 81 81 * @return fully qualified url for downloading the specified tile image 82 82 */ 83 publicString getTileUrl(int zoom, int tilex, int tiley) throws IOException;83 String getTileUrl(int zoom, int tilex, int tiley) throws IOException; 84 84 85 85 /** … … 89 89 * @return file extension of the tile image type 90 90 */ 91 publicString getTileType();91 String getTileType(); 92 92 93 93 /** … … 95 95 * @return The size of a single tile in pixels. 96 96 */ 97 publicint getTileSize();97 int getTileSize(); 98 98 99 99 /** 100 100 * @return True if the tile source requires attribution in text or image form. 101 101 */ 102 publicboolean requiresAttribution();102 boolean requiresAttribution(); 103 103 104 104 /** … … 108 108 * @return Attribution text for the image source. 109 109 */ 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(); 111 116 112 117 /** 113 118 * @return The URL for the attribution image. Null if no image should be displayed. 114 119 */ 115 publicImage getAttributionImage();120 Image getAttributionImage(); 116 121 117 122 /** 118 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. 119 126 */ 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(); 121 135 122 136 /** 123 137 * @return The URL to open when the user clicks the attribution "Terms of Use" text. 124 138 */ 125 publicString getTermsOfUseURL();139 String getTermsOfUseURL(); 126 140 127 publicdouble latToTileY(double lat, int zoom);141 double latToTileY(double lat, int zoom); 128 142 129 publicdouble lonToTileX(double lon, int zoom);143 double lonToTileX(double lon, int zoom); 130 144 131 publicdouble tileYToLat(int y, int zoom);145 double tileYToLat(int y, int zoom); 132 146 133 publicdouble tileXToLon(int x, int zoom);147 double tileXToLon(int x, int zoom); 134 148 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java
r26253 r26793 40 40 41 41 @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 42 57 public String getTermsOfUseURL() { 43 58 return "http://www.openstreetmap.org/copyright"; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTSMTileSource.java
r26249 r26793 31 31 } 32 32 33 @Override 33 34 public String getName() { 34 35 return name; 35 36 } 36 37 38 @Override 37 39 public int getMaxZoom() { 38 40 return 21; 39 41 } 40 42 43 @Override 41 44 public int getMinZoom() { 42 45 return 0; … … 58 61 } 59 62 63 @Override 60 64 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException { 61 65 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley); … … 67 71 } 68 72 73 @Override 69 74 public String getTileType() { 70 75 return "png"; 71 76 } 72 77 78 @Override 73 79 public int getTileSize() { 74 80 return 256; 75 81 } 76 82 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 77 99 public Image getAttributionImage() { 78 100 if (attrImgUrl != null) 79 101 return new ImageIcon(attrImgUrl).getImage(); 102 80 103 else 81 104 return null; 82 105 } 83 106 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() { 89 109 throw new UnsupportedOperationException("no attribution"); 90 110 } 91 111 92 public String getAttributionLinkURL() { 112 @Override 113 public String getTermsOfUseText() { 93 114 throw new UnsupportedOperationException("no attribution"); 94 115 } 95 116 117 @Override 96 118 public String getTermsOfUseURL() { 97 119 throw new UnsupportedOperationException("no attribution"); 98 120 } 99 121 122 @Override 100 123 public double latToTileY(double lat, int zoom) { 101 124 double l = lat / 180 * Math.PI; … … 104 127 } 105 128 129 @Override 106 130 public double lonToTileX(double lon, int zoom) { 107 131 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0; 108 132 } 109 133 134 @Override 110 135 public double tileYToLat(int y, int zoom) { 111 136 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, zoom - 1)))) * 180 / Math.PI; 112 137 } 113 138 139 @Override 114 140 public double tileXToLon(int x, int zoom) { 115 141 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 1 1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 3 //License: GPL. 2 4 3 5 import java.awt.Image; … … 177 179 178 180 @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 179 189 public Image getAttributionImage() { 180 190 try { … … 186 196 187 197 @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; 193 205 } 194 206 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java
r26253 r26793 1 1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 3 //License: GPL. 2 4 3 5 import java.awt.Image; … … 9 11 protected int minZoom = 0; 10 12 protected String attributionText; 13 protected String attributionLinkURL; 11 14 protected Image attributionImage; 12 protected String attributionLinkURL; 15 protected String attributionImageURL; 16 protected String termsOfUseText; 13 17 protected String termsOfUseURL; 14 18 … … 49 53 50 54 @Override 55 public String getAttributionLinkURL() { 56 return attributionLinkURL; 57 } 58 59 @Override 51 60 public Image getAttributionImage() { 52 61 return attributionImage; … … 54 63 55 64 @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; 58 72 } 59 73 … … 67 81 } 68 82 83 public void setAttributionLinkURL(String text) { 84 attributionLinkURL = text; 85 } 86 69 87 public void setAttributionImage(Image img) { 70 88 attributionImage = img; 71 89 } 72 90 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; 75 97 } 76 98
Note:
See TracChangeset
for help on using the changeset viewer.