Ignore:
Timestamp:
2009-10-18T21:02:12+02:00 (15 years ago)
Author:
dhansen
Message:

We need some more information out of the tiles other than the error
image that the tile loading has errored out. This should do it.

Refactor the map sources code to make it easier to make more of these.

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

Legend:

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

    r13036 r18211  
    5757                } catch (Exception e) {
    5858                    tile.setImage(Tile.ERROR_IMAGE);
     59                    tile.error = true;
    5960                    listener.tileLoadingFinished(tile, false);
    6061                    if (input == null)
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileSource.java

    r15039 r18211  
    66
    77    public static final String MAP_MAPNIK = "http://tile.openstreetmap.org";
    8     public static final String MAP_OSMA = "http://tah.openstreetmap.org/Tiles/tile";
     8    public static final String MAP_OSMA = "http://tah.openstreetmap.org/Tiles";
    99
    10     protected static abstract class AbstractOsmTileSource implements TileSource {
     10    public static abstract class AbstractOsmTileSource implements TileSource {
     11        protected String NAME;
     12        protected String BASE_URL;
     13        public AbstractOsmTileSource(String name, String base_url)
     14        {
     15            NAME = name;
     16            BASE_URL = base_url;
     17        }
     18
     19        public String getName() {
     20            return NAME;
     21        }
    1122
    1223        public int getMaxZoom() {
     
    1829        }
    1930
     31        public String getTilePath(int zoom, int tilex, int tiley) {
     32            return "/" + zoom + "/" + tilex + "/" + tiley + ".png";
     33        }
     34
     35        public String getBaseUrl() {
     36            return this.BASE_URL;
     37        }
     38
    2039        public String getTileUrl(int zoom, int tilex, int tiley) {
    21             return "/" + zoom + "/" + tilex + "/" + tiley + ".png";
     40            return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
    2241        }
    2342
     
    3453
    3554    public static class Mapnik extends AbstractOsmTileSource {
    36 
    37         public static String NAME = "Mapnik";
    38 
    39         public String getName() {
    40             return NAME;
    41         }
    42 
    43         @Override
    44         public String getTileUrl(int zoom, int tilex, int tiley) {
    45             return MAP_MAPNIK + super.getTileUrl(zoom, tilex, tiley);
     55        public Mapnik() {
     56            super("Mapnik", MAP_MAPNIK);
    4657        }
    4758
     
    5465    public static class CycleMap extends AbstractOsmTileSource {
    5566
    56         private static final String PATTERN = "http://%s.andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png";
    57         public static String NAME = "OSM Cycle Map";
     67        private static final String PATTERN = "http://%s.andy.sandbox.cloudmade.com/tiles/cycle";
    5868
    5969        private static final String[] SERVER = { "a", "b", "c" };
     
    6171        private int SERVER_NUM = 0;
    6272
     73        public CycleMap() {
     74            super("OSM Cycle Map", PATTERN);
     75        }
     76
    6377        @Override
    64         public String getTileUrl(int zoom, int tilex, int tiley) {
    65             String url = String.format(PATTERN, new Object[] { SERVER[SERVER_NUM], zoom, tilex, tiley });
     78        public String getBaseUrl() {
     79            String url = String.format(this.BASE_URL, new Object[] { SERVER[SERVER_NUM] });
    6680            SERVER_NUM = (SERVER_NUM + 1) % SERVER.length;
    6781            return url;
     
    7286        }
    7387
    74         public String getName() {
    75             return NAME;
    76         }
    77 
    7888        public TileUpdate getTileUpdate() {
    7989            return TileUpdate.LastModified;
     
    8292    }
    8393
    84     public static class TilesAtHome extends AbstractOsmTileSource {
    85 
    86         public static String NAME = "TilesAtHome";
     94    public static abstract class OsmaSource extends AbstractOsmTileSource {
     95        String osmaSuffix;
     96        public OsmaSource(String name, String osmaSuffix) {
     97            super(name, MAP_OSMA);
     98            this.osmaSuffix = osmaSuffix;
     99        }
    87100
    88101        public int getMaxZoom() {
     
    90103        }
    91104
    92         public String getName() {
    93             return NAME;
    94         }
    95 
    96105        @Override
    97         public String getTileUrl(int zoom, int tilex, int tiley) {
    98             return MAP_OSMA + super.getTileUrl(zoom, tilex, tiley);
     106        public String getBaseUrl() {
     107            return MAP_OSMA + "/" + osmaSuffix;
    99108        }
    100109
     
    103112        }
    104113    }
     114    public static class TilesAtHome extends OsmaSource {
     115        public TilesAtHome() {
     116            super("TilesAtHome", "tile");
     117        }
     118    }
     119    public static class Maplint extends OsmaSource {
     120        public Maplint() {
     121            super("Maplint", "maplint");
     122        }
     123    }
    105124}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r18179 r18211  
    4747    protected boolean loaded = false;
    4848    protected boolean loading = false;
     49    protected boolean error = false;
    4950    public static final int SIZE = 256;
    5051
     
    225226        if (this.loaded)
    226227            status = "loaded";
     228        if (this.error)
     229            status = "error";
    227230        return status;
    228231    }
     232    public boolean hasError() {
     233        return error;
     234    }
    229235
    230236}
Note: See TracChangeset for help on using the changeset viewer.