Changeset 16157 in osm for applications/editors/josm/plugins/slippymap
- Timestamp:
- 2009-06-26T21:00:40+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r16153 r16157 127 127 } 128 128 })); 129 130 tileOptionMenu.add(new JMenuItem( 131 new AbstractAction(tr("Flush Tile Cache")) { 132 public void actionPerformed(ActionEvent ae) { 133 System.out.print("flushing all tiles..."); 134 for (SlippyMapTile t : tileStorage.values()) { 135 t.dropImage(); 136 } 137 System.out.println("done"); 138 } 139 })); 129 140 // end of adding menu commands 130 141 … … 161 172 /** 162 173 * Zoom in, go closer to map. 174 * 175 * @return true, if zoom increasing was successfull, false othervise 163 176 */ 164 public voidincreaseZoomLevel() {177 public boolean increaseZoomLevel() { 165 178 if (currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl()) { 166 179 currentZoomLevel++; … … 170 183 System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+ 171 184 "MaxZoomLvl ("+SlippyMapPreferences.getMaxZoomLvl()+") reached."); 172 } 185 return false; 186 } 187 return true; 173 188 } 174 189 175 190 /** 176 191 * Zoom out from map. 192 * 193 * @return true, if zoom increasing was successfull, false othervise 177 194 */ 178 public voiddecreaseZoomLevel() {195 public boolean decreaseZoomLevel() { 179 196 if (currentZoomLevel > SlippyMapPreferences.getMinZoomLvl()) { 180 197 Main.debug("decreasing zoom level to: " + currentZoomLevel); … … 183 200 } else { 184 201 System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl reached."); 185 } 202 return false; 203 } 204 return true; 186 205 } 187 206 … … 249 268 void loadAllTiles() { 250 269 MapView mv = Main.map.mapView; 270 int zoom = currentZoomLevel; 251 271 LatLon topLeft = mv.getLatLon(0, 0); 252 272 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); 253 z12x0 = lonToTileX(topLeft.lon() );254 z12x1 = lonToTileX(botRight.lon() );255 z12y0 = latToTileY(topLeft.lat() );256 z12y1 = latToTileY(botRight.lat() );273 z12x0 = lonToTileX(topLeft.lon(), zoom); 274 z12x1 = lonToTileX(botRight.lon(), zoom); 275 z12y0 = latToTileY(topLeft.lat(), zoom); 276 z12y1 = latToTileY(botRight.lat(), zoom); 257 277 if (z12x0 > z12x1) { 258 278 int tmp = z12x0; … … 365 385 g = bufferImage.getGraphics(); 366 386 367 z12x0 = lonToTileX(topLeft.lon()); 368 z12x1 = lonToTileX(botRight.lon()); 369 z12y0 = latToTileY(topLeft.lat()); 370 z12y1 = latToTileY(botRight.lat()); 387 int zoom = currentZoomLevel; 388 z12x0 = lonToTileX(topLeft.lon(), zoom); 389 z12x1 = lonToTileX(botRight.lon(), zoom); 390 z12y0 = latToTileY(topLeft.lat(), zoom); 391 z12y1 = latToTileY(botRight.lat(), zoom); 371 392 372 393 if (z12x0 > z12x1) { … … 387 408 388 409 for (int x = z12x0 - 1; x <= z12x1 + 1; x++) { 389 double lon = tileXToLon(x );410 double lon = tileXToLon(x, zoom); 390 411 for (int y = z12y0 - 1; y <= z12y1 + 1; y++) { 391 LatLon tmpLL = new LatLon(tileYToLat(y ), lon);412 LatLon tmpLL = new LatLon(tileYToLat(y, zoom), lon); 392 413 pixelpos[x - z12x0 + 1][y - z12y0 + 1] = mv.getPoint(Main.proj 393 414 .latlon2eastNorth(tmpLL)); … … 605 626 } 606 627 607 private int latToTileY(double lat ) {628 private int latToTileY(double lat, int zoom) { 608 629 double l = lat / 180 * Math.PI; 609 630 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l))); 610 return (int) (Math.pow(2.0, currentZoomLevel- 1) * (Math.PI - pf) / Math.PI);611 } 612 613 private int lonToTileX(double lon ) {614 return (int) (Math.pow(2.0, currentZoomLevel- 3) * (lon + 180.0) / 45.0);615 } 616 617 private double tileYToLat(int y ) {631 return (int) (Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI); 632 } 633 634 private int lonToTileX(double lon, int zoom) { 635 return (int) (Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0); 636 } 637 638 private double tileYToLat(int y, int zoom) { 618 639 return Math.atan(Math.sinh(Math.PI 619 - (Math.PI * y / Math.pow(2.0, currentZoomLevel- 1))))640 - (Math.PI * y / Math.pow(2.0, zoom - 1)))) 620 641 * 180 / Math.PI; 621 642 } 622 643 623 private double tileXToLon(int x ) {624 return x * 45.0 / Math.pow(2.0, currentZoomLevel- 3) - 180.0;644 private double tileXToLon(int x, int zoom) { 645 return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0; 625 646 } 626 647
Note:
See TracChangeset
for help on using the changeset viewer.