Changeset 13712 in osm for applications
- Timestamp:
- 2009-02-14T01:13:09+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/slippymap
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r13625 r13712 44 44 { 45 45 public int currentZoomLevel = 14; 46 ArrayList<HashMap<SlippyMapKey, SlippyMapTile>> tileStorage = null; 46 //ArrayList<HashMap<SlippyMapKey, SlippyMapTile>> tileStorage = null; 47 private HashMap<SlippyMapKey, SlippyMapTile>[] tileStorage = null; 47 48 48 49 Point[][] pixelpos = new Point[21][21]; … … 59 60 { 60 61 super(tr("Slippy Map")); 61 62 background = true; 62 63 63 64 clearTileStorage(); … … 178 179 */ 179 180 public void increaseZoomLevel() { 180 //TODO max lvl should be in preferences... 181 if(currentZoomLevel < 17) { 181 if(currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl()) { 182 182 currentZoomLevel++; 183 loadAllTiles(); 183 //if(SlippyMapPreferences.getAutoloadTiles()) { 184 // loadAllTiles(); 185 //} 184 186 } 185 187 } … … 191 193 if(currentZoomLevel > 10) { 192 194 currentZoomLevel--; 193 loadAllTiles(); 195 //if(SlippyMapPreferences.getAutoloadTiles()) { 196 // loadAllTiles(); 197 //} 194 198 } 195 199 } 196 200 197 private void clearTileStorage() 198 { 199 tileStorage = new ArrayList<HashMap<SlippyMapKey, SlippyMapTile>>(20); 200 201 for (int i = 0; i < 18; i++) 202 tileStorage.add(new HashMap<SlippyMapKey, SlippyMapTile>()); 201 public void clearTileStorage() 202 { 203 int maxZoom = SlippyMapPreferences.getMaxZoomLvl(); 204 // +1 because of array indexed from 0. 205 tileStorage = new HashMap[maxZoom+1]; 206 207 for (int i = 0; i < maxZoom+1; i++) 208 tileStorage[i] = new HashMap<SlippyMapKey, SlippyMapTile>(); 203 209 } 204 210 … … 240 246 SlippyMapKey key = new SlippyMapKey(x,y); 241 247 242 SlippyMapTile tile = tileStorage .get(currentZoomLevel).get(key);248 SlippyMapTile tile = tileStorage[currentZoomLevel].get(key); 243 249 244 250 if (tile == null) 245 tileStorage .get(currentZoomLevel).put(key,251 tileStorage[currentZoomLevel].put(key, 246 252 tile = new SlippyMapTile(x, y, currentZoomLevel)); 247 253 … … 321 327 { 322 328 SlippyMapKey key = new SlippyMapKey(x,y); 323 SlippyMapTile tile = tileStorage.get(currentZoomLevel).get(key); 329 SlippyMapTile tile; 330 try 331 { 332 tile = tileStorage[currentZoomLevel].get(key); 333 } catch (IndexOutOfBoundsException ex) { 334 throw new RuntimeException("currentZoomLevel=" + currentZoomLevel + " and tile storage array have just size=" + tileStorage.length + " and maxZoomLvl in preferences is " + SlippyMapPreferences.getMaxZoomLvl() + ".", ex); 335 } 324 336 325 337 if (tile == null) 326 338 { 327 tileStorage.get(currentZoomLevel).put(key, 328 tile = new SlippyMapTile(x, y, currentZoomLevel)); 339 tile = new SlippyMapTile(x, y, currentZoomLevel); 340 tileStorage[currentZoomLevel].put(key, tile); 341 if(SlippyMapPreferences.getAutoloadTiles()) { 342 //TODO probably do on background 343 tile.loadImage(); 344 } 329 345 } 330 346 Image img = tile.getImage(); … … 357 373 SlippyMapKey key = new SlippyMapKey(x,y); 358 374 int texty = p.y + 2 + fontHeight; 359 SlippyMapTile tile = tileStorage .get(currentZoomLevel).get(key);375 SlippyMapTile tile = tileStorage[currentZoomLevel].get(key); 360 376 p = pixelpos[x - z12x0 + 1][y - z12y0 + 2]; 361 377 g.drawString("x=" + x + " y=" + y + " z=" + currentZoomLevel + "", p.x + 2, texty); … … 398 414 399 415 if((z12x1 - z12x0 < 2) || (z12y1 - z12y0 < 2)) { 400 increaseZoomLevel(); 416 if(SlippyMapPreferences.getAutozoom()) { 417 increaseZoomLevel(); 418 } 401 419 this.paint(oldg, mv); 402 420 } 403 421 404 422 if((z12x1 - z12x0 > 6) || (z12y1 - z12y0 > 6)) { 405 decreaseZoomLevel(); 423 if(SlippyMapPreferences.getAutozoom()) { 424 decreaseZoomLevel(); 425 } 406 426 this.paint(oldg, mv); 407 427 } … … 438 458 439 459 SlippyMapKey key = new SlippyMapKey(tilex,tiley); 440 SlippyMapTile tile = tileStorage .get(currentZoomLevel).get(key);460 SlippyMapTile tile = tileStorage[currentZoomLevel].get(key); 441 461 if (tile == null) 442 tileStorage .get(currentZoomLevel).put(key,462 tileStorage[currentZoomLevel].put(key, 443 463 tile = new SlippyMapTile(tilex, tiley, currentZoomLevel)); 444 464 return tile; -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferenceSetting.java
r13625 r13712 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import javax.swing.Box; 6 import javax.swing.JCheckBox; 5 7 import javax.swing.JComboBox; 6 8 import javax.swing.JLabel; 9 import javax.swing.JPanel; 10 import javax.swing.JSpinner; 7 11 8 import org.openstreetmap.josm.Main;9 12 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 10 13 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 22 25 */ 23 26 private JComboBox tileSourceCombo; 27 28 private JCheckBox autozoomActive = new JCheckBox(tr("autozoom")); 29 private JCheckBox autoloadTiles = new JCheckBox(tr("autoload tiles")); 30 private JSpinner maxZoomLvl = new JSpinner(); 24 31 25 32 public void addGui(PreferenceDialog gui) 26 33 { 34 //String description = tr("A plugin that adds to JOSM new layer. This layer could render external tiles."); 35 JPanel slippymapTab = gui.createPreferenceTab("slippymap.png", tr("SlippyMap"), tr("Settings for the SlippyMap plugin.")); 36 37 JPanel mapUrlPanel = new JPanel(); 27 38 String[] allMapUrls = SlippyMapPreferences.getAllMapUrls(); 28 39 tileSourceCombo = new JComboBox(allMapUrls); 29 40 tileSourceCombo.setEditable(true); 30 41 String source = SlippyMapPreferences.getMapUrl(); 31 32 for (int i = 0; i < allMapUrls.length; i++) 33 { 34 // System.err.println("Comparing '" + source + "' to '" 35 // + allMapUrls[i]); 36 37 if (source.equals(allMapUrls[i])) 38 { 39 tileSourceCombo.setSelectedIndex(i); 40 break; 41 } 42 } 43 44 gui.display.add(new JLabel(tr("Tile Sources")), GBC.std()); 45 gui.display.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 46 gui.display.add(tileSourceCombo, GBC.eol().fill(GBC.HORIZONTAL)); 42 tileSourceCombo.setSelectedItem(source); 43 mapUrlPanel.add(new JLabel(tr("Tile Sources")), GBC.std()); 44 mapUrlPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 45 mapUrlPanel.add(tileSourceCombo, GBC.eol().fill(GBC.HORIZONTAL)); 46 47 JPanel autozoomPanel = new JPanel(); 48 autozoomPanel.add(new JLabel(tr("Auto zoom: ")), GBC.std()); 49 autozoomPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 50 autozoomPanel.add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 51 52 JPanel autoloadPanel = new JPanel(); 53 autoloadPanel.add(new JLabel(tr("Autoload Tiles: ")), GBC.std()); 54 autoloadPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 55 autoloadPanel.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL)); 56 57 JPanel maxZoomLvlPanel = new JPanel(); 58 maxZoomLvlPanel.add(new JLabel(tr("Max zoom lvl: ")), GBC.std()); 59 maxZoomLvlPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 60 maxZoomLvlPanel.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 61 62 slippymapTab.add(mapUrlPanel, GBC.eol().fill(GBC.HORIZONTAL)); 63 slippymapTab.add(autozoomPanel, GBC.eol().fill(GBC.HORIZONTAL)); 64 slippymapTab.add(autoloadPanel, GBC.eol().fill(GBC.HORIZONTAL)); 65 slippymapTab.add(maxZoomLvlPanel, GBC.eol().fill(GBC.HORIZONTAL)); 66 slippymapTab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 67 68 this.loadSettings(); 47 69 } 48 70 49 71 /** 72 * <p> 73 * Load settings from {@link SlippyMapPreferences} class. Loaded preferences are stored to local GUI components. 74 * Actualy this method loads and sets this params:<br> 75 * <ul> 76 * <li>autozoom - {@link #autozoomActive} - {@link SlippyMapPreferences#getAutozoom()}</li> 77 * <li>autoload - {@link #autoloadTiles} - {@link SlippyMapPreferences#getAutoloadTiles()}</li> 78 * <li>maxZoomLvl - {@link #maxZoomLvl} - {@link SlippyMapPreferences#getMaxZoomLvl()}</li> 79 * </ul> 80 * </p> 81 */ 82 private void loadSettings() { 83 this.autozoomActive.setSelected(SlippyMapPreferences.getAutozoom()); 84 this.autoloadTiles.setSelected(SlippyMapPreferences.getAutoloadTiles()); 85 this.maxZoomLvl.setValue(SlippyMapPreferences.getMaxZoomLvl()); 86 } 87 88 /** 89 * <p> 50 90 * Someone pressed the "ok" button 91 * </p> 92 * <p> 93 * This method saves actual state from GUI objects to actual preferences. 94 * </p> 51 95 */ 52 96 public boolean ok() 53 97 { 54 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_URL, tileSourceCombo.getSelectedItem().toString()); 55 //restart isnt required 98 SlippyMapPreferences.setMapUrl(this.tileSourceCombo.getSelectedItem().toString()); 99 SlippyMapPreferences.setAutozoom(this.autozoomActive.isSelected()); 100 SlippyMapPreferences.setAutoloadTiles(this.autoloadTiles.isSelected()); 101 SlippyMapPreferences.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue()); 102 //restart isn't required 56 103 return false; 57 104 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r13625 r13712 12 12 public class SlippyMapPreferences 13 13 { 14 public static String PREFERENCE_PREFIX = "slippymap";14 public static final String PREFERENCE_PREFIX = "slippymap"; 15 15 16 public static String PREFERENCE_TILE_URL = PREFERENCE_PREFIX + ".tile_url"; 16 private static final String PREFERENCE_TILE_URL = PREFERENCE_PREFIX + ".tile_url"; 17 private static final String PREFERENCE_AUTOZOOM = PREFERENCE_PREFIX + ".autozoom"; 18 private static final String PREFERENCE_AUTOLOADTILES = PREFERENCE_PREFIX + ".autoload_tiles"; 19 private static final String PREFERENCE_MAX_ZOOM_LVL = PREFERENCE_PREFIX + ".max_zoom_lvl"; 17 20 18 21 public static String getMapUrl() … … 28 31 return url; 29 32 } 33 34 public static void setMapUrl(String mapUrl) { 35 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_URL, mapUrl); 36 } 37 38 public static boolean getAutozoom() 39 { 40 String autozoom = Main.pref.get(PREFERENCE_AUTOZOOM); 30 41 42 if (autozoom == null || "".equals(autozoom)) 43 { 44 autozoom = "true"; 45 Main.pref.put(PREFERENCE_AUTOZOOM, autozoom); 46 } 47 48 return Boolean.parseBoolean(autozoom); 49 } 50 51 public static void setAutozoom(boolean autozoom) { 52 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOZOOM, autozoom); 53 } 54 55 public static boolean getAutoloadTiles() 56 { 57 String autoloadTiles = Main.pref.get(PREFERENCE_AUTOLOADTILES); 58 59 if (autoloadTiles == null || "".equals(autoloadTiles)) 60 { 61 autoloadTiles = "true"; 62 Main.pref.put(PREFERENCE_AUTOLOADTILES, autoloadTiles); 63 } 64 65 return Boolean.parseBoolean(autoloadTiles); 66 } 67 68 public static void setAutoloadTiles(boolean autoloadTiles) { 69 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOLOADTILES, autoloadTiles); 70 } 71 72 public static int getMaxZoomLvl() 73 { 74 String maxZoomLvl = Main.pref.get(PREFERENCE_MAX_ZOOM_LVL); 75 76 if (maxZoomLvl == null || "".equals(maxZoomLvl)) 77 { 78 maxZoomLvl = "17"; 79 Main.pref.put(PREFERENCE_MAX_ZOOM_LVL, maxZoomLvl); 80 } 81 82 int navrat; 83 try { 84 navrat = Integer.parseInt(maxZoomLvl); 85 } catch (Exception ex) { 86 throw new RuntimeException("Problem while converting string to int. Converting value of prefetrences " + PREFERENCE_MAX_ZOOM_LVL + ". Value=\"" + maxZoomLvl + "\". Should be an integer. Error: " + ex.getMessage(), ex); 87 } 88 if(navrat > 30) { 89 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 90 navrat = 30; 91 } 92 return navrat; 93 } 94 95 public static void setMaxZoomLvl(int maxZoomLvl) { 96 if(maxZoomLvl > 30) { 97 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 98 maxZoomLvl = 30; 99 } 100 Main.pref.put(SlippyMapPreferences.PREFERENCE_MAX_ZOOM_LVL, "" + maxZoomLvl); 101 } 102 31 103 public static String[] getAllMapUrls() 32 104 {
Note:
See TracChangeset
for help on using the changeset viewer.