Ignore:
Timestamp:
2010-12-27T19:40:35+01:00 (13 years ago)
Author:
jttt
Message:

Make sure wms layer will not try to download the same area twice

Location:
trunk/src/org/openstreetmap/josm/io/imagery
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/imagery/Grabber.java

    r3720 r3747  
    2323    protected volatile boolean canceled;
    2424
    25     Grabber(MapView mv, WMSLayer layer, CacheFiles cache) {
     25    Grabber(MapView mv, WMSLayer layer) {
    2626        this.mv = mv;
    2727        this.layer = layer;
     
    5050    }
    5151
    52     abstract void fetch(WMSRequest request) throws Exception; // the image fetch code
     52    abstract void fetch(WMSRequest request, int attempt) throws Exception; // the image fetch code
    5353
    5454    int width(){
     
    8686                if (!layer.requestIsValid(request))
    8787                    return;
    88                 fetch(request);
     88                fetch(request, i);
    8989                break; // break out of the retry loop
    9090            } catch (Exception e) {
  • trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java

    r3720 r3747  
    1414import org.openstreetmap.josm.gui.MapView;
    1515import org.openstreetmap.josm.gui.layer.WMSLayer;
    16 import org.openstreetmap.josm.io.CacheFiles;
    1716
    1817public class HTMLGrabber extends WMSGrabber {
    1918    public static final StringProperty PROP_BROWSER = new StringProperty("imagery.wms.browser", "webkit-image {0}");
    2019
    21     public HTMLGrabber(MapView mv, WMSLayer layer, CacheFiles cache) {
    22         super(mv, layer, cache);
     20    public HTMLGrabber(MapView mv, WMSLayer layer) {
     21        super(mv, layer);
    2322    }
    2423
    2524    @Override
    26     protected BufferedImage grab(URL url) throws IOException {
     25    protected BufferedImage grab(URL url, int attempt) throws IOException {
    2726        String urlstring = url.toExternalForm();
    2827
    29         System.out.println("Grabbing HTML " + url);
     28        System.out.println("Grabbing HTML " + (attempt > 1? "(attempt " + attempt + ") ":"") + url);
    3029
    3130        ArrayList<String> cmdParams = new ArrayList<String>();
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java

    r3720 r3747  
    2727import org.openstreetmap.josm.data.coor.EastNorth;
    2828import org.openstreetmap.josm.data.coor.LatLon;
     29import org.openstreetmap.josm.data.imagery.GeorefImage.State;
    2930import org.openstreetmap.josm.data.imagery.ImageryInfo;
    30 import org.openstreetmap.josm.data.imagery.GeorefImage.State;
    3131import org.openstreetmap.josm.data.projection.Mercator;
    3232import org.openstreetmap.josm.gui.MapView;
    3333import org.openstreetmap.josm.gui.layer.WMSLayer;
    34 import org.openstreetmap.josm.io.CacheFiles;
    3534import org.openstreetmap.josm.io.OsmTransferException;
    3635import org.openstreetmap.josm.io.ProgressInputStream;
     
    4241    private final boolean urlWithPatterns;
    4342
    44     public WMSGrabber(MapView mv, WMSLayer layer, CacheFiles cache) {
    45         super(mv, layer, cache);
     43    public WMSGrabber(MapView mv, WMSLayer layer) {
     44        super(mv, layer);
    4645        this.baseURL = layer.getInfo().getURL();
    4746        /* URL containing placeholders? */
     
    5049
    5150    @Override
    52     void fetch(WMSRequest request) throws Exception{
     51    void fetch(WMSRequest request, int attempt) throws Exception{
    5352        URL url = null;
    5453        try {
     
    5756                    b.max.east(), b.max.north(),
    5857                    width(), height());
    59             request.finish(State.IMAGE, grab(url));
     58            request.finish(State.IMAGE, grab(url, attempt));
    6059
    6160        } catch(Exception e) {
     
    165164    }
    166165
    167     protected BufferedImage grab(URL url) throws IOException, OsmTransferException {
    168         System.out.println("Grabbing WMS " + url);
     166    protected BufferedImage grab(URL url, int attempt) throws IOException, OsmTransferException {
     167        System.out.println("Grabbing WMS " + (attempt > 1? "(attempt " + attempt + ") ":"") + url);
    169168
    170169        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     
    193192        InputStream in = conn.getInputStream();
    194193        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    195 
    196         String line = null;
    197         while( (line = br.readLine()) != null) {
    198             // filter non-ASCII characters and control characters
    199             exception.append(line.replaceAll("[^\\p{Print}]", ""));
    200             exception.append('\n');
    201         }
    202         return exception.toString();
     194        try {
     195            String line = null;
     196            while( (line = br.readLine()) != null) {
     197                // filter non-ASCII characters and control characters
     198                exception.append(line.replaceAll("[^\\p{Print}]", ""));
     199                exception.append('\n');
     200            }
     201            return exception.toString();
     202        } finally {
     203            br.close();
     204        }
    203205    }
    204206}
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSRequest.java

    r3720 r3747  
    44import java.awt.image.BufferedImage;
    55
    6 import org.openstreetmap.josm.data.imagery.GeorefImage;
    76import org.openstreetmap.josm.data.imagery.GeorefImage.State;
    87
Note: See TracChangeset for help on using the changeset viewer.