Ignore:
Timestamp:
2011-05-01T21:56:49+02:00 (15 years ago)
Author:
jttt
Message:

Improved wms cache

  • files saved in original format (no need to recode to png)
  • possibility to tile with different pos/ppd that overlaps current tile
File:
1 edited

Legend:

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

    r3826 r4065  
    66import java.awt.image.BufferedImage;
    77import java.io.BufferedReader;
     8import java.io.ByteArrayInputStream;
     9import java.io.ByteArrayOutputStream;
    810import java.io.IOException;
    911import java.io.InputStream;
     
    3436import org.openstreetmap.josm.io.OsmTransferException;
    3537import org.openstreetmap.josm.io.ProgressInputStream;
     38import org.openstreetmap.josm.tools.Utils;
    3639
    3740
     
    5356        try {
    5457            url = getURL(
    55                     b.min.east(), b.min.north(),
    56                     b.max.east(), b.max.north(),
     58                    b.minEast, b.minNorth,
     59                    b.maxEast, b.maxNorth,
    5760                    width(), height());
    5861            request.finish(State.IMAGE, grab(url, attempt));
     
    143146    @Override
    144147    public boolean loadFromCache(WMSRequest request) {
    145         URL url = null;
    146         try{
    147             url = getURL(
    148                     b.min.east(), b.min.north(),
    149                     b.max.east(), b.max.north(),
    150                     width(), height());
    151         } catch(Exception e) {
    152             return false;
    153         }
    154         BufferedImage cached = cache.getImg(url.toString());
    155         if((!request.isReal() && !layer.hasAutoDownload()) || cached != null){
    156             if(cached == null){
    157                 request.finish(State.NOT_IN_CACHE, null);
    158                 return true;
    159             }
     148        BufferedImage cached = layer.cache.getExactMatch(Main.proj, pixelPerDegree, b.minEast, b.minNorth);
     149
     150        if (cached != null) {
    160151            request.finish(State.IMAGE, cached);
    161152            return true;
    162         }
     153        } else if (request.isAllowPartialCacheMatch()) {
     154            BufferedImage partialMatch = layer.cache.getPartialMatch(Main.proj, pixelPerDegree, b.minEast, b.minNorth);
     155            if (partialMatch != null) {
     156                request.finish(State.PARTLY_IN_CACHE, partialMatch);
     157                return true;
     158            }
     159        }
     160
     161        if((!request.isReal() && !layer.hasAutoDownload())){
     162            request.finish(State.NOT_IN_CACHE, null);
     163            return true;
     164        }
     165
    163166        return false;
    164167    }
     
    180183            throw new IOException(readException(conn));
    181184
     185        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    182186        InputStream is = new ProgressInputStream(conn, null);
    183         BufferedImage img = layer.normalizeImage(ImageIO.read(is));
    184         is.close();
    185 
    186         cache.saveImg(url.toString(), img);
     187        try {
     188            Utils.copyStream(is, baos);
     189        } finally {
     190            is.close();
     191        }
     192
     193        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
     194        BufferedImage img = layer.normalizeImage(ImageIO.read(bais));
     195        bais.reset();
     196        layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.proj, pixelPerDegree, b.minEast, b.minNorth);
    187197        return img;
    188198    }
Note: See TracChangeset for help on using the changeset viewer.