Changeset 4065 in josm for trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
- Timestamp:
- 2011-05-01T21:56:49+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r3826 r4065 6 6 import java.awt.image.BufferedImage; 7 7 import java.io.BufferedReader; 8 import java.io.ByteArrayInputStream; 9 import java.io.ByteArrayOutputStream; 8 10 import java.io.IOException; 9 11 import java.io.InputStream; … … 34 36 import org.openstreetmap.josm.io.OsmTransferException; 35 37 import org.openstreetmap.josm.io.ProgressInputStream; 38 import org.openstreetmap.josm.tools.Utils; 36 39 37 40 … … 53 56 try { 54 57 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, 57 60 width(), height()); 58 61 request.finish(State.IMAGE, grab(url, attempt)); … … 143 146 @Override 144 147 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) { 160 151 request.finish(State.IMAGE, cached); 161 152 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 163 166 return false; 164 167 } … … 180 183 throw new IOException(readException(conn)); 181 184 185 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 182 186 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); 187 197 return img; 188 198 }
Note:
See TracChangeset
for help on using the changeset viewer.
