Changeset 13645 in osm for applications/editors/josm/plugins/wmsplugin
- Timestamp:
- 2009-02-10T17:42:52+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java
r13497 r13645 1 1 package wmsplugin; 2 2 3 import java.awt.Dimension; 3 4 import java.awt.Graphics; 4 5 import java.awt.Point; … … 16 17 public class GeorefImage implements Serializable { 17 18 public BufferedImage image = null; 19 private BufferedImage reImg = null; 20 private Dimension reImgHash = new Dimension(0, 0); 18 21 public EastNorth min, max; 19 22 public boolean downloadingStarted; … … 44 47 Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma); 45 48 49 // downloadAndPaintVisible in WMSLayer.java requests visible images only 50 // so this path is never hit. 46 51 /* this is isVisible() but taking dx, dy into account */ 47 if(!(g.hitClip(minPt.x, maxPt.y, 48 maxPt.x - minPt.x, minPt.y - maxPt.y))) 52 /*if(!(g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y))) { 49 53 return false; 54 }*/ 55 56 // Width and height flicker about 2 pixels due to rounding errors, typically only 1 57 int width = Math.abs(maxPt.x-minPt.x); 58 int height = Math.abs(minPt.y-maxPt.y); 59 int diffx = reImgHash.width - width; 60 int diffy = reImgHash.height - height; 61 62 // We still need to re-render if the requested size is larger (otherwise we'll have black lines) 63 // If it's only up to two pixels smaller, just draw the old image, the errors are minimal 64 // but the performance improvements when moving are huge 65 // Zooming is still slow because the images need to be resized 66 if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) { 67 g.drawImage(reImg, minPt.x, maxPt.y, null); 68 return true; 69 } 50 70 51 g.drawImage(image, 52 minPt.x, maxPt.y, maxPt.x, minPt.y, // dest 71 // We haven't got a saved resized copy, so resize and cache it 72 reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 73 reImg.getGraphics().drawImage(image, 74 0, 0, width, height, // dest 53 75 0, 0, image.getWidth(), image.getHeight(), // src 54 76 null); 55 77 78 reImgHash.setSize(width, height); 79 g.drawImage(reImg, minPt.x, maxPt.y, null); 56 80 return true; 57 81 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java
r13618 r13645 31 31 public class WMSGrabber extends Grabber { 32 32 protected String baseURL; 33 protected Cache cache = new wmsplugin.Cache(); 33 34 private static Boolean shownWarning = false; 34 35 … … 112 113 113 114 protected BufferedImage grab(URL url) throws IOException { 115 BufferedImage cached = cache.getImg(url.toString()); 116 if(cached != null) return cached; 117 114 118 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 115 119 … … 123 127 BufferedImage img = ImageIO.read(is); 124 128 is.close(); 125 return img; 129 130 return cache.saveImg(url.toString(), img, true); 126 131 } 127 132 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java
r13497 r13645 8 8 * @author Frederik Ramm <frederik@remote.org> 9 9 */ 10 public class WMSInfo implements Comparable {10 public class WMSInfo implements Comparable<WMSInfo> { 11 11 12 12 String name; … … 23 23 Main.pref.put("wmsplugin.url." + prefid + ".url", url); 24 24 } 25 public int compareTo( Objectc)25 public int compareTo(WMSInfo c) 26 26 { 27 Integer i = 0; 28 if(c instanceof WMSInfo) 29 { 30 WMSInfo in = (WMSInfo)c; 31 i = name.compareTo(in.name); 32 if(i == 0) 33 i = url.compareTo(in.url); 34 if(i == 0) 35 i = prefid-in.prefid; 36 } 27 WMSInfo in = (WMSInfo)c; 28 Integer i = name.compareTo(in.name); 29 if(i == 0) 30 i = url.compareTo(in.url); 31 if(i == 0) 32 i = prefid-in.prefid; 37 33 return i; 38 34 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r13600 r13645 177 177 } 178 178 } 179 180 new wmsplugin.Cache().cleanUp(); 179 181 } 180 182 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r13497 r13645 31 31 import org.openstreetmap.josm.gui.MapView; 32 32 33 34 // NW 151006 only add the landsat task when the map frame is initialised with35 // data.36 37 38 39 33 public class WMSPlugin extends Plugin { 40 34 … … 66 60 public void copy(String from, String to) throws FileNotFoundException, IOException 67 61 { 68 File pluginDir = new File( Main.pref.getPreferencesDir() + "plugins/wmsplugin/");62 File pluginDir = new File(getPrefsPath()); 69 63 if (!pluginDir.exists()) 70 64 pluginDir.mkdirs(); 71 FileOutputStream out = new FileOutputStream( Main.pref.getPreferencesDir() + "plugins/wmsplugin/"+ to);65 FileOutputStream out = new FileOutputStream(getPrefsPath() + to); 72 66 InputStream in = WMSPlugin.class.getResourceAsStream(from); 73 67 byte[] buffer = new byte[8192]; … … 222 216 return new WMSPreferenceEditor(); 223 217 } 218 219 static public String getPrefsPath() 220 { 221 return Main.pref.getPluginsDirFile().getPath() + "wmsplugin/"; 222 } 224 223 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java
r13497 r13645 21 21 public class YAHOOGrabber extends WMSGrabber{ 22 22 protected String browserCmd; 23 protected Cache cache = new wmsplugin.Cache(); 23 24 24 25 YAHOOGrabber(String baseURL, Bounds b, Projection proj, 25 26 double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) { 26 super("file:///" + Main.pref.getPreferencesDir() + "plugins/wmsplugin/ymap.html?" 27 // + "request=getmap&format=image/jpeg" 27 super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?" 28 28 , b, proj, pixelPerDegree, image, mv, layer); 29 29 this.browserCmd = baseURL.replaceFirst("yahoo://", ""); … … 31 31 32 32 protected BufferedImage grab(URL url) throws IOException { 33 ArrayList<String> cmdParams = new ArrayList<String>();34 33 String urlstring = url.toExternalForm(); 35 34 // work around a problem in URL removing 2 slashes 36 35 if(!urlstring.startsWith("file:///")) 37 36 urlstring = urlstring.replaceFirst("file:", "file://"); 37 38 BufferedImage cached = cache.getImg(urlstring); 39 if(cached != null) return cached; 40 41 ArrayList<String> cmdParams = new ArrayList<String>(); 38 42 StringTokenizer st = new StringTokenizer(MessageFormat.format(browserCmd, urlstring)); 39 43 while( st.hasMoreTokens() ) … … 50 54 } 51 55 52 return ImageIO.read(browser.getInputStream());56 return cache.saveImg(urlstring, ImageIO.read(browser.getInputStream()), true); 53 57 } 54 58 }
Note:
See TracChangeset
for help on using the changeset viewer.