Changeset 9618 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2008-08-10T17:53:22+02:00 (16 years ago)
- Location:
- applications/viewer/jmapviewer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer
-
Property svn:ignore
set to
JMapViewer_Demo.jar
JMapViewer_src.jar
JMapViewer.jar
-
Property svn:ignore
set to
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r9494 r9618 13 13 import javax.swing.JPanel; 14 14 15 16 15 /** 17 16 * … … 23 22 public class Demo extends JFrame { 24 23 24 private static final long serialVersionUID = 1L; 25 25 26 public Demo() { 26 27 super("JMapViewer Demo"); 27 28 setSize(400, 400); 28 29 final JMapViewer map = new JMapViewer(); 29 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); 30 // map.setTileLoader(new OsmFileCacheTileLoader(map,OsmTileLoader.MAP_MAPNIK)); 30 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); 31 // map.setTileLoader(new 32 // OsmFileCacheTileLoader(map,OsmTileLoader.MAP_MAPNIK)); 31 33 new DefaultMapController(map); 32 34 setLayout(new BorderLayout()); … … 35 37 JPanel panel = new JPanel(); 36 38 add(panel, BorderLayout.NORTH); 37 JLabel label = 38 new JLabel( 39 "Use right mouse button to move,\n left double click or mouse wheel to zoom."); 39 JLabel label = new JLabel( 40 "Use right mouse button to move,\n left double click or mouse wheel to zoom."); 40 41 panel.add(label); 41 42 JButton button = new JButton("setDisplayToFitMapMarkers"); … … 83 84 map.addMapMarker(new MapMarkerDot(49.807, 8.644)); 84 85 85 // map.setDisplayPositionByLatLon(49.807, 8.6, 11);86 // map.setTileGridVisible(true);86 // map.setDisplayPositionByLatLon(49.807, 8.6, 11); 87 // map.setTileGridVisible(true); 87 88 } 88 89 … … 91 92 */ 92 93 public static void main(String[] args) { 93 //Properties systemProperties = System.getProperties();94 //systemProperties.setProperty("http.proxyHost","localhost");95 //systemProperties.setProperty("http.proxyPort","8008");94 // Properties systemProperties = System.getProperties(); 95 // systemProperties.setProperty("http.proxyHost","localhost"); 96 // systemProperties.setProperty("http.proxyPort","8008"); 96 97 new Demo().setVisible(true); 97 98 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r9538 r9618 13 13 import java.net.URL; 14 14 import java.net.URLConnection; 15 16 import javax.imageio.ImageIO;17 15 18 16 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; … … 90 88 f = getTileFile(tile); 91 89 fin = new FileInputStream(f); 92 tile. setImage(ImageIO.read(fin));90 tile.loadImage(fin); 93 91 fin.close(); 94 92 fileAge = f.lastModified(); … … 129 127 // } 130 128 byte[] buffer = loadTileInBuffer(urlConn); 131 tile. setImage(ImageIO.read(new ByteArrayInputStream(buffer)));129 tile.loadImage(new ByteArrayInputStream(buffer)); 132 130 tile.setLoaded(true); 133 131 map.repaint(); … … 136 134 } catch (Exception e) { 137 135 if (input == null /* || !input.isStopped() */) 138 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " "139 + e.getMessage());136 System.err.println("failed loading " + zoom + "/" + tilex 137 + "/" + tiley + " " + e.getMessage()); 140 138 } finally { 141 139 tile.loading = false; … … 143 141 } 144 142 145 protected byte[] loadTileInBuffer(URLConnection urlConn) throws IOException { 143 protected byte[] loadTileInBuffer(URLConnection urlConn) 144 throws IOException { 146 145 input = urlConn.getInputStream(); 147 ByteArrayOutputStream bout = new ByteArrayOutputStream(input.available()); 146 ByteArrayOutputStream bout = new ByteArrayOutputStream(input 147 .available()); 148 148 byte[] buffer = new byte[2048]; 149 149 boolean finished = false; … … 175 175 * @throws IOException 176 176 */ 177 protected boolean isOsmTileNewer(Tile tile, long fileAge) throws IOException { 177 protected boolean isOsmTileNewer(Tile tile, long fileAge) 178 throws IOException { 178 179 URL url; 179 180 url = new URL(baseUrl + "/" + tile.getKey() + ".png"); 180 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 181 HttpURLConnection urlConn = (HttpURLConnection) url 182 .openConnection(); 181 183 urlConn.setRequestMethod("HEAD"); 182 184 urlConn.setReadTimeout(30000); // 30 seconds read … … 191 193 192 194 protected File getTileFile(Tile tile) throws IOException { 193 return new File(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() + "_"194 + tile.get Ytile() + FILE_EXT);195 return new File(tileCacheDir + "/" + tile.getZoom() + "_" 196 + tile.getXtile() + "_" + tile.getYtile() + FILE_EXT); 195 197 } 196 198 197 199 protected void saveTileToFile(Tile tile, byte[] rawData) { 198 200 try { 199 FileOutputStream f = 200 new FileOutputStream(tileCacheDir + "/" + tile.getZoom() + "_"201 + tile.getXtile() + "_"+ tile.getYtile() + FILE_EXT);201 FileOutputStream f = new FileOutputStream(tileCacheDir + "/" 202 + tile.getZoom() + "_" + tile.getXtile() + "_" 203 + tile.getYtile() + FILE_EXT); 202 204 f.write(rawData); 203 205 f.close(); 204 206 // System.out.println("Saved tile to file: " + tile); 205 207 } catch (Exception e) { 206 System.err.println("Failed to save tile content: " + e.getLocalizedMessage()); 208 System.err.println("Failed to save tile content: " 209 + e.getLocalizedMessage()); 207 210 } 208 211 } … … 230 233 231 234 public void setTileCacheDir(String tileCacheDir) { 232 this.tileCacheDir = tileCacheDir; 233 } 234 235 235 File dir = new File(tileCacheDir); 236 dir.mkdirs(); 237 this.tileCacheDir = dir.getAbsolutePath(); 238 } 239 236 240 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r9494 r9618 7 7 import java.net.HttpURLConnection; 8 8 import java.net.URL; 9 10 import javax.imageio.ImageIO;11 9 12 10 import org.openstreetmap.gui.jmapviewer.interfaces.Job; … … 54 52 // Thread.sleep(500); 55 53 input = loadTileFromOsm(tile).getInputStream(); 56 tile. setImage(ImageIO.read(input));54 tile.loadImage(input); 57 55 tile.setLoaded(true); 58 56 map.repaint(); … … 61 59 } catch (Exception e) { 62 60 if (input == null /* || !input.isStopped() */) 63 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley64 + " " + e.getMessage());61 System.err.println("failed loading " + zoom + "/" 62 + tilex + "/" + tiley + " " + e.getMessage()); 65 63 } finally { 66 64 tile.loading = false; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r9494 r9618 7 7 import java.awt.geom.AffineTransform; 8 8 import java.awt.image.BufferedImage; 9 import java.io.IOException; 10 import java.io.InputStream; 11 12 import javax.imageio.ImageIO; 9 13 10 14 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; … … 55 59 */ 56 60 public void loadPlaceholderFromCache(TileCache cache) { 57 BufferedImage tmpImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); 61 BufferedImage tmpImage = new BufferedImage(WIDTH, HEIGHT, 62 BufferedImage.TYPE_INT_RGB); 58 63 Graphics2D g = (Graphics2D) tmpImage.getGraphics(); 59 64 // g.drawImage(image, 0, 0, null); … … 71 76 for (int x = 0; x < factor; x++) { 72 77 for (int y = 0; y < factor; y++) { 73 Tile tile = cache.getTile(xtile_high + x, ytile_high + y, zoom_high); 78 Tile tile = cache.getTile(xtile_high + x, ytile_high 79 + y, zoom_high); 74 80 if (tile != null && tile.isLoaded()) { 75 81 paintedTileCount++; … … 134 140 } 135 141 142 public void loadImage(InputStream input) throws IOException { 143 image = ImageIO.read(input); 144 } 145 136 146 /** 137 147 * @return key that identifies a tile … … 175 185 return false; 176 186 Tile tile = (Tile) obj; 177 return (xtile == tile.xtile) && (ytile == tile.ytile) && (zoom == tile.zoom); 187 return (xtile == tile.xtile) && (ytile == tile.ytile) 188 && (zoom == tile.zoom); 178 189 } 179 190
Note:
See TracChangeset
for help on using the changeset viewer.