Changeset 4825 in josm
- Timestamp:
- 2012-01-20T12:46:28+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4538 r4825 18 18 import java.io.File; 19 19 import java.io.IOException; 20 import java.util.ArrayList; 21 import java.util.Collections; 22 import java.util.HashSet; 23 import java.util.LinkedList; 24 import java.util.List; 25 import java.util.Map; 20 import java.io.StringReader; 21 import java.net.URL; 22 import java.util.*; 26 23 import java.util.Map.Entry; 24 import java.util.concurrent.Callable; 27 25 import java.util.regex.Matcher; 28 26 import java.util.regex.Pattern; … … 44 42 import org.openstreetmap.gui.jmapviewer.Tile; 45 43 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 46 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;47 44 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 48 45 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; … … 69 66 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 70 67 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 68 import org.openstreetmap.josm.io.CacheCustomContent; 69 import org.openstreetmap.josm.io.UTFInputStreamReader; 70 import org.xml.sax.InputSource; 71 71 72 72 /** … … 225 225 } 226 226 227 private static class CachedAttributionBingAerialTileSource extends BingAerialTileSource { 228 229 class BingAttributionData extends CacheCustomContent<IOException> { 230 231 public BingAttributionData() { 232 super("bing.attribution.xml", CacheCustomContent.INTERVAL_WEEKLY); 233 } 234 235 @Override 236 protected byte[] updateData() throws IOException { 237 URL u = getAttributionUrl(); 238 UTFInputStreamReader in = UTFInputStreamReader.create(u.openStream(), "utf-8"); 239 String r = new Scanner(in).useDelimiter("\\A").next(); 240 System.out.println("Successfully loaded Bing attribution data."); 241 return r.getBytes("utf-8"); 242 } 243 } 244 245 @Override 246 protected Callable<List<Attribution>> getAttributionLoaderCallable() { 247 return new Callable<List<Attribution>>() { 248 249 @Override 250 public List<Attribution> call() throws Exception { 251 BingAttributionData attributionLoader = new BingAttributionData(); 252 int waitTimeSec = 1; 253 while (true) { 254 try { 255 String xml = attributionLoader.updateIfRequiredString(); 256 return parseAttributionText(new InputSource(new StringReader((xml)))); 257 } catch (IOException ex) { 258 System.err.println("Could not connect to Bing API. Will retry in " + waitTimeSec + " seconds."); 259 Thread.sleep(waitTimeSec * 1000L); 260 waitTimeSec *= 2; 261 } 262 } 263 } 264 }; 265 } 266 } 267 227 268 public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException { 228 269 if (info.getImageryType() == ImageryType.TMS) { … … 232 273 return t; 233 274 } else if (info.getImageryType() == ImageryType.BING) 234 return new BingAerialTileSource();235 else if (info.getImageryType() == ImageryType.SCANEX) 275 return new CachedAttributionBingAerialTileSource(); 276 else if (info.getImageryType() == ImageryType.SCANEX) { 236 277 return new ScanexTileSource(info.getUrl()); 278 } 237 279 return null; 238 280 } 239 281 240 282 public static void checkUrl(String url) throws IllegalArgumentException { 241 283 if (url == null) {
Note:
See TracChangeset
for help on using the changeset viewer.