Changeset 24763 in osm for applications/viewer


Ignore:
Timestamp:
2010-12-15T18:27:25+01:00 (14 years ago)
Author:
upliner
Message:

jmapviewer: don't show Bing tiles until the attribution data is loaded

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/BingAerialTileSource.java

    r24706 r24763  
    77import java.util.ArrayList;
    88import java.util.List;
     9import java.util.concurrent.Callable;
     10import java.util.concurrent.Executors;
     11import java.util.concurrent.Future;
    912
    1013import javax.imageio.ImageIO;
     
    1922public class BingAerialTileSource extends OsmTileSource.AbstractOsmTileSource {
    2023    private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU";
    21     private static List<Attribution> attributions;
     24    private static Future<List<Attribution>> attributions;
    2225
    2326    public BingAerialTileSource() {
     
    2528
    2629        if (attributions == null) {
    27             Thread t = new Thread(new Runnable() {
     30            attributions = Executors.newSingleThreadExecutor().submit(new Callable<List<Attribution>>() {
    2831                @Override
    29                 public void run() {
    30                     attributions = loadAttributionText();
     32                public List<Attribution> call() throws Exception {
     33                    return loadAttributionText();
    3134                }
    3235            });
    33             t.setDaemon(true);
    34             t.start();
    3536        }
    3637    }
     
    130131
    131132    @Override
    132     public String getTilePath(int zoom, int tilex, int tiley) {
    133         String quadtree = computeQuadTree(zoom, tilex, tiley);
    134         return "/tiles/a" + quadtree + "." + getExtension() + "?g=587";
     133    public String getTilePath(int zoom, int tilex, int tiley) throws IOException {
     134        try {
     135            if (attributions.get() == null)
     136                throw new IOException("Cannot load Bing attribution");
     137            String quadtree = computeQuadTree(zoom, tilex, tiley);
     138            return "/tiles/a" + quadtree + "." + getExtension() + "?g=587";
     139        } catch (Exception e) {
     140            throw new IOException("Cannot load Bing attribution", e);
     141        }
    135142    }
    136143
     
    169176    @Override
    170177    public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
    171         if (attributions == null)
    172             // TODO: don't show Bing tiles until attribution data is loaded
    173             return "";
    174         StringBuilder a = new StringBuilder();
    175         for (Attribution attr : attributions) {
    176             if(zoom <= attr.maxZoom && zoom >= attr.minZoom) {
    177                 if(topLeft.getLon() < attr.max.getLon()
    178                         && botRight.getLon() > attr.min.getLon()
    179                         && topLeft.getLat() > attr.min.getLat()
    180                         && botRight.getLat() < attr.max.getLat()) {
    181                     a.append(attr.attribution);
    182                     a.append(" ");
     178        try {
     179            if (!attributions.isDone())
     180                return "Loading Bing attribution data...";
     181            if (attributions.get() == null)
     182                return "Error loading Bing attribution data";
     183            StringBuilder a = new StringBuilder();
     184            for (Attribution attr : attributions.get()) {
     185                if(zoom <= attr.maxZoom && zoom >= attr.minZoom) {
     186                    if(topLeft.getLon() < attr.max.getLon()
     187                            && botRight.getLon() > attr.min.getLon()
     188                            && topLeft.getLat() > attr.min.getLat()
     189                            && botRight.getLat() < attr.max.getLat()) {
     190                        a.append(attr.attribution);
     191                        a.append(" ");
     192                    }
    183193                }
    184194            }
    185         }
    186         return a.toString();
     195            return a.toString();
     196        } catch (Exception e) {
     197            e.printStackTrace();
     198        }
     199        return "Error loading Bing attribution data";
    187200    }
    188201
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java

    r18772 r24763  
    6363            log.log(Level.WARNING,
    6464                    "Failed to access system property ''java.io.tmpdir'' for security reasons. Exception was: "
    65                             + e.toString());
     65                    + e.toString());
    6666            throw e; // rethrow
    6767        }
     
    7373                // On Linux/Unix systems we do not have a per user tmp directory.
    7474                // Therefore we add the user name for getting a unique dir name.
    75                 if (userName != null && userName.length() > 0)
     75                if (userName != null && userName.length() > 0) {
    7676                    subDirName += "_" + userName;
     77                }
    7778                cacheDir = new File(tempDir, subDirName);
    7879            }
     
    208209            } catch (Exception e) {
    209210                tile.setImage(Tile.ERROR_IMAGE);
     211                tile.error = true;
    210212                listener.tileLoadingFinished(tile, false);
    211213                if (input == null) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java

    r24706 r24763  
    22
    33import java.awt.Image;
     4import java.io.IOException;
    45
    56import javax.swing.ImageIcon;
     
    4849        }
    4950
    50         public String getTilePath(int zoom, int tilex, int tiley) {
     51        /**
     52         * @throws IOException when subclass cannot return the tile URL
     53         */
     54        public String getTilePath(int zoom, int tilex, int tiley) throws IOException {
    5155            return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension();
    5256        }
     
    5660        }
    5761
    58         public String getTileUrl(int zoom, int tilex, int tiley) {
     62        public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
    5963            return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
    6064        }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r22281 r24763  
    184184    }
    185185
    186     public String getUrl() {
     186    public String getUrl() throws IOException {
    187187        return source.getTileUrl(zoom, xtile, ytile);
    188188    }
     
    254254    public String getStatus() {
    255255        String status = "new";
     256        if (this.error) {
     257            status = "error";
     258        }
    256259        if (this.loading) {
    257260            status = "loading";
     
    260263            status = "loaded";
    261264        }
    262         if (this.error) {
    263             status = "error";
    264         }
    265265        return status;
    266266    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java

    r24706 r24763  
    22
    33import java.awt.Image;
     4import java.io.IOException;
    45
    56import org.openstreetmap.gui.jmapviewer.Coordinate;
     
    8081     * @return fully qualified url for downloading the specified tile image
    8182     */
    82     public String getTileUrl(int zoom, int tilex, int tiley);
     83    public String getTileUrl(int zoom, int tilex, int tiley) throws IOException;
    8384
    8485    /**
Note: See TracChangeset for help on using the changeset viewer.