Changeset 24967 in osm for applications/viewer/jmapviewer/src/org/openstreetmap
- Timestamp:
- 2011-01-04T16:00:17+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
r24847 r24967 203 203 saveTagsToFile(); 204 204 205 byte[] buffer = loadTileInBuffer(urlConn); 205 byte[] buffer = null; 206 if ("no-tile".equals(tile.getValue("tile-info"))) 207 { 208 tile.setError("No tile at this zoom level"); 209 } else { 210 buffer = loadTileInBuffer(urlConn); 211 } 206 212 if (buffer != null) { 207 213 tile.loadImage(new ByteArrayInputStream(buffer)); … … 209 215 listener.tileLoadingFinished(tile, true); 210 216 saveTileToFile(buffer); 211 } else {212 tile.setLoaded(true);213 217 } 214 218 } catch (Exception e) { 215 tile.setImage(Tile.ERROR_IMAGE); 216 tile.error = true; 219 tile.setError(e.getMessage()); 217 220 listener.tileLoadingFinished(tile, false); 218 221 if (input == null) { … … 229 232 try { 230 233 tileFile = getTileFile(); 231 fin = new FileInputStream(tileFile);232 if (fin.available() == 0)233 throw new IOException("File empty");234 tile.loadImage(fin);235 fin.close();236 237 234 loadTagsFromFile(); 235 if ("no-tile".equals(tile.getValue("tile-info"))) 236 { 237 tile.setError("No tile at this zoom level"); 238 if (tileFile.exists()) { 239 tileFile.delete(); 240 } 241 tileFile = getTagsFile(); 242 } else { 243 fin = new FileInputStream(tileFile); 244 if (fin.available() == 0) 245 throw new IOException("File empty"); 246 tile.loadImage(fin); 247 fin.close(); 248 } 238 249 239 250 fileAge = tileFile.lastModified(); … … 333 344 } 334 345 346 protected File getTagsFile() { 347 return new File(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() + "_" + tile.getYtile() 348 + TAGS_FILE_EXT); 349 } 350 335 351 protected void saveTileToFile(byte[] rawData) { 336 352 try { … … 346 362 347 363 protected void saveTagsToFile() { 348 File tagsFile = new File(tileCacheDir, tile.getZoom() + "_" 349 + tile.getXtile() + "_" + tile.getYtile() + TAGS_FILE_EXT); 364 File tagsFile = getTagsFile(); 350 365 if (tile.getMetadata() == null) { 351 366 tagsFile.delete(); … … 353 368 } 354 369 try { 355 final PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile))); 370 final PrintWriter f = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tagsFile), 371 TAGS_CHARSET)); 356 372 for (Entry<String, String> entry : tile.getMetadata().entrySet()) { 357 373 f.println(entry.getKey() + "=" + entry.getValue()); … … 385 401 protected void loadTagsFromFile() { 386 402 loadOldETagfromFile(); 387 File tagsFile = new File(tileCacheDir, tile.getZoom() + "_"388 + tile.getXtile() + "_" + tile.getYtile() + TAGS_FILE_EXT);389 try {390 final BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile)));403 File tagsFile = getTagsFile(); 404 try { 405 final BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(tagsFile), 406 TAGS_CHARSET)); 391 407 for (String line = f.readLine(); line != null; line = f.readLine()) { 392 408 final int i = line.indexOf('='); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r24840 r24967 52 52 URLConnection conn = loadTileFromOsm(tile); 53 53 loadTileMetadata(tile, conn); 54 input = conn.getInputStream(); 55 tile.loadImage(input); 54 if ("no-tile".equals(tile.getValue("tile-info"))) { 55 tile.setError("No tile at this zoom level"); 56 } else { 57 input = conn.getInputStream(); 58 tile.loadImage(input); 59 input.close(); 60 input = null; 61 } 56 62 tile.setLoaded(true); 57 63 listener.tileLoadingFinished(tile, true); 58 input.close();59 input = null;60 64 } catch (Exception e) { 61 tile.setImage(Tile.ERROR_IMAGE); 62 tile.error = true; 65 tile.setError(e.getMessage()); 63 66 listener.tileLoadingFinished(tile, false); 64 67 if (input == null) { … … 86 89 87 90 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 String str = urlConn.getHeaderField("X-VE-TILEMETA-CaptureDatesRange"); 92 if (str != null) { 93 tile.putValue("capture-date", str); 94 } 95 str = urlConn.getHeaderField("X-VE-Tile-Info"); 96 if (str != null) { 97 tile.putValue("tile-info", str); 91 98 } 92 99 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r24847 r24967 50 50 protected boolean loading = false; 51 51 protected boolean error = false; 52 protected String error_message; 52 53 53 54 /** TileLoader-specific tile metadata */ … … 271 272 } 272 273 274 public String getErrorMessage() { 275 return error_message; 276 } 277 278 public void setError(String message) { 279 error = true; 280 setImage(ERROR_IMAGE); 281 error_message = message; 282 } 283 273 284 public void putValue(String key, String value) { 274 285 if (value == null || "".equals(value)) {
Note:
See TracChangeset
for help on using the changeset viewer.