Changeset 24840 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2010-12-22T16:59:45+01:00 (14 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r24828 r24840 113 113 114 114 public FileLoadJob(TileSource source, int tilex, int tiley, int zoom) { 115 super();116 115 this.source = source; 117 116 this.tilex = tilex; … … 151 150 try { 152 151 // log.finest("Loading tile from OSM: " + tile); 153 HttpURLConnection urlConn = loadTileFromOsm(tile);152 URLConnection urlConn = loadTileFromOsm(tile); 154 153 if (tileFile != null) { 155 154 switch (source.getTileUpdate()) { … … 189 188 saveETagToFile(eTag); 190 189 } 191 if (urlConn.getResponseCode() == 304) { 190 loadTileMetadata(tile, urlConn); 191 if (urlConn instanceof HttpURLConnection && ((HttpURLConnection)urlConn).getResponseCode() == 304) { 192 192 // If we are isModifiedSince or If-None-Match has been set 193 193 // and the server answers with a HTTP 304 = "Not Modified" -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r18772 r24840 7 7 import java.net.HttpURLConnection; 8 8 import java.net.URL; 9 import java.net.URLConnection; 9 10 10 11 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; … … 14 15 15 16 /** 16 * A {@link TileLoader} implementation that loads tiles from OSM via HTTP.17 * A {@link TileLoader} implementation that loads tiles from OSM. 17 18 * 18 19 * @author Jan Peter Stotz … … 49 50 try { 50 51 // Thread.sleep(500); 51 input = loadTileFromOsm(tile).getInputStream(); 52 URLConnection conn = loadTileFromOsm(tile); 53 loadTileMetadata(tile, conn); 54 input = conn.getInputStream(); 52 55 tile.loadImage(input); 53 56 tile.setLoaded(true); … … 59 62 tile.error = true; 60 63 listener.tileLoadingFinished(tile, false); 61 if (input == null) 64 if (input == null) { 62 65 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage()); 66 } 63 67 } finally { 64 68 tile.loading = false; … … 70 74 } 71 75 72 protected HttpURLConnection loadTileFromOsm(Tile tile) throws IOException {76 protected URLConnection loadTileFromOsm(Tile tile) throws IOException { 73 77 URL url; 74 78 url = new URL(tile.getUrl()); 75 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 76 prepareHttpUrlConnection(urlConn); 79 URLConnection urlConn = url.openConnection(); 80 if (urlConn instanceof HttpURLConnection) { 81 prepareHttpUrlConnection((HttpURLConnection)urlConn); 82 } 77 83 urlConn.setReadTimeout(30000); // 30 seconds read timeout 78 84 return urlConn; 79 85 } 80 86 87 protected void loadTileMetadata(Tile tile, URLConnection urlConn) { 88 String bing_capturedate = urlConn.getHeaderField("X-VE-TILEMETA-CaptureDatesRange"); 89 if (bing_capturedate != null) { 90 tile.putValue("capture-date", bing_capturedate); 91 } 92 } 93 81 94 protected void prepareHttpUrlConnection(HttpURLConnection urlConn) { 82 if (USER_AGENT != null) 95 if (USER_AGENT != null) { 83 96 urlConn.setRequestProperty("User-agent", USER_AGENT); 97 } 84 98 urlConn.setRequestProperty("Accept", ACCEPT); 85 99 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r24763 r24840 9 9 import java.io.IOException; 10 10 import java.io.InputStream; 11 import java.util.HashMap; 12 import java.util.Map; 11 13 12 14 import javax.imageio.ImageIO; … … 48 50 protected boolean loading = false; 49 51 protected boolean error = false; 52 53 /** TileSource-specific tile metadata */ 54 protected Map<String, String> metadata; 50 55 51 56 /** … … 253 258 254 259 public String getStatus() { 255 String status = "new"; 256 if (this.error) { 257 status = "error"; 258 } 259 if (this.loading) { 260 status = "loading"; 261 } 262 if (this.loaded) { 263 status = "loaded"; 264 } 265 return status; 260 if (this.error) 261 return "error"; 262 if (this.loaded) 263 return "loaded"; 264 if (this.loading) 265 return "loading"; 266 return "new"; 266 267 } 267 268 … … 270 271 } 271 272 273 public void putValue(String key, String value) { 274 if (metadata == null) { 275 metadata = new HashMap<String,String>(); 276 } 277 metadata.put(key, value); 278 } 279 280 public String getValue(String key) { 281 if (metadata == null) return null; 282 return metadata.get(key); 283 } 284 285 public Map<String,String> getMetadata() { 286 return metadata; 287 } 272 288 }
Note:
See TracChangeset
for help on using the changeset viewer.