Changeset 18355 in osm
- Timestamp:
- 2009-10-29T00:00:08+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r18354 r18355 63 63 64 64 protected MemoryTileCache tileCache; 65 protected TileSource tileSource = new OsmTileSource.Mapnik();65 protected TileSource tileSource; 66 66 protected TileLoader tileLoader; 67 67 JobDispatcher jobDispatcher = JobDispatcher.getInstance(); … … 81 81 return tileCache; 82 82 } 83 void clearTileStorage() 84 { 85 out("clearing tile storage"); 83 void clearTileCache() 84 { 85 if (debug) 86 out("clearing tile storage"); 86 87 tileCache = new MemoryTileCache(); 87 88 tileCache.setCacheSize(2000); … … 109 110 } 110 111 112 void newTileStorage() 113 { 114 int origZoom = currentZoomLevel; 115 tileSource = SlippyMapPreferences.getMapSource(); 116 // The minimum should also take care of integer parsing 117 // errors which would leave us with a zoom of -1 otherwise 118 if (tileSource.getMaxZoom() < currentZoomLevel) 119 currentZoomLevel = tileSource.getMaxZoom(); 120 if (tileSource.getMinZoom() > currentZoomLevel) 121 currentZoomLevel = tileSource.getMinZoom(); 122 if (currentZoomLevel != origZoom) { 123 out("changed currentZoomLevel loading new tile store from " + origZoom + " to " + currentZoomLevel); 124 out("tileSource.getMinZoom(): " + tileSource.getMinZoom()); 125 out("tileSource.getMaxZoom(): " + tileSource.getMaxZoom()); 126 SlippyMapPreferences.setLastZoom(currentZoomLevel); 127 } 128 clearTileCache(); 129 //tileLoader = new OsmTileLoader(this); 130 tileLoader = new OsmFileCacheTileLoader(this); 131 } 132 111 133 @SuppressWarnings("serial") 112 134 public SlippyMapLayer() { … … 117 139 118 140 currentZoomLevel = SlippyMapPreferences.getLastZoom(); 119 if (currentZoomLevel <= 0) 120 currentZoomLevel = SlippyMapPreferences.getMinZoomLvl(); 121 clearTileStorage(); 122 //tileLoader = new OsmTileLoader(this); 123 tileLoader = new OsmFileCacheTileLoader(this); 141 newTileStorage(); 124 142 125 143 tileOptionMenu = new JPopupMenu(); … … 168 186 tr("Load All Tiles")) { 169 187 public void actionPerformed(ActionEvent ae) { 170 loadAllTiles( );188 loadAllTiles(true); 171 189 redraw(); 172 190 } … … 191 209 192 210 tileOptionMenu.add(new JMenuItem( 211 new AbstractAction(tr("Snap to tile size")) { 212 public void actionPerformed(ActionEvent ae) { 213 double new_factor = Math.sqrt(lastImageScale); 214 if (debug) 215 out("tile snap: scale was: " + lastImageScale + ", new factor: " + new_factor); 216 Main.map.mapView.zoomToFactor(new_factor); 217 redraw(); 218 } 219 })); 220 // end of adding menu commands 221 222 tileOptionMenu.add(new JMenuItem( 193 223 new AbstractAction(tr("Flush Tile Cache")) { 194 224 public void actionPerformed(ActionEvent ae) { 195 225 System.out.print("flushing all tiles..."); 196 clearTile Storage();226 clearTileCache(); 197 227 System.out.println("done"); 198 228 } … … 238 268 SlippyMapPreferences.setLastZoom(currentZoomLevel); 239 269 } 270 271 int getMaxZoomLvl() 272 { 273 int ret = SlippyMapPreferences.getMaxZoomLvl(); 274 if (tileSource.getMaxZoom() < ret) 275 ret = tileSource.getMaxZoom(); 276 return ret; 277 } 278 279 int getMinZoomLvl() 280 { 281 int ret = SlippyMapPreferences.getMinZoomLvl(); 282 if (tileSource.getMinZoom() > ret) 283 ret = tileSource.getMinZoom(); 284 return ret; 285 } 286 240 287 /** 241 288 * Zoom in, go closer to map. … … 245 292 public boolean zoomIncreaseAllowed() 246 293 { 247 boolean zia = currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl();294 boolean zia = currentZoomLevel < this.getMaxZoomLvl(); 248 295 if (debug) 249 out("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + SlippyMapPreferences.getMaxZoomLvl() );296 out("zoomIncreaseAllowed(): " + zia + " " + currentZoomLevel + " vs. " + this.getMaxZoomLvl() ); 250 297 return zia; 251 298 } … … 260 307 } else { 261 308 System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+ 262 "MaxZoomLvl ("+ SlippyMapPreferences.getMaxZoomLvl()+") reached.");309 "MaxZoomLvl ("+this.getMaxZoomLvl()+") reached."); 263 310 return false; 264 311 } … … 273 320 public boolean zoomDecreaseAllowed() 274 321 { 275 return currentZoomLevel > SlippyMapPreferences.getMinZoomLvl();322 return currentZoomLevel > this.getMinZoomLvl(); 276 323 } 277 324 public boolean decreaseZoomLevel() { 278 int minZoom = SlippyMapPreferences.getMinZoomLvl();325 int minZoom = this.getMinZoomLvl(); 279 326 lastImageScale = null; 280 327 if (zoomDecreaseAllowed()) { … … 315 362 { 316 363 if (tile == null) 364 return false; 365 if (tile.hasError()) 317 366 return false; 318 367 if (tile.isLoaded()) … … 328 377 } 329 378 330 void loadAllTiles( ) {379 void loadAllTiles(boolean force) { 331 380 MapView mv = Main.map.mapView; 332 381 LatLon topLeft = mv.getLatLon(0, 0); … … 341 390 return; 342 391 } 343 ts.loadAllTiles( );392 ts.loadAllTiles(force); 344 393 } 345 394 … … 422 471 LatLon topLeft = tileLatLon(topLeftTile); 423 472 LatLon botRight = tileLatLon(botRightTile); 473 474 if (!autoZoomEnabled()) 475 return 0; 476 if (!SlippyMapPreferences.getAutoloadTiles()) 477 return 0; 424 478 425 479 /* … … 437 491 for (int zoomOff : otherZooms) { 438 492 int zoom = currentZoomLevel + zoomOff; 439 if ((zoom < SlippyMapPreferences.getMinZoomLvl()) ||440 (zoom > SlippyMapPreferences.getMaxZoomLvl())) {493 if ((zoom < this.getMinZoomLvl()) || 494 (zoom > this.getMaxZoomLvl())) { 441 495 continue; 442 496 } … … 612 666 return ret; 613 667 } 614 void loadAllTiles( )668 void loadAllTiles(boolean force) 615 669 { 616 670 List<Tile> tiles = this.allTiles(true); 671 boolean autoload = SlippyMapPreferences.getAutoloadTiles(); 672 if (!autoload && !force) 673 return; 617 674 int nr_queued = 0; 618 675 for (Tile t : tiles) { … … 697 754 return; 698 755 699 ts.loadAllTiles( );756 ts.loadAllTiles(false); 700 757 701 758 int fontHeight = g.getFontMetrics().getHeight(); … … 736 793 out("autozoom increase: scale: " + lastImageScale); 737 794 increaseZoomLevel(); 795 this.paint(oldg, mv); 738 796 } 739 this.paint(oldg, mv);740 797 // If each source image pixel is being squished into > 0.32 741 798 // of a drawn pixels, zoom out. … … 745 802 out("autozoom decrease: scale: " + lastImageScale); 746 803 decreaseZoomLevel(); 804 this.paint(oldg, mv); 747 805 } 748 this.paint(oldg, mv);749 806 } 750 807 } … … 767 824 TileSet ts = new TileSet(topLeft, botRight, z); 768 825 769 ts.loadAllTiles( ); // make sure there are tile objects for all tiles826 ts.loadAllTiles(false); // make sure there are tile objects for all tiles 770 827 Tile clickedTile = null; 771 828 Point p1 = null, p2 = null; … … 866 923 autoZoomPopup.setSelected(SlippyMapPreferences.getAutozoom()); 867 924 } 925 if (key.equals(SlippyMapPreferences.PREFERENCE_TILE_SOURCE)) { 926 newTileStorage(); 927 } 868 928 redraw(); 869 929 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferenceSetting.java
r14730 r18355 10 10 import javax.swing.JSlider; 11 11 import javax.swing.JSpinner; 12 import javax.swing.SpinnerNumberModel; 13 import java.util.Collection; 14 15 import org.openstreetmap.gui.jmapviewer.*; 16 import org.openstreetmap.gui.jmapviewer.interfaces.*; 12 17 13 18 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; … … 29 34 private JCheckBox autozoomActive = new JCheckBox(tr("autozoom")); 30 35 private JCheckBox autoloadTiles = new JCheckBox(tr("autoload tiles")); 31 private JSpinner maxZoomLvl = new JSpinner(); 36 private JSpinner maxZoomLvl; 37 private JSpinner minZoomLvl = new JSpinner(); 32 38 private JSlider fadeBackground = new JSlider(0, 100); 33 39 34 40 public void addGui(PreferenceDialog gui) 35 41 { 42 minZoomLvl = new JSpinner(new SpinnerNumberModel(SlippyMapPreferences.DEFAULT_MIN_ZOOM, SlippyMapPreferences.MIN_ZOOM, SlippyMapPreferences.MAX_ZOOM, 1)); 43 maxZoomLvl = new JSpinner(new SpinnerNumberModel(SlippyMapPreferences.DEFAULT_MAX_ZOOM, SlippyMapPreferences.MIN_ZOOM, SlippyMapPreferences.MAX_ZOOM, 1)); 36 44 //String description = tr("A plugin that adds to JOSM new layer. This layer could render external tiles."); 37 45 JPanel slippymapTab = gui.createPreferenceTab("slippymap.png", tr("SlippyMap"), tr("Settings for the SlippyMap plugin.")); 38 String[] allMapUrls = SlippyMapPreferences.getAllMapUrls();39 tileSourceCombo = new JComboBox(allMapUrls);40 tileSourceCombo .setEditable(true);41 String source = SlippyMapPreferences.getMapUrl();42 tileSourceCombo.setSelectedItem( source);46 Collection<TileSource> allSources = SlippyMapPreferences.getAllMapSources(); 47 //Collection<String> allSources = SlippyMapPreferences.getAllMapNames(); 48 tileSourceCombo = new JComboBox(allSources.toArray()); 49 //tileSourceCombo.setEditable(true); 50 tileSourceCombo.setSelectedItem(SlippyMapPreferences.getMapSource()); 43 51 slippymapTab.add(new JLabel(tr("Tile Sources")), GBC.std()); 44 52 slippymapTab.add(GBC.glue(5, 0), GBC.std()); … … 53 61 slippymapTab.add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL)); 54 62 63 slippymapTab.add(new JLabel(tr("Min zoom lvl: ")), GBC.std()); 64 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 65 slippymapTab.add(this.minZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 66 55 67 slippymapTab.add(new JLabel(tr("Max zoom lvl: ")), GBC.std()); 56 68 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 57 69 slippymapTab.add(this.maxZoomLvl, GBC.eol().fill(GBC.HORIZONTAL)); 58 70 59 71 slippymapTab.add(new JLabel(tr("Fade background: ")), GBC.std()); 60 72 slippymapTab.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); … … 75 87 * <li>autoload - {@link #autoloadTiles} - {@link SlippyMapPreferences#getAutoloadTiles()}</li> 76 88 * <li>maxZoomLvl - {@link #maxZoomLvl} - {@link SlippyMapPreferences#getMaxZoomLvl()}</li> 89 * <li>minZoomLvl - {@link #minZoomLvl} - {@link SlippyMapPreferences#getMaxZoomLvl()}</li> 77 90 * </ul> 78 91 * </p> … … 82 95 this.autoloadTiles.setSelected(SlippyMapPreferences.getAutoloadTiles()); 83 96 this.maxZoomLvl.setValue(SlippyMapPreferences.getMaxZoomLvl()); 97 this.minZoomLvl.setValue(SlippyMapPreferences.getMinZoomLvl()); 84 98 this.fadeBackground.setValue(Math.round(SlippyMapPreferences.getFadeBackground()*100f)); 85 99 } … … 95 109 public boolean ok() 96 110 { 97 SlippyMapPreferences.setMap Url(this.tileSourceCombo.getSelectedItem().toString());111 SlippyMapPreferences.setMapSource((TileSource)this.tileSourceCombo.getSelectedItem()); 98 112 SlippyMapPreferences.setAutozoom(this.autozoomActive.isSelected()); 99 113 SlippyMapPreferences.setAutoloadTiles(this.autoloadTiles.isSelected()); 100 114 SlippyMapPreferences.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue()); 115 SlippyMapPreferences.setMinZoomLvl((Integer)this.minZoomLvl.getValue()); 101 116 SlippyMapPreferences.setFadeBackground(this.fadeBackground.getValue()/100f); 102 117 //restart isn't required -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r18354 r18355 2 2 3 3 import org.openstreetmap.josm.Main; 4 import java.util.List; 5 import java.util.ArrayList; 6 import java.util.Collection; 7 import java.util.Map; 8 import org.openstreetmap.gui.jmapviewer.*; 9 import org.openstreetmap.gui.jmapviewer.interfaces.*; 4 10 5 11 /** 6 12 * Preferences for Slippy Map Tiles 7 * 13 * 8 14 * @author Hakan Tandogan <hakan@gurkensalat.com> 9 15 * @author LuVar <lubomir.varga@freemap.sk> 10 * 16 * 11 17 */ 12 18 public class SlippyMapPreferences … … 14 20 public static final String PREFERENCE_PREFIX = "slippymap"; 15 21 16 public static final String PREFERENCE_TILE_URL = PREFERENCE_PREFIX + ".tile_url"; 22 public static final String PREFERENCE_TILE_CUSTOM_SOURCE = PREFERENCE_PREFIX + ".custom_tile_source_"; 23 public static final String PREFERENCE_TILE_SOURCE = PREFERENCE_PREFIX + ".tile_source"; 17 24 public static final String PREFERENCE_AUTOZOOM = PREFERENCE_PREFIX + ".autozoom"; 18 25 public static final String PREFERENCE_AUTOLOADTILES = PREFERENCE_PREFIX + ".autoload_tiles"; … … 22 29 public static final String PREFERENCE_FADE_BACKGROUND = PREFERENCE_PREFIX + ".fade_background"; 23 30 public static final String PREFERENCE_DRAW_DEBUG = PREFERENCE_PREFIX + ".draw_debug"; 24 25 public static String getMapUrl() 26 { 27 String url = Main.pref.get(PREFERENCE_TILE_URL); 28 29 if (url == null || "".equals(url)) 30 { 31 url = "http://tah.openstreetmap.org/Tiles/tile"; // t@h 32 Main.pref.put(PREFERENCE_TILE_URL, url); 33 } 34 35 return url; 36 } 37 38 public static void setMapUrl(String mapUrl) { 39 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_URL, mapUrl); 40 } 41 31 32 public static final int MAX_ZOOM = 30; 33 public static final int MIN_ZOOM = 2; 34 public static final int DEFAULT_MAX_ZOOM = 20; 35 public static final int DEFAULT_MIN_ZOOM = 2; 36 37 public static TileSource getMapSource() 38 { 39 String name = Main.pref.get(PREFERENCE_TILE_SOURCE); 40 List<TileSource> sources = SlippyMapPreferences.getAllMapSources(); 41 TileSource source = sources.get(0); 42 if (name == null || "".equals(name)) { 43 name = source.getName(); 44 Main.pref.put(PREFERENCE_TILE_SOURCE, name); 45 } 46 for (TileSource s : sources) { 47 if (!name.equals(s.getName())) 48 continue; 49 source = s; 50 break; 51 } 52 return source; 53 } 54 55 public static void setMapSource(TileSource source) { 56 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_SOURCE, source.getName()); 57 } 58 42 59 public static boolean getAutozoom() 43 60 { … … 52 69 return Boolean.parseBoolean(autozoom); 53 70 } 54 71 55 72 public static void setAutozoom(boolean autozoom) { 56 73 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOZOOM, autozoom); 57 74 } 58 75 59 76 public static void setDrawDebug(boolean drawDebug) { 60 77 Main.pref.put(SlippyMapPreferences.PREFERENCE_DRAW_DEBUG, drawDebug); 61 78 } 62 79 63 80 public static void setLastZoom(int zoom) { 64 81 Main.pref.put(SlippyMapPreferences.PREFERENCE_LAST_ZOOM, ""+zoom); … … 86 103 return Boolean.parseBoolean(drawDebug); 87 104 } 88 105 89 106 public static boolean getAutoloadTiles() 90 107 { … … 99 116 return Boolean.parseBoolean(autoloadTiles); 100 117 } 101 118 102 119 public static void setFadeBackground(float fadeBackground) { 103 120 Main.pref.put(SlippyMapPreferences.PREFERENCE_FADE_BACKGROUND, fadeBackground + ""); … … 105 122 106 123 /** 107 * 124 * 108 125 * @return number between 0 and 1, inclusive 109 126 */ … … 116 133 Main.pref.put(PREFERENCE_FADE_BACKGROUND, fadeBackground); 117 134 } 118 135 119 136 float parsed; 120 137 try { … … 135 152 return parsed; 136 153 } 137 154 138 155 public static void setAutoloadTiles(boolean autoloadTiles) { 139 156 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOLOADTILES, autoloadTiles); 140 157 } 141 158 159 private static int getIntPref(String prefName, int def) 160 { 161 int pref; 162 try { 163 //Should we use Main.pref.getInteger(str)? 164 pref = Main.pref.getInteger(prefName, def); 165 } catch (Exception ex) { 166 String str = Main.pref.get(prefName); 167 Main.pref.put(prefName, null); 168 throw new RuntimeException("Problem while converting string to int. " 169 + "Converting value of preferences " 170 + prefName + ". Value=\"" + str 171 + "\". Should be an integer. Error: " 172 + ex.getMessage(), ex); 173 } 174 return pref; 175 } 176 177 static int checkMaxZoomLvl(int maxZoomLvl) 178 { 179 if(maxZoomLvl > MAX_ZOOM) { 180 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 181 maxZoomLvl = MAX_ZOOM; 182 } 183 if(maxZoomLvl < SlippyMapPreferences.__getMinZoomLvl()) { 184 System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl."); 185 maxZoomLvl = SlippyMapPreferences.__getMinZoomLvl(); 186 } 187 return maxZoomLvl; 188 } 189 142 190 public static int getMaxZoomLvl() 143 191 { 144 String maxZoomLvl = Main.pref.get(PREFERENCE_MAX_ZOOM_LVL); 145 146 if (maxZoomLvl == null || "".equals(maxZoomLvl)) 147 { 148 maxZoomLvl = "17"; 149 Main.pref.put(PREFERENCE_MAX_ZOOM_LVL, maxZoomLvl); 150 } 151 152 int navrat; 153 try { 154 navrat = Integer.parseInt(maxZoomLvl); 155 } catch (Exception ex) { 156 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); 157 } 158 if(navrat > 30) { 159 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 160 navrat = 30; 161 } 162 //if(navrat < SlippyMapPreferences.getMinZoomLvl()) { 163 // System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl."); 164 // navrat = SlippyMapPreferences.getMinZoomLvl(); 165 //} 166 return navrat; 167 } 168 192 int maxZoomLvl = getIntPref(PREFERENCE_MAX_ZOOM_LVL, DEFAULT_MAX_ZOOM); 193 return checkMaxZoomLvl(maxZoomLvl); 194 } 195 169 196 public static void setMaxZoomLvl(int maxZoomLvl) { 170 if(maxZoomLvl > 30) { 171 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 172 maxZoomLvl = 30; 173 } 174 if(maxZoomLvl < SlippyMapPreferences.getMinZoomLvl()) { 175 System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl."); 176 maxZoomLvl = SlippyMapPreferences.getMinZoomLvl(); 177 } 197 maxZoomLvl = checkMaxZoomLvl(maxZoomLvl); 178 198 Main.pref.put(SlippyMapPreferences.PREFERENCE_MAX_ZOOM_LVL, "" + maxZoomLvl); 179 199 } 180 181 public static int getMinZoomLvl() 182 { 183 String minZoomLvl = Main.pref.get(PREFERENCE_MIN_ZOOM_LVL); 184 185 if (minZoomLvl == null || "".equals(minZoomLvl)) 186 { 187 minZoomLvl = "" + (SlippyMapPreferences.getMaxZoomLvl() - 4); 188 Main.pref.put(PREFERENCE_MIN_ZOOM_LVL, minZoomLvl); 189 } 190 191 int navrat; 192 try { 193 navrat = Integer.parseInt(minZoomLvl); 194 } catch (Exception ex) { 195 throw new RuntimeException("Problem while converting string to int. Converting value of prefetrences " + PREFERENCE_MIN_ZOOM_LVL + ". Value=\"" + minZoomLvl + "\". Should be an integer. Error: " + ex.getMessage(), ex); 196 } 197 if(navrat < 2) { 198 System.err.println("minZoomLvl shouldnt be lees than 2! Setting to 2."); 199 navrat = 2; 200 } 201 //if(navrat > SlippyMapPreferences.getMaxZoomLvl()) { 202 // System.err.println("minZoomLvl shouldnt be more than maxZoomLvl! Setting to maxZoomLvl."); 203 // navrat = SlippyMapPreferences.getMaxZoomLvl(); 204 //} 205 return navrat; 206 } 207 208 public static void setMinZoomLvl(int minZoomLvl) { 209 if(minZoomLvl < 2) { 210 System.err.println("minZoomLvl shouldnt be lees than 2! Setting to 2."); 211 minZoomLvl = 2; 200 201 static int checkMinZoomLvl(int minZoomLvl) 202 { 203 if(minZoomLvl < MIN_ZOOM) { 204 System.err.println("minZoomLvl shouldnt be lees than "+MIN_ZOOM+"! Setting to that."); 205 minZoomLvl = MIN_ZOOM; 212 206 } 213 207 if(minZoomLvl > SlippyMapPreferences.getMaxZoomLvl()) { … … 215 209 minZoomLvl = SlippyMapPreferences.getMaxZoomLvl(); 216 210 } 211 return minZoomLvl; 212 } 213 214 private static int __getMinZoomLvl() 215 { 216 // We can use this internally 217 return getIntPref(PREFERENCE_MIN_ZOOM_LVL, DEFAULT_MIN_ZOOM); 218 } 219 public static int getMinZoomLvl() 220 { 221 return checkMinZoomLvl(__getMinZoomLvl()); 222 } 223 224 public static void setMinZoomLvl(int minZoomLvl) { 225 minZoomLvl = checkMinZoomLvl(minZoomLvl); 217 226 Main.pref.put(SlippyMapPreferences.PREFERENCE_MIN_ZOOM_LVL, "" + minZoomLvl); 218 227 } 219 220 public static String[] getAllMapUrls() 221 { 222 String[] defaultTileSources = new String[] 223 { 224 "http://tah.openstreetmap.org/Tiles/tile", // t@h 225 "http://tah.openstreetmap.org/Tiles/maplint", // maplint 226 "http://tile.openstreetmap.org", // mapnik 227 "http://hypercube.telascience.org/tiles/1.0.0/coastline", // coastline 228 "http://www.freemap.sk/layers/allinone/?", //freemapy.sk 229 "http://www.freemap.sk/layers/tiles/?", //freemapy.sk pokus 2 230 }; 231 return defaultTileSources; 228 229 public static class Coastline extends OsmTileSource.AbstractOsmTileSource { 230 public Coastline() { 231 super("Coastline", "http://hypercube.telascience.org/tiles/1.0.0/coastline"); 232 } 233 public TileUpdate getTileUpdate() { 234 return TileUpdate.IfNoneMatch; 235 } 236 } 237 public static class FreeMapySk extends OsmTileSource.AbstractOsmTileSource { 238 public FreeMapySk() { 239 super("freemapy.sk", "http://www.freemap.sk/layers/allinone/?"); 240 } 241 public TileUpdate getTileUpdate() { 242 return TileUpdate.IfNoneMatch; 243 } 244 } 245 public static class FreeMapySkPokus extends OsmTileSource.AbstractOsmTileSource { 246 public FreeMapySkPokus() { 247 super("freemapy.sk pokus 2", "http://www.freemap.sk/layers/tiles/?"); 248 } 249 public TileUpdate getTileUpdate() { 250 return TileUpdate.IfNoneMatch; 251 } 252 } 253 254 public static class Custom extends OsmTileSource.AbstractOsmTileSource { 255 public Custom(String name, String url) { 256 super(name, url); 257 } 258 public Custom(String name, String url, String extension) { 259 super(name, url); 260 this.extension = extension; 261 } 262 String extension; 263 @Override 264 public String getExtension() { 265 if (extension == null) 266 return super.getExtension(); 267 return extension; 268 } 269 public TileUpdate getTileUpdate() { 270 return TileUpdate.IfNoneMatch; 271 } 272 } 273 274 public static List<TileSource> getCustomSources() 275 { 276 List<TileSource> ret = new ArrayList<TileSource>(); 277 Map<String, String> customSources = Main.pref.getAllPrefix(PREFERENCE_TILE_CUSTOM_SOURCE); 278 for (String key : customSources.keySet()) { 279 String short_key = key.replaceFirst(PREFERENCE_TILE_CUSTOM_SOURCE, ""); 280 // slippymap.custom_tile_source_1.name=OOC layer 281 // slippymap.custom_tile_source_1.url=http://a.ooc.openstreetmap.org/npe 282 // slippymap.custom_tile_source_1.ext=png 283 284 if (!(short_key.endsWith("name"))) 285 continue; 286 String url_key = short_key.replaceFirst("name","url"); 287 String ext_key = short_key.replaceFirst("name","ext"); 288 String name = customSources.get(key); 289 String url = customSources.get(PREFERENCE_TILE_CUSTOM_SOURCE + url_key); 290 String ext = customSources.get(PREFERENCE_TILE_CUSTOM_SOURCE + ext_key); 291 // ext may be null, but that's OK 292 System.out.println("found new tile source: '" +name+"' url:'"+url+"'"+"' ext:'"+ext+"'"); 293 ret.add(new Custom(name, url, ext)); 294 } 295 return ret; 296 } 297 298 public static ArrayList<TileSource> sources = null; 299 public static List<TileSource> getAllMapSources() 300 { 301 if (sources != null) 302 return sources; 303 sources = new ArrayList<TileSource>(); 304 // first here is the default if the user does not set one 305 sources.add(new OsmTileSource.Mapnik()); 306 sources.add(new OsmTileSource.CycleMap()); 307 sources.add(new OsmTileSource.TilesAtHome()); 308 sources.add(new Coastline()); 309 sources.add(new FreeMapySkPokus()); 310 sources.add(new FreeMapySk()); 311 sources.addAll(getCustomSources()); 312 // Probably need to either add these or let users add them somehow 313 // "http://hypercube.telascience.org/tiles/1.0.0/coastline", // coastline 314 // "http://www.freemap.sk/layers/allinone/?", //freemapy.sk 315 // "http://www.freemap.sk/layers/tiles/?", //freemapy.sk pokus 2 316 return sources; 317 } 318 319 public static TileSource getSourceNamed(String name) 320 { 321 for (TileSource s : getAllMapSources()) 322 if (s.getName().equals(name)) 323 return s; 324 return null; 232 325 } 233 326 }
Note:
See TracChangeset
for help on using the changeset viewer.