Changeset 4825 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
20.01.2012 12:46:28 (4 months ago)
Author:
simon04
Message:

see #7289 - remove JOSM specific stuff from jmapviewer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4538 r4825  
    1818import java.io.File; 
    1919import 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; 
     20import java.io.StringReader; 
     21import java.net.URL; 
     22import java.util.*; 
    2623import java.util.Map.Entry; 
     24import java.util.concurrent.Callable; 
    2725import java.util.regex.Matcher; 
    2826import java.util.regex.Pattern; 
     
    4442import org.openstreetmap.gui.jmapviewer.Tile; 
    4543import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 
    46 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 
    4744import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 
    4845import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 
     
    6966import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 
    7067import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 
     68import org.openstreetmap.josm.io.CacheCustomContent; 
     69import org.openstreetmap.josm.io.UTFInputStreamReader; 
     70import org.xml.sax.InputSource; 
    7171 
    7272/** 
     
    225225    } 
    226226 
     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 
    227268    public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException { 
    228269        if (info.getImageryType() == ImageryType.TMS) { 
     
    232273            return t; 
    233274        } 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) { 
    236277            return new ScanexTileSource(info.getUrl()); 
     278        } 
    237279        return null; 
    238280    } 
    239      
     281 
    240282    public static void checkUrl(String url) throws IllegalArgumentException { 
    241283        if (url == null) { 
Note: See TracChangeset for help on using the changeset viewer.