Changeset 13625 in osm for applications/editors/josm/plugins/slippymap/src
- Timestamp:
- 2009-02-09T08:42:12+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r13497 r13625 35 35 /** 36 36 * Class that displays a slippy map layer. 37 * 37 * 38 38 * @author Frederik Ramm <frederik@remote.org> 39 * 39 * @author LuVar <lubomir.varga@freemap.sk> 40 * 40 41 */ 41 42 public class SlippyMapLayer extends Layer implements ImageObserver, 42 43 PreferenceChangedListener 43 44 { 44 ArrayList<HashMap<Integer, SlippyMapTile>> tileStorage = null; 45 public int currentZoomLevel = 14; 46 ArrayList<HashMap<SlippyMapKey, SlippyMapTile>> tileStorage = null; 45 47 46 48 Point[][] pixelpos = new Point[21][21]; … … 57 59 { 58 60 super(tr("Slippy Map")); 59 61 background = true; 60 62 61 63 clearTileStorage(); … … 110 112 } 111 113 })); 114 115 //increase and decrease commands 116 tileOptionMenu.add(new JMenuItem(new AbstractAction(tr("Increase zoom")) 117 { 118 public void actionPerformed(ActionEvent ae) 119 { 120 increaseZoomLevel(); 121 needRedraw = true; 122 Main.map.repaint(); 123 } 124 })); 125 126 tileOptionMenu.add(new JMenuItem(new AbstractAction(tr("Decrease zoom")) 127 { 128 public void actionPerformed(ActionEvent ae) 129 { 130 decreaseZoomLevel(); 131 needRedraw = true; 132 Main.map.repaint(); 133 } 134 })); 135 //end of adding menu commands 112 136 113 137 SwingUtilities.invokeLater(new Runnable() … … 150 174 } 151 175 176 /** 177 * Zoom in, go closer to map. 178 */ 179 public void increaseZoomLevel() { 180 //TODO max lvl should be in preferences... 181 if(currentZoomLevel < 17) { 182 currentZoomLevel++; 183 loadAllTiles(); 184 } 185 } 186 187 /** 188 * Zoom out from map. 189 */ 190 public void decreaseZoomLevel() { 191 if(currentZoomLevel > 10) { 192 currentZoomLevel--; 193 loadAllTiles(); 194 } 195 } 196 152 197 private void clearTileStorage() 153 198 { 154 tileStorage = new ArrayList<HashMap< Integer, SlippyMapTile>>(20);199 tileStorage = new ArrayList<HashMap<SlippyMapKey, SlippyMapTile>>(20); 155 200 156 201 for (int i = 0; i < 18; i++) 157 tileStorage.add(new HashMap< Integer, SlippyMapTile>());202 tileStorage.add(new HashMap<SlippyMapKey, SlippyMapTile>()); 158 203 } 159 204 … … 179 224 z12y1 = tmp; 180 225 } 181 if (z12x1 - z12x0 > 18) 226 //if there is more than 18 tiles on screen in any direction, do not load all tiles! 227 if (z12x1 - z12x0 > 18) { 228 System.out.println("Not downloading all tiles because there is more than 18 tiles on X axis!"); 182 229 return; 183 if (z12y1 - z12y0 > 18) 184 return; 230 } 231 if (z12y1 - z12y0 > 18) { 232 System.out.println("Not downloading all tiles because there is more than 18 tiles on Y axis!"); 233 return; 234 } 235 185 236 for (int x = z12x0 - 1; x <= z12x1; x++) 186 237 { 187 238 for (int y = z12y0 - 1; y <= z12y1; y++) 188 239 { 189 intkey =(y << 19) + x;190 191 SlippyMapTile tile = tileStorage.get( 12).get(key);240 SlippyMapKey key = new SlippyMapKey(x,y); 241 242 SlippyMapTile tile = tileStorage.get(currentZoomLevel).get(key); 192 243 193 244 if (tile == null) 194 tileStorage.get( 12).put(key,195 tile = new SlippyMapTile(x, y, 12));245 tileStorage.get(currentZoomLevel).put(key, 246 tile = new SlippyMapTile(x, y, currentZoomLevel)); 196 247 197 248 if (tile.getImage() == null) … … 244 295 z12y1 = tmp; 245 296 } 246 297 247 298 if (z12x1 - z12x0 > 18) 248 299 return; … … 269 320 for (int y = z12y0 - 1; y <= z12y1; y++) 270 321 { 271 intkey =(y << 19) + x;272 SlippyMapTile tile = tileStorage.get( 12).get(key);322 SlippyMapKey key = new SlippyMapKey(x,y); 323 SlippyMapTile tile = tileStorage.get(currentZoomLevel).get(key); 273 324 274 325 if (tile == null) 275 326 { 276 tileStorage.get( 12).put(key,277 tile = new SlippyMapTile(x, y, 12));327 tileStorage.get(currentZoomLevel).put(key, 328 tile = new SlippyMapTile(x, y, currentZoomLevel)); 278 329 } 279 330 Image img = tile.getImage(); … … 304 355 for (int y = z12y0 - 1; y <= z12y1; y++) 305 356 { 306 intkey =(y << 19) + x;357 SlippyMapKey key = new SlippyMapKey(x,y); 307 358 int texty = p.y + 2 + fontHeight; 308 SlippyMapTile tile = tileStorage.get( 12).get(key);359 SlippyMapTile tile = tileStorage.get(currentZoomLevel).get(key); 309 360 p = pixelpos[x - z12x0 + 1][y - z12y0 + 2]; 310 g.drawString("x=" + x + " y=" + y + " z= 12", p.x + 2, texty);361 g.drawString("x=" + x + " y=" + y + " z=" + currentZoomLevel + "", p.x + 2, texty); 311 362 texty += 1 + fontHeight; 312 363 if ((x % 32 == 0) && (y % 32 == 0)) … … 346 397 oldg.drawImage(bufferImage, 0, 0, null); 347 398 348 } 399 if((z12x1 - z12x0 < 2) || (z12y1 - z12y0 < 2)) { 400 increaseZoomLevel(); 401 this.paint(oldg, mv); 402 } 403 404 if((z12x1 - z12x0 > 6) || (z12y1 - z12y0 > 6)) { 405 decreaseZoomLevel(); 406 this.paint(oldg, mv); 407 } 408 409 g.drawString("currentZoomLevel=" + currentZoomLevel, 120, 120); 410 }//end of paint metod 349 411 350 412 SlippyMapTile getTileForPixelpos(int px, int py) … … 375 437 return null; 376 438 377 intkey =(tiley << 19) + tilex;378 SlippyMapTile tile = tileStorage.get( 12).get(key);439 SlippyMapKey key = new SlippyMapKey(tilex,tiley); 440 SlippyMapTile tile = tileStorage.get(currentZoomLevel).get(key); 379 441 if (tile == null) 380 tileStorage.get( 12).put(key,381 tile = new SlippyMapTile(tilex, tiley, 12));442 tileStorage.get(currentZoomLevel).put(key, 443 tile = new SlippyMapTile(tilex, tiley, currentZoomLevel)); 382 444 return tile; 383 445 } … … 435 497 double l = lat / 180 * Math.PI; 436 498 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l))); 437 return (int) ( 2048.0* (Math.PI - pf) / Math.PI);499 return (int) (Math.pow(2.0, currentZoomLevel-1) * (Math.PI - pf) / Math.PI); 438 500 } 439 501 440 502 private int lonToTileX(double lon) 441 503 { 442 return (int) ( 512.0* (lon + 180.0) / 45.0);504 return (int) (Math.pow(2.0, currentZoomLevel-3) * (lon + 180.0) / 45.0); 443 505 } 444 506 445 507 private double tileYToLat(int y) 446 508 { 447 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / 2048.0))) * 180509 return Math.atan(Math.sinh(Math.PI - (Math.PI * y / Math.pow(2.0, currentZoomLevel-1)))) * 180 448 510 / Math.PI; 449 511 } … … 451 513 private double tileXToLon(int x) 452 514 { 453 return x * 45.0 / 512.0- 180.0;515 return x * 45.0 / Math.pow(2.0, currentZoomLevel-3) - 180.0; 454 516 } 455 517 … … 468 530 /* 469 531 * (non-Javadoc) 470 * 532 * 471 533 * @see org.openstreetmap.josm.data.Preferences.PreferenceChangedListener#preferenceChanged(java.lang.String, 472 534 * java.lang.String) -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPlugin.java
r13497 r13625 16 16 public SlippyMapPlugin() 17 17 { 18 19 18 } 20 19 -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferenceSetting.java
r13497 r13625 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component;6 7 import javax.swing.DefaultListCellRenderer;8 5 import javax.swing.JComboBox; 9 6 import javax.swing.JLabel; 10 import javax.swing.JList;11 import javax.swing.ListCellRenderer;12 import javax.swing.UIManager;13 import javax.swing.UIManager.LookAndFeelInfo;14 7 15 8 import org.openstreetmap.josm.Main; … … 24 17 * 25 18 */ 26 public class SlippyMapPreferenceSetting implements PreferenceSetting 27 { 19 public class SlippyMapPreferenceSetting implements PreferenceSetting { 28 20 /** 29 21 * ComboBox with all known tile sources. … … 60 52 public boolean ok() 61 53 { 62 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_URL, tileSourceCombo 63 .getSelectedItem().toString());54 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_URL, tileSourceCombo.getSelectedItem().toString()); 55 //restart isnt required 64 56 return false; 65 57 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r13497 r13625 5 5 /** 6 6 * Preferences for Slippy Map Tiles 7 * 7 * 8 8 * @author Hakan Tandogan <hakan@gurkensalat.com> 9 * 9 * @author LuVar <lubomir.varga@freemap.sk> 10 * 10 11 */ 11 12 public class SlippyMapPreferences … … 14 15 15 16 public static String PREFERENCE_TILE_URL = PREFERENCE_PREFIX + ".tile_url"; 16 17 17 18 public static String getMapUrl() 18 19 { … … 35 36 "http://tah.openstreetmap.org/Tiles/maplint", // maplint 36 37 "http://tile.openstreetmap.org", // mapnik 37 "http://hypercube.telascience.org/tiles/1.0.0/coastline" // coastline 38 "http://hypercube.telascience.org/tiles/1.0.0/coastline", // coastline 39 "http://www.freemap.sk/layers/allinone/?", //freemapy.sk 40 "http://www.freemap.sk/layers/tiles/?", //freemapy.sk pokus 2 38 41 }; 39 42 return defaultTileSources; -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java
r13497 r13625 13 13 /** 14 14 * Class that contains information about one single slippy map tile. 15 * 15 * 16 16 * @author Frederik Ramm <frederik@remote.org> 17 * 17 * @author LuVar <lubomir.varga@freemap.sk> 18 * 18 19 */ 19 20 public class SlippyMapTile … … 21 22 private Image tileImage; 22 23 23 int 24 int 25 int 24 int x; 25 int y; 26 int z; 26 27 27 28 private String metadata; … … 45 46 URL imageURL = new URL(SlippyMapPreferences.getMapUrl() + "/" + z 46 47 + "/" + x + "/" + y + ".png"); 47 48 48 49 tileImage = Toolkit.getDefaultToolkit().createImage(imageURL); 49 50 } … … 65 66 URL dev = new URL( 66 67 "http://tah.openstreetmap.org/Tiles/info_short.php?x=" + x 67 + "&y=" + y + "&z= 12/layer=tile");68 + "&y=" + y + "&z=" + z + "/layer=tile"); 68 69 URLConnection devc = dev.openConnection(); 69 70 BufferedReader in = new BufferedReader(new InputStreamReader(devc
Note:
See TracChangeset
for help on using the changeset viewer.