Changeset 9713 in osm for applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
- Timestamp:
- 2008-08-12T14:16:26+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r9619 r9713 43 43 * Vectors for clock-wise tile painting 44 44 */ 45 protected static final Point[] move = { new Point(1, 0), new Point(0, 1),46 new Point(-1, 0), new Point(0, -1) }; 45 protected static final Point[] move = 46 { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1) }; 47 47 48 48 public static final int MAX_ZOOM = 18; … … 102 102 setPreferredSize(new Dimension(400, 400)); 103 103 try { 104 loadingImage = ImageIO.read(JMapViewer.class105 .getResourceAsStream("images/hourglass.png")); 104 loadingImage = 105 ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png")); 106 106 } catch (Exception e1) { 107 107 loadingImage = null; … … 123 123 int size = 18; 124 124 try { 125 ImageIcon icon = new ImageIcon(getClass().getResource( 126 "images/plus.png")); 125 ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png")); 127 126 zoomInButton = new JButton(icon); 128 127 } catch (Exception e) { … … 140 139 add(zoomInButton); 141 140 try { 142 ImageIcon icon = new ImageIcon(getClass().getResource( 143 "images/minus.png")); 141 ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png")); 144 142 zoomOutButton = new JButton(icon); 145 143 } catch (Exception e) { … … 170 168 */ 171 169 public void setDisplayPositionByLatLon(double lat, double lon, int zoom) { 172 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), 173 lat, lon, zoom); 170 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), lat, lon, zoom); 174 171 } 175 172 … … 189 186 * {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM} 190 187 */ 191 public void setDisplayPositionByLatLon(Point mapPoint, double lat, 192 double lon, int zoom) { 188 public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) { 193 189 int x = OsmMercator.LonToX(lon, zoom); 194 190 int y = OsmMercator.LatToY(lat, zoom); … … 197 193 198 194 public void setDisplayPosition(int x, int y, int zoom) { 199 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, 200 zoom); 195 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom); 201 196 } 202 197 … … 210 205 p.y = y - mapPoint.y + getHeight() / 2; 211 206 center = p; 212 this.zoom = zoom; 213 if (zoomSlider.getValue() != zoom) 214 zoomSlider.setValue(zoom); 215 repaint(); 207 setIgnoreRepaint(true); 208 try { 209 int oldZoom = this.zoom; 210 this.zoom = zoom; 211 if (oldZoom != zoom) 212 zoomChanged(oldZoom); 213 if (zoomSlider.getValue() != zoom) 214 zoomSlider.setValue(zoom); 215 } finally { 216 setIgnoreRepaint(false); 217 repaint(); 218 } 216 219 } 217 220 … … 240 243 // System.out.println(y_min + " < y < " + y_max); 241 244 // System.out.println("tiles: " + width + " " + height); 242 int zoom = MAX_ZOOM;245 int newZoom = MAX_ZOOM; 243 246 int x = x_max - x_min; 244 247 int y = y_max - y_min; 245 248 while (x > width || y > height) { 246 249 // System.out.println("zoom: " + zoom + " -> " + x + " " + y); 247 zoom--;250 newZoom--; 248 251 x >>= 1; 249 252 y >>= 1; … … 251 254 x = x_min + (x_max - x_min) / 2; 252 255 y = y_min + (y_max - y_min) / 2; 253 int z = 1 << (MAX_ZOOM - zoom);256 int z = 1 << (MAX_ZOOM - newZoom); 254 257 x /= z; 255 258 y /= z; 256 setDisplayPosition(x, y, zoom);259 setDisplayPosition(x, y, newZoom); 257 260 } 258 261 … … 334 337 x++; 335 338 for (int z = 0; z < x; z++) { 336 if (x_min <= posx && posx <= x_max && y_min <= posy 337 && posy <= y_max) { // tile 339 if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { // tile 338 340 // is 339 341 // visible … … 419 421 return; 420 422 Point2D.Double zoomPos = getPosition(mapPoint); 421 // addMapMarker(new MapMarkerDot(Color.RED, zoomPos.x, zoomPos.y));422 423 jobDispatcher.cancelOutstandingJobs(); // Clearing outstanding load 423 424 // requests … … 450 451 } 451 452 if (!tile.isLoaded()) { 452 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, 453 zoom)); 453 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, zoom)); 454 454 } 455 455 return tile; 456 } 457 458 /** 459 * Every time the zoom level changes this method is called. Override it in 460 * derived implementations for adapting zoom dependent values. The new zoom 461 * level can be obtained via {@link #getZoom()}. 462 * 463 * @param oldZoom 464 * the previous zoom level 465 */ 466 protected void zoomChanged(int oldZoom) { 456 467 } 457 468
Note:
See TracChangeset
for help on using the changeset viewer.