source: osm/applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java@ 25538

Last change on this file since 25538 was 25538, checked in by bastik, 14 years ago

fix josm bug #6075 - the attribution is not generic and has to come from ImageryInfo or similar. This change removes attribution from osm layers again.

File size: 3.1 KB
Line 
1/**
2 *
3 */
4package org.openstreetmap.gui.jmapviewer.tilesources;
5
6import java.awt.Image;
7import java.io.IOException;
8
9import javax.swing.ImageIcon;
10
11import org.openstreetmap.gui.jmapviewer.Coordinate;
12import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
13
14public abstract class AbstractOsmTileSource implements TileSource {
15
16 protected String name;
17 protected String baseUrl;
18 protected String attrImgUrl;
19
20 public AbstractOsmTileSource(String name, String base_url) {
21 this(name, base_url, null);
22 }
23
24 public AbstractOsmTileSource(String name, String base_url, String attr_img_url) {
25 this.name = name;
26 this.baseUrl = base_url;
27 attrImgUrl = attr_img_url;
28 }
29
30 public String getName() {
31 return name;
32 }
33
34 public int getMaxZoom() {
35 return 18;
36 }
37
38 public int getMinZoom() {
39 return 0;
40 }
41
42 public String getExtension() {
43 return "png";
44 }
45
46 /**
47 * @throws IOException when subclass cannot return the tile URL
48 */
49 public String getTilePath(int zoom, int tilex, int tiley) throws IOException {
50 return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension();
51 }
52
53 public String getBaseUrl() {
54 return this.baseUrl;
55 }
56
57 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
58 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
59 }
60
61 @Override
62 public String toString() {
63 return getName();
64 }
65
66 public String getTileType() {
67 return "png";
68 }
69
70 public int getTileSize() {
71 return 256;
72 }
73
74 public Image getAttributionImage() {
75 if (attrImgUrl != null)
76 return new ImageIcon(attrImgUrl).getImage();
77 else
78 return null;
79 }
80
81 public boolean requiresAttribution() {
82 return false;
83 }
84
85 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
86 throw new UnsupportedOperationException("no attribution");
87 //return "\u00a9 OpenStreetMap contributors, CC-BY-SA ";
88 }
89
90 public String getAttributionLinkURL() {
91 throw new UnsupportedOperationException("no attribution");
92 //return "http://openstreetmap.org/";
93 }
94
95 public String getTermsOfUseURL() {
96 throw new UnsupportedOperationException("no attribution");
97 //return "http://www.openstreetmap.org/copyright";
98 }
99
100 public double latToTileY(double lat, int zoom) {
101 double l = lat / 180 * Math.PI;
102 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));
103 return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI;
104 }
105
106 public double lonToTileX(double lon, int zoom) {
107 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;
108 }
109
110 public double tileYToLat(int y, int zoom) {
111 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, zoom - 1)))) * 180 / Math.PI;
112 }
113
114 public double tileXToLon(int x, int zoom) {
115 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;
116 }
117}
Note: See TracBrowser for help on using the repository browser.