Changeset 24763 in osm for applications/viewer/jmapviewer/src/org/openstreetmap/gui
- Timestamp:
- 2010-12-15T18:27:25+01:00 (14 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/BingAerialTileSource.java
r24706 r24763 7 7 import java.util.ArrayList; 8 8 import java.util.List; 9 import java.util.concurrent.Callable; 10 import java.util.concurrent.Executors; 11 import java.util.concurrent.Future; 9 12 10 13 import javax.imageio.ImageIO; … … 19 22 public class BingAerialTileSource extends OsmTileSource.AbstractOsmTileSource { 20 23 private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU"; 21 private static List<Attribution> attributions;24 private static Future<List<Attribution>> attributions; 22 25 23 26 public BingAerialTileSource() { … … 25 28 26 29 if (attributions == null) { 27 Thread t = new Thread(new Runnable() {30 attributions = Executors.newSingleThreadExecutor().submit(new Callable<List<Attribution>>() { 28 31 @Override 29 public void run(){30 attributions =loadAttributionText();32 public List<Attribution> call() throws Exception { 33 return loadAttributionText(); 31 34 } 32 35 }); 33 t.setDaemon(true);34 t.start();35 36 } 36 37 } … … 130 131 131 132 @Override 132 public String getTilePath(int zoom, int tilex, int tiley) { 133 String quadtree = computeQuadTree(zoom, tilex, tiley); 134 return "/tiles/a" + quadtree + "." + getExtension() + "?g=587"; 133 public String getTilePath(int zoom, int tilex, int tiley) throws IOException { 134 try { 135 if (attributions.get() == null) 136 throw new IOException("Cannot load Bing attribution"); 137 String quadtree = computeQuadTree(zoom, tilex, tiley); 138 return "/tiles/a" + quadtree + "." + getExtension() + "?g=587"; 139 } catch (Exception e) { 140 throw new IOException("Cannot load Bing attribution", e); 141 } 135 142 } 136 143 … … 169 176 @Override 170 177 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) { 171 if (attributions == null) 172 // TODO: don't show Bing tiles until attribution data is loaded 173 return ""; 174 StringBuilder a = new StringBuilder(); 175 for (Attribution attr : attributions) { 176 if(zoom <= attr.maxZoom && zoom >= attr.minZoom) { 177 if(topLeft.getLon() < attr.max.getLon() 178 && botRight.getLon() > attr.min.getLon() 179 && topLeft.getLat() > attr.min.getLat() 180 && botRight.getLat() < attr.max.getLat()) { 181 a.append(attr.attribution); 182 a.append(" "); 178 try { 179 if (!attributions.isDone()) 180 return "Loading Bing attribution data..."; 181 if (attributions.get() == null) 182 return "Error loading Bing attribution data"; 183 StringBuilder a = new StringBuilder(); 184 for (Attribution attr : attributions.get()) { 185 if(zoom <= attr.maxZoom && zoom >= attr.minZoom) { 186 if(topLeft.getLon() < attr.max.getLon() 187 && botRight.getLon() > attr.min.getLon() 188 && topLeft.getLat() > attr.min.getLat() 189 && botRight.getLat() < attr.max.getLat()) { 190 a.append(attr.attribution); 191 a.append(" "); 192 } 183 193 } 184 194 } 185 } 186 return a.toString(); 195 return a.toString(); 196 } catch (Exception e) { 197 e.printStackTrace(); 198 } 199 return "Error loading Bing attribution data"; 187 200 } 188 201 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r18772 r24763 63 63 log.log(Level.WARNING, 64 64 "Failed to access system property ''java.io.tmpdir'' for security reasons. Exception was: " 65 65 + e.toString()); 66 66 throw e; // rethrow 67 67 } … … 73 73 // On Linux/Unix systems we do not have a per user tmp directory. 74 74 // Therefore we add the user name for getting a unique dir name. 75 if (userName != null && userName.length() > 0) 75 if (userName != null && userName.length() > 0) { 76 76 subDirName += "_" + userName; 77 } 77 78 cacheDir = new File(tempDir, subDirName); 78 79 } … … 208 209 } catch (Exception e) { 209 210 tile.setImage(Tile.ERROR_IMAGE); 211 tile.error = true; 210 212 listener.tileLoadingFinished(tile, false); 211 213 if (input == null) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java
r24706 r24763 2 2 3 3 import java.awt.Image; 4 import java.io.IOException; 4 5 5 6 import javax.swing.ImageIcon; … … 48 49 } 49 50 50 public String getTilePath(int zoom, int tilex, int tiley) { 51 /** 52 * @throws IOException when subclass cannot return the tile URL 53 */ 54 public String getTilePath(int zoom, int tilex, int tiley) throws IOException { 51 55 return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension(); 52 56 } … … 56 60 } 57 61 58 public String getTileUrl(int zoom, int tilex, int tiley) {62 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException { 59 63 return this.getBaseUrl() + getTilePath(zoom, tilex, tiley); 60 64 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r22281 r24763 184 184 } 185 185 186 public String getUrl() {186 public String getUrl() throws IOException { 187 187 return source.getTileUrl(zoom, xtile, ytile); 188 188 } … … 254 254 public String getStatus() { 255 255 String status = "new"; 256 if (this.error) { 257 status = "error"; 258 } 256 259 if (this.loading) { 257 260 status = "loading"; … … 260 263 status = "loaded"; 261 264 } 262 if (this.error) {263 status = "error";264 }265 265 return status; 266 266 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r24706 r24763 2 2 3 3 import java.awt.Image; 4 import java.io.IOException; 4 5 5 6 import org.openstreetmap.gui.jmapviewer.Coordinate; … … 80 81 * @return fully qualified url for downloading the specified tile image 81 82 */ 82 public String getTileUrl(int zoom, int tilex, int tiley) ;83 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException; 83 84 84 85 /**
Note:
See TracChangeset
for help on using the changeset viewer.