Changeset 24840 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2010-12-22T16:59:45+01:00 (14 years ago)
Author:
upliner
Message:

jmapviewer: initial support for bing tile metadata

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

Legend:

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

    r24828 r24840  
    113113
    114114        public FileLoadJob(TileSource source, int tilex, int tiley, int zoom) {
    115             super();
    116115            this.source = source;
    117116            this.tilex = tilex;
     
    151150            try {
    152151                // log.finest("Loading tile from OSM: " + tile);
    153                 HttpURLConnection urlConn = loadTileFromOsm(tile);
     152                URLConnection urlConn = loadTileFromOsm(tile);
    154153                if (tileFile != null) {
    155154                    switch (source.getTileUpdate()) {
     
    189188                    saveETagToFile(eTag);
    190189                }
    191                 if (urlConn.getResponseCode() == 304) {
     190                loadTileMetadata(tile, urlConn);
     191                if (urlConn instanceof HttpURLConnection && ((HttpURLConnection)urlConn).getResponseCode() == 304) {
    192192                    // If we are isModifiedSince or If-None-Match has been set
    193193                    // and the server answers with a HTTP 304 = "Not Modified"
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r18772 r24840  
    77import java.net.HttpURLConnection;
    88import java.net.URL;
     9import java.net.URLConnection;
    910
    1011import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
     
    1415
    1516/**
    16  * A {@link TileLoader} implementation that loads tiles from OSM via HTTP.
     17 * A {@link TileLoader} implementation that loads tiles from OSM.
    1718 *
    1819 * @author Jan Peter Stotz
     
    4950                try {
    5051                    // Thread.sleep(500);
    51                     input = loadTileFromOsm(tile).getInputStream();
     52                    URLConnection conn = loadTileFromOsm(tile);
     53                    loadTileMetadata(tile, conn);
     54                    input = conn.getInputStream();
    5255                    tile.loadImage(input);
    5356                    tile.setLoaded(true);
     
    5962                    tile.error = true;
    6063                    listener.tileLoadingFinished(tile, false);
    61                     if (input == null)
     64                    if (input == null) {
    6265                        System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage());
     66                    }
    6367                } finally {
    6468                    tile.loading = false;
     
    7074    }
    7175
    72     protected HttpURLConnection loadTileFromOsm(Tile tile) throws IOException {
     76    protected URLConnection loadTileFromOsm(Tile tile) throws IOException {
    7377        URL url;
    7478        url = new URL(tile.getUrl());
    75         HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    76         prepareHttpUrlConnection(urlConn);
     79        URLConnection urlConn = url.openConnection();
     80        if (urlConn instanceof HttpURLConnection) {
     81            prepareHttpUrlConnection((HttpURLConnection)urlConn);
     82        }
    7783        urlConn.setReadTimeout(30000); // 30 seconds read timeout
    7884        return urlConn;
    7985    }
    8086
     87    protected void loadTileMetadata(Tile tile, URLConnection urlConn) {
     88        String bing_capturedate = urlConn.getHeaderField("X-VE-TILEMETA-CaptureDatesRange");
     89        if (bing_capturedate != null) {
     90            tile.putValue("capture-date", bing_capturedate);
     91        }
     92    }
     93
    8194    protected void prepareHttpUrlConnection(HttpURLConnection urlConn) {
    82         if (USER_AGENT != null)
     95        if (USER_AGENT != null) {
    8396            urlConn.setRequestProperty("User-agent", USER_AGENT);
     97        }
    8498        urlConn.setRequestProperty("Accept", ACCEPT);
    8599    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r24763 r24840  
    99import java.io.IOException;
    1010import java.io.InputStream;
     11import java.util.HashMap;
     12import java.util.Map;
    1113
    1214import javax.imageio.ImageIO;
     
    4850    protected boolean loading = false;
    4951    protected boolean error = false;
     52
     53    /** TileSource-specific tile metadata */
     54    protected Map<String, String> metadata;
    5055
    5156    /**
     
    253258
    254259    public String getStatus() {
    255         String status = "new";
    256         if (this.error) {
    257             status = "error";
    258         }
    259         if (this.loading) {
    260             status = "loading";
    261         }
    262         if (this.loaded) {
    263             status = "loaded";
    264         }
    265         return status;
     260        if (this.error)
     261            return "error";
     262        if (this.loaded)
     263            return "loaded";
     264        if (this.loading)
     265            return "loading";
     266        return "new";
    266267    }
    267268
     
    270271    }
    271272
     273    public void putValue(String key, String value) {
     274        if (metadata == null) {
     275            metadata = new HashMap<String,String>();
     276        }
     277        metadata.put(key, value);
     278    }
     279
     280    public String getValue(String key) {
     281        if (metadata == null) return null;
     282        return metadata.get(key);
     283    }
     284
     285    public Map<String,String> getMetadata() {
     286        return metadata;
     287    }
    272288}
Note: See TracChangeset for help on using the changeset viewer.