Changeset 23190 in osm for applications/editors/josm/plugins/slippymap/src
- Timestamp:
- 2010-09-15T18:54:18+02:00 (14 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/SlippyMapKey.java
r16161 r23190 1 1 /** 2 * 2 * 3 3 */ 4 4 package org.openstreetmap.josm.plugins.slippymap; … … 9 9 * {@link #equals(Object)} and also {@link #toString()}. 10 10 * </p> 11 * 11 * 12 12 * @author LuVar <lubomir.varga@freemap.sk> 13 13 * @author Dave Hansen <dave@sr71.net> … … 15 15 */ 16 16 public class SlippyMapKey { 17 18 19 20 21 22 23 24 25 26 * 27 * @param xx position in tiles table28 * @param yy position in tiles table29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 * 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 * @returnreturn new Integer(this.x + this.y * 10000).hashCode();63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 17 private final int x; 18 private final int y; 19 private final int level; 20 21 /** 22 * <p> 23 * Constructs key for hashmaps for some tile describedy by X and Y position. X and Y are tiles 24 * positions on discrete map. 25 * </p> 26 * 27 * @param x x position in tiles table 28 * @param y y position in tiles table 29 */ 30 public final boolean valid; 31 public SlippyMapKey(int x, int y, int level) { 32 this.x = x; 33 this.y = y; 34 this.level = level; 35 if (level <= 0 || x < 0 || y < 0) { 36 this.valid = false; 37 System.err.println("invalid SlippyMapKey("+level+", "+x+", "+y+")"); 38 } else { 39 this.valid = true; 40 } 41 } 42 43 /** 44 * <p> 45 * Returns true ONLY if x and y are equals. 46 * </p> 47 * 48 * @see java.lang.Object#equals(java.lang.Object) 49 */ 50 @Override 51 public boolean equals(Object obj) { 52 if (obj instanceof SlippyMapKey) { 53 SlippyMapKey smk = (SlippyMapKey) obj; 54 if((smk.x == this.x) && (smk.y == this.y) && (smk.level == this.level)) { 55 return true; 56 } 57 } 58 return false; 59 } 60 61 /** 62 * @return return new Integer(this.x + this.y * 10000).hashCode(); 63 * @see java.lang.Object#hashCode() 64 */ 65 @Override 66 public int hashCode() { 67 return new Integer(this.x + this.y * 10000 + this.level * 100000).hashCode(); 68 } 69 70 /** 71 * @see java.lang.Object#toString() 72 */ 73 @Override 74 public String toString() { 75 return "SlippyMapKey(x=" + this.x + ",y=" + this.y + ",level=" + level + ")"; 76 } 77 78 78 } -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java
r22848 r23190 212 212 // FIXME: currently ran in errors 213 213 214 214 tileOptionMenu.add(new JMenuItem( 215 215 new AbstractAction(tr("Snap to tile size")) { 216 216 public void actionPerformed(ActionEvent ae) { … … 252 252 MapView.addLayerChangeListener(new LayerChangeListener() { 253 253 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 254 254 // 255 255 } 256 256 257 257 public void layerAdded(Layer newLayer) { 258 258 // 259 259 } 260 260 261 261 public void layerRemoved(Layer oldLayer) { 262 262 MapView.removeLayerChangeListener(this); 263 263 } 264 264 }); -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPlugin.java
r22848 r23190 21 21 public SlippyMapPlugin(PluginInformation info) 22 22 { 23 24 23 super(info); 24 Main.pref.addPreferenceChangeListener(this); 25 25 } 26 26 27 27 @Override 28 28 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) 29 29 { 30 30 if (newFrame != null && SlippyMapPreferences.getMapSource() != SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { … … 53 53 */ 54 54 public void preferenceChanged(PreferenceChangeEvent event) { 55 56 57 58 59 60 55 if (!Main.isDisplayingMapView()) { 56 return; 57 } 58 List<SlippyMapLayer> layes = Main.map.mapView.getLayersOfType(SlippyMapLayer.class); 59 assert layes.size() <= 1; 60 SlippyMapLayer layer = layes.isEmpty()?null:layes.get(0); 61 61 62 62 if (event.getKey().equals(SlippyMapPreferences.PREFERENCE_TILE_SOURCE)) { 63 64 65 66 67 68 69 70 71 63 if (layer == null && SlippyMapPreferences.getMapSource() != SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 64 Main.map.mapView.addLayer(new SlippyMapLayer()); 65 } else if (layer != null && SlippyMapPreferences.getMapSource() == SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 66 Main.map.mapView.removeLayer(layer); 67 } else if (layer == null && SlippyMapPreferences.getMapSource() == SlippyMapPreferences.NO_DEFAULT_TILE_SOURCE) { 68 // Do nothing 69 } else { 70 layer.newTileStorage(); 71 } 72 72 } else if (event.getKey().startsWith(SlippyMapPreferences.PREFERENCE_PREFIX) && layer != null) { 73 73 // System.err.println(this + ".preferenceChanged('" + key + "', '" -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferenceSetting.java
r22848 r23190 114 114 * Actualy this method loads and sets this params:<br> 115 115 * <ul> 116 * 117 * 118 * 119 * 116 * <li>autozoom - {@link #autozoomActive} - {@link SlippyMapPreferences#getAutozoom()}</li> 117 * <li>autoload - {@link #autoloadTiles} - {@link SlippyMapPreferences#getAutoloadTiles()}</li> 118 * <li>maxZoomLvl - {@link #maxZoomLvl} - {@link SlippyMapPreferences#getMaxZoomLvl()}</li> 119 * <li>minZoomLvl - {@link #minZoomLvl} - {@link SlippyMapPreferences#getMaxZoomLvl()}</li> 120 120 * </ul> 121 121 * </p> … … 139 139 public boolean ok() 140 140 { 141 141 SlippyMapPreferences.setMapSource((TileSource)this.tileSourceCombo.getSelectedItem()); 142 142 SlippyMapPreferences.setAutozoom(this.autozoomActive.isSelected()); 143 143 SlippyMapPreferences.setAutoloadTiles(this.autoloadTiles.isSelected()); -
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapPreferences.java
r22848 r23190 21 21 public class SlippyMapPreferences 22 22 { 23 23 public static final String NO_DEFAULT_TILE_SOURCE_NAME = "{%no_default%}"; 24 24 public static final String PREFERENCE_PREFIX = "slippymap"; 25 25 … … 47 47 public static TileSource getMapSource(String name) 48 48 { 49 50 51 49 if (NO_DEFAULT_TILE_SOURCE_NAME.equals(name)) { 50 return NO_DEFAULT_TILE_SOURCE; // User don't want to load slippy layer on startup 51 } 52 52 53 53 List<TileSource> sources = SlippyMapPreferences.getAllMapSources(); … … 60 60 for (TileSource s : sources) { 61 61 if (name.equals(s.getName())) 62 62 return s; 63 63 } 64 64 … … 67 67 68 68 public static void setMapSource(TileSource source) { 69 69 Main.pref.put(SlippyMapPreferences.PREFERENCE_TILE_SOURCE, source == NO_DEFAULT_TILE_SOURCE?NO_DEFAULT_TILE_SOURCE_NAME:source.getName()); 70 70 } 71 71 … … 76 76 if (autozoom == null || "".equals(autozoom)) 77 77 { 78 78 autozoom = "true"; 79 79 Main.pref.put(PREFERENCE_AUTOZOOM, autozoom); 80 80 } … … 84 84 85 85 public static void setAutozoom(boolean autozoom) { 86 86 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOZOOM, autozoom); 87 87 } 88 88 89 89 public static void setDrawDebug(boolean drawDebug) { 90 90 Main.pref.put(SlippyMapPreferences.PREFERENCE_DRAW_DEBUG, drawDebug); 91 91 } 92 92 93 93 public static void setLastZoom(int zoom) { 94 94 Main.pref.put(SlippyMapPreferences.PREFERENCE_LAST_ZOOM, ""+zoom); 95 95 } 96 96 public static int getLastZoom() { 97 97 int ret = -1; 98 98 String pref = Main.pref.get(SlippyMapPreferences.PREFERENCE_LAST_ZOOM); 99 99 try { … … 110 110 if (drawDebug == null || "".equals(drawDebug)) 111 111 { 112 112 drawDebug = "false"; 113 113 Main.pref.put(PREFERENCE_DRAW_DEBUG, drawDebug); 114 114 } … … 123 123 if (autoloadTiles == null || "".equals(autoloadTiles)) 124 124 { 125 125 autoloadTiles = "true"; 126 126 Main.pref.put(PREFERENCE_AUTOLOADTILES, autoloadTiles); 127 127 } … … 131 131 132 132 public static void setFadeBackground(float fadeBackground) { 133 133 Main.pref.put(SlippyMapPreferences.PREFERENCE_FADE_BACKGROUND, fadeBackground + ""); 134 134 } 135 135 136 136 /** 137 137 * 138 * @return 138 * @return number between 0 and 1, inclusive 139 139 */ 140 140 public static float getFadeBackground() { … … 143 143 if (fadeBackground == null || "".equals(fadeBackground)) 144 144 { 145 145 fadeBackground = "0.0"; 146 146 Main.pref.put(PREFERENCE_FADE_BACKGROUND, fadeBackground); 147 147 } … … 149 149 float parsed; 150 150 try { 151 151 parsed = Float.parseFloat(fadeBackground); 152 152 } catch (Exception ex) { 153 154 155 156 153 setFadeBackground(0.1f); 154 System.out.println("Error while parsing setting fade background to float! returning 0.1, because of error:"); 155 ex.printStackTrace(System.out); 156 return 0.1f; 157 157 } 158 158 if(parsed < 0f) { 159 159 parsed = 0f; 160 160 } else { 161 162 161 if(parsed > 1f) { 162 parsed = 1f; 163 163 } 164 164 } … … 167 167 168 168 public static void setAutoloadTiles(boolean autoloadTiles) { 169 169 Main.pref.put(SlippyMapPreferences.PREFERENCE_AUTOLOADTILES, autoloadTiles); 170 170 } 171 171 … … 174 174 int pref; 175 175 try { 176 177 176 //Should we use Main.pref.getInteger(str)? 177 pref = Main.pref.getInteger(prefName, def); 178 178 } catch (Exception ex) { 179 179 String str = Main.pref.get(prefName); 180 180 Main.pref.put(prefName, null); 181 181 throw new RuntimeException("Problem while converting string to int. " 182 182 + "Converting value of preferences " 183 183 + prefName + ". Value=\"" + str … … 190 190 static int checkMaxZoomLvl(int maxZoomLvl) 191 191 { 192 193 194 195 196 197 198 199 192 if(maxZoomLvl > MAX_ZOOM) { 193 System.err.println("MaxZoomLvl shouldnt be more than 30! Setting to 30."); 194 maxZoomLvl = MAX_ZOOM; 195 } 196 if(maxZoomLvl < SlippyMapPreferences.__getMinZoomLvl()) { 197 System.err.println("maxZoomLvl shouldnt be more than minZoomLvl! Setting to minZoomLvl."); 198 maxZoomLvl = SlippyMapPreferences.__getMinZoomLvl(); 199 } 200 200 TileSource ts = getMapSource(); 201 201 if (ts != null && ts.getMaxZoom() < SlippyMapPreferences.__getMinZoomLvl()) { 202 202 System.err.println("decreasing maxZoomLvl to match new tile source"); 203 203 maxZoomLvl = ts.getMaxZoom(); 204 204 } … … 214 214 public static void setMaxZoomLvl(int maxZoomLvl) { 215 215 maxZoomLvl = checkMaxZoomLvl(maxZoomLvl); 216 216 Main.pref.put(SlippyMapPreferences.PREFERENCE_MAX_ZOOM_LVL, "" + maxZoomLvl); 217 217 } 218 218 … … 220 220 { 221 221 if(minZoomLvl < MIN_ZOOM) { 222 223 224 225 226 227 228 222 System.err.println("minZoomLvl shouldnt be lees than "+MIN_ZOOM+"! Setting to that."); 223 minZoomLvl = MIN_ZOOM; 224 } 225 if(minZoomLvl > SlippyMapPreferences.getMaxZoomLvl()) { 226 System.err.println("minZoomLvl shouldnt be more than maxZoomLvl! Setting to maxZoomLvl."); 227 minZoomLvl = SlippyMapPreferences.getMaxZoomLvl(); 228 } 229 229 return minZoomLvl; 230 230 } … … 242 242 public static void setMinZoomLvl(int minZoomLvl) { 243 243 minZoomLvl = checkMinZoomLvl(minZoomLvl); 244 244 Main.pref.put(SlippyMapPreferences.PREFERENCE_MIN_ZOOM_LVL, "" + minZoomLvl); 245 245 } 246 246 247 247 public static TileSource NO_DEFAULT_TILE_SOURCE = new AbstractOsmTileSource(tr("(none)"), "") { 248 249 250 248 public TileUpdate getTileUpdate() { 249 return null; 250 } 251 251 }; 252 252 … … 282 282 283 283 @Override 284 284 public int getMaxZoom() { 285 285 return 21; 286 286 } 287 287 288 288 @Override 289 289 public String getTilePath(int zoom, int tilex, int tiley) { 290 290 return "z=" + zoom + "&x=" + tilex + "&y=" + tiley; 291 291 } … … 303 303 304 304 @Override 305 305 public int getMaxZoom() { 306 306 return 21; 307 307 } 308 308 309 309 @Override 310 311 310 public String getTilePath(int zoom, int tilex, int tiley) { 311 return "/" + zoom + "/" + tilex + "/" + tiley + ".png"; 312 312 } 313 313
Note:
See TracChangeset
for help on using the changeset viewer.