Changeset 25369 in osm for applications/viewer/jmapviewer/src/org/openstreetmap
- Timestamp:
- 2011-02-19T16:49:09+01:00 (14 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 added
- 4 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r25314 r25369 19 19 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 20 20 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 21 import org.openstreetmap.gui.jmapviewer.tilesources.BingAerialTileSource; 22 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource; 21 23 22 24 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r24706 r25369 32 32 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 33 33 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 34 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource; 34 35 35 36 /** … … 745 746 746 747 private void paintAttribution(Graphics g) { 747 if (!tileSource.requiresAttribution()) return; 748 if (!tileSource.requiresAttribution()) 749 return; 748 750 // Draw attribution 749 751 Font font = g.getFont(); … … 771 773 772 774 g.setFont(ATTR_FONT); 773 Coordinate topLeft = getPosition(0, 0);774 Coordinate bottomRight = getPosition(getWidth(), getHeight());775 Coordinate topLeft = getPosition(0, 0); 776 Coordinate bottomRight = getPosition(getWidth(), getHeight()); 775 777 String attributionText = tileSource.getAttributionText(zoom, topLeft, bottomRight); 776 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);777 {778 if (attributionText != null) { 779 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); 778 780 int x = getWidth() - (int) stringBounds.getWidth(); 779 781 int y = getHeight() - textHeight; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileController.java
r18772 r25369 6 6 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 7 7 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 8 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource; 8 9 9 10 public class TileController { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r25265 r25369 98 98 99 99 /** 100 * @return True if the tile source requires attribution .100 * @return True if the tile source requires attribution in text or image form. 101 101 */ 102 102 public boolean requiresAttribution(); … … 128 128 129 129 public double lonToTileX(double lon, int zoom); 130 130 131 131 public double tileYToLat(int y, int zoom); 132 132 133 133 public double tileXToLon(int x, int zoom); 134 134 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
r25366 r25369 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 2 3 3 import java.awt.Image; … … 14 14 import javax.imageio.ImageIO; 15 15 16 import org.openstreetmap.gui.jmapviewer.Coordinate; 16 17 import org.xml.sax.Attributes; 17 18 import org.xml.sax.InputSource; … … 21 22 import org.xml.sax.helpers.XMLReaderFactory; 22 23 23 public class BingAerialTileSource extends OsmTileSource.AbstractOsmTileSource {24 public class BingAerialTileSource extends AbstractOsmTileSource { 24 25 private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU"; 25 26 private static Future<List<Attribution>> attributions; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/OsmTileSource.java
r25366 r25369 1 package org.openstreetmap.gui.jmapviewer; 2 3 import java.awt.Image; 4 import java.io.IOException; 5 6 import javax.swing.ImageIcon; 7 8 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 1 package org.openstreetmap.gui.jmapviewer.tilesources; 9 2 10 3 public class OsmTileSource { … … 12 5 public static final String MAP_MAPNIK = "http://tile.openstreetmap.org"; 13 6 public static final String MAP_OSMA = "http://tah.openstreetmap.org/Tiles"; 14 15 public static abstract class AbstractOsmTileSource implements TileSource {16 protected String NAME;17 protected String BASE_URL;18 protected String ATTR_IMG_URL;19 protected boolean REQUIRES_ATTRIBUTION = true;20 21 public AbstractOsmTileSource(String name, String base_url) {22 this(name, base_url, null);23 }24 25 public AbstractOsmTileSource(String name, String base_url, String attr_img_url) {26 NAME = name;27 BASE_URL = base_url;28 ATTR_IMG_URL = attr_img_url;29 if(ATTR_IMG_URL == null) {30 REQUIRES_ATTRIBUTION = false;31 }32 }33 34 public String getName() {35 return NAME;36 }37 38 public int getMaxZoom() {39 return 18;40 }41 42 public int getMinZoom() {43 return 0;44 }45 46 public String getExtension() {47 return "png";48 }49 50 /**51 * @throws IOException when subclass cannot return the tile URL52 */53 public String getTilePath(int zoom, int tilex, int tiley) throws IOException {54 return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension();55 }56 57 public String getBaseUrl() {58 return this.BASE_URL;59 }60 61 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {62 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);63 }64 65 @Override66 public String toString() {67 return getName();68 }69 70 public String getTileType() {71 return "png";72 }73 74 public int getTileSize() {75 return 256;76 }77 78 public Image getAttributionImage() {79 if (ATTR_IMG_URL != null)80 return new ImageIcon(ATTR_IMG_URL).getImage();81 else82 return null;83 }84 85 public boolean requiresAttribution() {86 return REQUIRES_ATTRIBUTION;87 }88 89 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {90 return "© OpenStreetMap contributors, CC-BY-SA ";91 }92 93 public String getAttributionLinkURL() {94 return "http://openstreetmap.org/";95 }96 97 public String getTermsOfUseURL() {98 return "http://www.openstreetmap.org/copyright";99 }100 101 public double latToTileY(double lat, int zoom) {102 double l = lat / 180 * Math.PI;103 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));104 return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI;105 }106 107 public double lonToTileX(double lon, int zoom) {108 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0;109 }110 111 public double tileYToLat(int y, int zoom) {112 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, zoom - 1)))) * 180 / Math.PI;113 }114 115 public double tileXToLon(int x, int zoom) {116 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;117 }118 }119 7 120 8 public static class Mapnik extends AbstractOsmTileSource { … … 143 31 @Override 144 32 public String getBaseUrl() { 145 String url = String.format(this. BASE_URL, new Object[] { SERVER[SERVER_NUM] });33 String url = String.format(this.baseUrl, new Object[] { SERVER[SERVER_NUM] }); 146 34 SERVER_NUM = (SERVER_NUM + 1) % SERVER.length; 147 35 return url; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/ScanexTileSource.java
r25366 r25369 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 2 3 public class ScanexTileSource extends OsmTileSource.AbstractOsmTileSource { 3 import org.openstreetmap.gui.jmapviewer.OsmMercator; 4 5 public class ScanexTileSource extends AbstractOsmTileSource { 4 6 private static String API_KEY = "4018C5A9AECAD8868ED5DEB2E41D09F7"; 5 7 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java
r25366 r25369 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 2 3 3 4 public class TMSTileSource extends OsmTileSource.AbstractOsmTileSource {4 public class TMSTileSource extends AbstractOsmTileSource { 5 5 private int maxZoom; 6 6 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
r25366 r25369 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 2 3 3 4 public class TemplatedTMSTileSource extends OsmTileSource.AbstractOsmTileSource {4 public class TemplatedTMSTileSource extends AbstractOsmTileSource { 5 5 private int maxZoom; 6 6 … … 11 11 12 12 public String getTileUrl(int zoom, int tilex, int tiley) { 13 return this. BASE_URL13 return this.baseUrl 14 14 .replaceAll("\\{zoom\\}", Integer.toString(zoom)) 15 15 .replaceAll("\\{x\\}", Integer.toString(tilex))
Note:
See TracChangeset
for help on using the changeset viewer.