Changeset 4745 in josm for trunk/src/org/openstreetmap/josm/io/imagery
- Timestamp:
- 2011-12-29T18:07:04+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/imagery
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/imagery/Grabber.java
r4126 r4745 4 4 import org.openstreetmap.josm.Main; 5 5 import org.openstreetmap.josm.data.ProjectionBounds; 6 import org.openstreetmap.josm.data.coor.EastNorth;7 6 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 8 import org.openstreetmap.josm.data.projection.Projection;9 7 import org.openstreetmap.josm.gui.MapView; 10 8 import org.openstreetmap.josm.gui.layer.WMSLayer; … … 13 11 protected final MapView mv; 14 12 protected final WMSLayer layer; 13 private final boolean localOnly; 15 14 16 15 protected ProjectionBounds b; 17 protected Projection proj;18 protected double pixelPerDegree;19 protected WMSRequest request;20 16 protected volatile boolean canceled; 21 17 22 Grabber(MapView mv, WMSLayer layer ) {18 Grabber(MapView mv, WMSLayer layer, boolean localOnly) { 23 19 this.mv = mv; 24 20 this.layer = layer; 25 } 26 27 private void updateState(WMSRequest request) { 28 b = new ProjectionBounds( 29 layer.getEastNorth(request.getXIndex(), request.getYIndex()), 30 layer.getEastNorth(request.getXIndex() + 1, request.getYIndex() + 1)); 31 if (WMSLayer.PROP_OVERLAP.get()) { 32 double eastSize = b.maxEast - b.minEast; 33 double northSize = b.maxNorth - b.minNorth; 34 35 double eastCoef = WMSLayer.PROP_OVERLAP_EAST.get() / 100.0; 36 double northCoef = WMSLayer.PROP_OVERLAP_NORTH.get() / 100.0; 37 38 this.b = new ProjectionBounds(b.getMin(), 39 new EastNorth(b.maxEast + eastCoef * eastSize, 40 b.maxNorth + northCoef * northSize)); 41 } 42 43 this.proj = Main.getProjection(); 44 this.pixelPerDegree = request.getPixelPerDegree(); 45 this.request = request; 21 this.localOnly = localOnly; 46 22 } 47 23 … … 60 36 if (canceled) 61 37 return; 62 WMSRequest request = layer.getRequest( );38 WMSRequest request = layer.getRequest(localOnly); 63 39 if (request == null) 64 40 return; 65 updateState(request); 66 if(!loadFromCache(request)){ 67 attempt(request); 41 this.b = layer.getBounds(request); 42 if (request.isPrecacheOnly()) { 43 if (!layer.cache.hasExactMatch(Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth)) { 44 attempt(request); 45 } 46 } else { 47 if(!loadFromCache(request)){ 48 attempt(request); 49 } 68 50 } 69 51 layer.finishRequest(request); … … 77 59 return; 78 60 try { 79 if (! layer.requestIsValid(request))61 if (!request.isPrecacheOnly() && !layer.requestIsVisible(request)) 80 62 return; 81 63 fetch(request, i); -
trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java
r4126 r4745 22 22 public static final StringProperty PROP_BROWSER = new StringProperty("imagery.wms.browser", "webkit-image {0}"); 23 23 24 public HTMLGrabber(MapView mv, WMSLayer layer ) {25 super(mv, layer );24 public HTMLGrabber(MapView mv, WMSLayer layer, boolean localOnly) { 25 super(mv, layer, localOnly); 26 26 } 27 27 28 28 @Override 29 protected BufferedImage grab( URL url, int attempt) throws IOException {29 protected BufferedImage grab(WMSRequest request, URL url, int attempt) throws IOException { 30 30 String urlstring = url.toExternalForm(); 31 31 … … 52 52 BufferedImage img = layer.normalizeImage(ImageIO.read(bais)); 53 53 bais.reset(); 54 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth);54 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth); 55 55 56 56 return img; -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r4432 r4745 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.io.imagery; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.awt.image.BufferedImage; … … 18 16 import java.text.DecimalFormatSymbols; 19 17 import java.text.NumberFormat; 20 import java.util.ArrayList; 21 import java.util.List; 22 import java.util.Map.Entry; 18 import java.util.HashMap; 23 19 import java.util.Locale; 24 20 import java.util.Map; 25 import java.util. HashMap;21 import java.util.Map.Entry; 26 22 import java.util.regex.Matcher; 27 23 import java.util.regex.Pattern; 28 24 29 25 import javax.imageio.ImageIO; 30 import javax.swing.JOptionPane;31 26 32 27 import org.openstreetmap.josm.Main; … … 50 45 private Map<String, String> props = new HashMap<String, String>(); 51 46 52 public WMSGrabber(MapView mv, WMSLayer layer ) {53 super(mv, layer );47 public WMSGrabber(MapView mv, WMSLayer layer, boolean localOnly) { 48 super(mv, layer, localOnly); 54 49 this.info = layer.getInfo(); 55 50 this.baseURL = info.getUrl(); … … 77 72 b.maxEast, b.maxNorth, 78 73 width(), height()); 79 request.finish(State.IMAGE, grab( url, attempt));74 request.finish(State.IMAGE, grab(request, url, attempt)); 80 75 81 76 } catch(Exception e) { … … 102 97 103 98 return new URL(baseURL.replaceAll("\\{proj(\\([^})]+\\))?\\}", myProj) 104 .replaceAll("\\{bbox\\}", latLonFormat.format(w) + ","105 + latLonFormat.format(s) + ","106 + latLonFormat.format(e) + ","107 + latLonFormat.format(n))108 .replaceAll("\\{w\\}", latLonFormat.format(w))109 .replaceAll("\\{s\\}", latLonFormat.format(s))110 .replaceAll("\\{e\\}", latLonFormat.format(e))111 .replaceAll("\\{n\\}", latLonFormat.format(n))112 .replaceAll("\\{width\\}", String.valueOf(wi))113 .replaceAll("\\{height\\}", String.valueOf(ht))114 .replace(" ", "%20"));99 .replaceAll("\\{bbox\\}", latLonFormat.format(w) + "," 100 + latLonFormat.format(s) + "," 101 + latLonFormat.format(e) + "," 102 + latLonFormat.format(n)) 103 .replaceAll("\\{w\\}", latLonFormat.format(w)) 104 .replaceAll("\\{s\\}", latLonFormat.format(s)) 105 .replaceAll("\\{e\\}", latLonFormat.format(e)) 106 .replaceAll("\\{n\\}", latLonFormat.format(n)) 107 .replaceAll("\\{width\\}", String.valueOf(wi)) 108 .replaceAll("\\{height\\}", String.valueOf(ht)) 109 .replace(" ", "%20")); 115 110 } 116 111 117 112 @Override 118 113 public boolean loadFromCache(WMSRequest request) { 119 BufferedImage cached = layer.cache.getExactMatch(Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth);114 BufferedImage cached = layer.cache.getExactMatch(Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth); 120 115 121 116 if (cached != null) { … … 123 118 return true; 124 119 } else if (request.isAllowPartialCacheMatch()) { 125 BufferedImage partialMatch = layer.cache.getPartialMatch(Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth);120 BufferedImage partialMatch = layer.cache.getPartialMatch(Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth); 126 121 if (partialMatch != null) { 127 122 request.finish(State.PARTLY_IN_CACHE, partialMatch); … … 138 133 } 139 134 140 protected BufferedImage grab( URL url, int attempt) throws IOException, OsmTransferException {135 protected BufferedImage grab(WMSRequest request, URL url, int attempt) throws IOException, OsmTransferException { 141 136 System.out.println("Grabbing WMS " + (attempt > 1? "(attempt " + attempt + ") ":"") + url); 142 137 … … 164 159 BufferedImage img = layer.normalizeImage(ImageIO.read(bais)); 165 160 bais.reset(); 166 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), pixelPerDegree, b.minEast, b.minNorth);161 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth); 167 162 return img; 168 163 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSRequest.java
r4065 r4745 5 5 6 6 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 7 import org.openstreetmap.josm.gui.layer.WMSLayer.PrecacheTask; 7 8 8 9 public class WMSRequest implements Comparable<WMSRequest> { … … 11 12 private final double pixelPerDegree; 12 13 private final boolean real; // Download even if autodownloading is disabled 14 private final PrecacheTask precacheTask; // Download even when wms tile is not currently visible (precache) 13 15 private final boolean allowPartialCacheMatch; 14 16 private int priority; 17 private boolean hasExactMatch; 15 18 // Result 16 19 private State state; … … 18 21 19 22 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch) { 23 this(xIndex, yIndex, pixelPerDegree, real, allowPartialCacheMatch, null); 24 } 25 26 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch, PrecacheTask precacheTask) { 20 27 this.xIndex = xIndex; 21 28 this.yIndex = yIndex; 22 29 this.pixelPerDegree = pixelPerDegree; 23 30 this.real = real; 31 this.precacheTask = precacheTask; 24 32 this.allowPartialCacheMatch = allowPartialCacheMatch; 25 33 } 34 26 35 27 36 public void finish(State state, BufferedImage image) { … … 99 108 public String toString() { 100 109 return "WMSRequest [xIndex=" + xIndex + ", yIndex=" + yIndex 101 + ", pixelPerDegree=" + pixelPerDegree + "]";110 + ", pixelPerDegree=" + pixelPerDegree + "]"; 102 111 } 103 112 … … 106 115 } 107 116 117 public boolean isPrecacheOnly() { 118 return precacheTask != null; 119 } 120 121 public PrecacheTask getPrecacheTask() { 122 return precacheTask; 123 } 124 108 125 public boolean isAllowPartialCacheMatch() { 109 126 return allowPartialCacheMatch; 110 127 } 128 129 public boolean hasExactMatch() { 130 return hasExactMatch; 131 } 132 133 public void setHasExactMatch(boolean hasExactMatch) { 134 this.hasExactMatch = hasExactMatch; 135 } 111 136 }
Note:
See TracChangeset
for help on using the changeset viewer.