Changeset 16158 in osm for applications
- Timestamp:
- 2009-06-26T21:44:57+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
r16157 r16158 12 12 import java.awt.event.MouseEvent; 13 13 import java.awt.image.ImageObserver; 14 import java.util.ArrayList; 14 15 import java.util.Comparator; 15 import java.util.HashMap; 16 import java.util.Hashtable; 17 import java.util.List; 16 18 import java.util.TreeSet; 17 19 … … 50 52 */ 51 53 public int currentZoomLevel = SlippyMapPreferences.getMinZoomLvl(); 52 private Hash Map<SlippyMapKey, SlippyMapTile> tileStorage = null;54 private Hashtable<SlippyMapKey, SlippyMapTile> tileStorage = null; 53 55 54 56 Point[][] pixelpos = new Point[21][21]; … … 209 211 // the setting isnt saved yet. 210 212 int maxZoom = 30; // SlippyMapPreferences.getMaxZoomLvl(); 211 tileStorage = new Hash Map<SlippyMapKey, SlippyMapTile>();213 tileStorage = new Hashtable<SlippyMapKey, SlippyMapTile>(); 212 214 213 215 checkTileStorage(); … … 266 268 } 267 269 270 synchronized SlippyMapTile getTile(int x, int y, int zoom) { 271 SlippyMapKey key = new SlippyMapKey(x, y, zoom); 272 if (!key.valid) { 273 key = null; 274 } 275 return tileStorage.get(key); 276 } 277 278 synchronized SlippyMapTile putTile(SlippyMapTile tile, int x, int y, int zoom) { 279 SlippyMapKey key = new SlippyMapKey(x, y, zoom); 280 if (!key.valid) { 281 key = null; 282 } 283 return tileStorage.put(key, tile); 284 } 285 286 synchronized SlippyMapTile getOrCreateTile(int x, int y, int zoom) { 287 SlippyMapTile tile = getTile(x, y, zoom); 288 if (tile != null) { 289 return tile; 290 } 291 tile = new SlippyMapTile(x, y, zoom); 292 putTile(tile, x, y, zoom); 293 return tile; 294 } 295 268 296 void loadAllTiles() { 269 297 MapView mv = Main.map.mapView; … … 356 384 } 357 385 386 private class Tile { 387 public int x; 388 public int y; 389 390 Tile(int x, int y) { 391 this.x = x; 392 this.y = y; 393 } 394 395 public Point pixelPos(int zoom) { 396 double lon = tileXToLon(this.x, zoom); 397 LatLon tmpLL = new LatLon(tileYToLat(this.y, zoom), lon); 398 MapView mv = Main.map.mapView; 399 return mv.getPoint(Main.proj.latlon2eastNorth(tmpLL)); 400 } 401 } 402 403 private class TileSet { 404 int z12x0, z12x1, z12y0, z12y1; 405 int zoom; 406 407 TileSet(LatLon topLeft, LatLon botRight, int zoom) { 408 this.zoom = zoom; 409 z12x0 = lonToTileX(topLeft.lon(), zoom); 410 z12x1 = lonToTileX(botRight.lon(), zoom); 411 z12y0 = latToTileY(topLeft.lat(), zoom); 412 z12y1 = latToTileY(botRight.lat(), zoom); 413 if (z12x0 > z12x1) { 414 int tmp = z12x0; 415 z12x0 = z12x1; 416 z12x1 = tmp; 417 } 418 if (z12y0 > z12y1) { 419 int tmp = z12y0; 420 z12y0 = z12y1; 421 z12y1 = tmp; 422 } 423 } 424 425 int tilesSpanned() { 426 int x_span = z12x1 - z12x0; 427 int y_span = z12y1 - z12y0; 428 return x_span * y_span; 429 } 430 431 /* 432 * This is pretty silly. Should probably just be implemented as an 433 * iterator to keep from having to instantiate all these tiles. 434 */ 435 List<Tile> allTiles() 436 { 437 List<Tile> ret = new ArrayList<Tile>(); 438 for (int x = z12x0 - 1; x <= z12x1 + 1; x++) { 439 if (x < 0) 440 continue; 441 for (int y = z12y0 - 1; y <= z12y1 + 1; y++) { 442 if (y < 0) 443 continue; 444 Tile t = new Tile(x, y); 445 ret.add(t); 446 } 447 } 448 return ret; 449 } 450 451 boolean topTile(Tile t) { 452 if (t.y == z12y0 - 1) 453 return true; 454 return false; 455 } 456 457 boolean leftTile(Tile t) { 458 if (t.x == z12x0 - 1) 459 return true; 460 return false; 461 } 462 } 463 358 464 /** 359 465 */
Note:
See TracChangeset
for help on using the changeset viewer.