Ticket #2719: wmsplugin.patch
| File wmsplugin.patch, 27.8 KB (added by , 17 years ago) |
|---|
-
src/wmsplugin/Grabber.java
2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.image.BufferedImage;6 import java.awt.Graphics;7 5 import java.awt.Color; 8 6 import java.awt.Font; 7 import java.awt.Graphics; 8 import java.awt.image.BufferedImage; 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.data.coor.LatLon; 11 13 import org.openstreetmap.josm.data.projection.Projection; 12 14 import org.openstreetmap.josm.gui.MapView; 13 import org.openstreetmap.josm.Main;14 import org.openstreetmap.josm.data.coor.LatLon;15 15 import org.openstreetmap.josm.io.CacheFiles; 16 16 17 17 abstract public class Grabber implements Runnable { … … 23 23 protected GeorefImage image; 24 24 protected CacheFiles cache; 25 25 26 Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image, 27 MapView mv, WMSLayer layer, CacheFiles cache) 26 Grabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) 28 27 { 29 28 if (b.min != null && b.max != null && WMSPlugin.doOverlap) 30 29 { … … 45 44 else 46 45 this.b = b; 47 46 48 this.proj = proj;49 this.pixelPerDegree = pixelPerDegree;47 this.proj = Main.main.proj; 48 this.pixelPerDegree = layer.pixelPerDegree; 50 49 this.image = image; 51 50 this.mv = mv; 52 51 this.layer = layer; -
src/wmsplugin/WMSInfo.java
11 11 12 12 String name; 13 13 String url; 14 String cookies; 14 15 int prefid; 15 16 16 17 public WMSInfo(String name, String url, int prefid) { 17 this .name=name; this.url=url; this.prefid=prefid;18 this(name, url, null, prefid); 18 19 } 19 20 21 public WMSInfo(String name, String url, String cookies, int prefid) { 22 this.name=name; 23 this.url=url; 24 this.cookies=cookies; 25 this.prefid=prefid; 26 } 20 27 21 28 public void save() { 22 29 Main.pref.put("wmsplugin.url." + prefid + ".name", name); 23 30 Main.pref.put("wmsplugin.url." + prefid + ".url", url); 24 31 } 25 public int compareTo(WMSInfo c) 32 33 public int compareTo(WMSInfo in) 26 34 { 27 WMSInfo in = (WMSInfo)c;28 35 Integer i = name.compareTo(in.name); 29 36 if(i == 0) 30 37 i = url.compareTo(in.url); -
src/wmsplugin/WMSLayer.java
58 58 JCheckBoxMenuItem startstop = new JCheckBoxMenuItem(tr("Automatic downloading"), true); 59 59 protected JCheckBoxMenuItem alphaChannel = new JCheckBoxMenuItem(new ToggleAlphaAction()); 60 60 protected String baseURL; 61 protected String cookies; 61 62 protected final int serializeFormatVersion = 4; 62 63 63 64 private ExecutorService executor = null; 64 65 65 66 public WMSLayer() { 66 this(tr("Blank Layer"), null );67 this(tr("Blank Layer"), null, null); 67 68 initializeImages(); 68 69 mv = Main.map.mapView; 69 70 } 70 71 71 public WMSLayer(String name, String baseURL ) {72 public WMSLayer(String name, String baseURL, String cookies) { 72 73 super(name); 73 74 alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel")); 74 75 background = true; /* set global background variable */ 75 76 initializeImages(); 76 77 this.baseURL = baseURL; 78 this.cookies = cookies; 77 79 WMSGrabber.getProjection(baseURL, true); 78 80 mv = Main.map.mapView; 79 81 getPPD(); … … 85 87 public void destroy() { 86 88 try { 87 89 executor.shutdown(); 88 // Might not be initalized, so catch NullPointer as well90 // Might not be initalized, so catch NullPointer as well 89 91 } catch(Exception x) {} 90 92 } 91 93 … … 127 129 128 130 private Bounds XYtoBounds (int x, int y) { 129 131 return new Bounds( 130 new LatLon( x * ImageSize / pixelPerDegree, 131 y * ImageSize / pixelPerDegree), 132 new LatLon((x + 1) * ImageSize / pixelPerDegree, 133 (y + 1) * ImageSize / pixelPerDegree)); 132 new LatLon( x * ImageSize / pixelPerDegree, y * ImageSize / pixelPerDegree), 133 new LatLon((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree)); 134 134 } 135 135 136 136 private int modulo (int a, int b) { 137 if(a%b>=0)return a%b; 138 else return a%b+b; 137 return a % b >= 0 ? a%b : a%b+b; 139 138 } 140 139 141 140 protected Bounds bounds(){ … … 179 178 img.downloadingStarted = true; 180 179 img.image = null; 181 180 img.flushedResizedCachedInstance(); 182 Grabber gr = WMSPlugin.getGrabber( baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);181 Grabber gr = WMSPlugin.getGrabber(XYtoBounds(x,y), img, mv, this); 183 182 executor.submit(gr); 183 } 184 184 } 185 }186 185 } 187 186 188 187 @Override public void visitBoundingBox(BoundingXYVisitor v) { … … 219 218 public GeorefImage findImage(EastNorth eastNorth) { 220 219 for(int x = 0; x<dax; ++x) 221 220 for(int y = 0; y<day; ++y) 222 if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null)223 if(images[x][y].contains(eastNorth, dx, dy))224 return images[x][y];221 if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null) 222 if(images[x][y].contains(eastNorth, dx, dy)) 223 return images[x][y]; 225 224 return null; 226 225 } 227 226 … … 293 292 super(tr("Save WMS layer to file"), ImageProvider.get("save")); 294 293 } 295 294 public void actionPerformed(ActionEvent ev) { 296 File f = DiskAccessAction.createAndOpenSaveFileChooser( 297 tr("Save WMS layer"), ".wms"); 295 File f = DiskAccessAction.createAndOpenSaveFileChooser(tr("Save WMS layer"), ".wms"); 298 296 try 299 297 { 300 298 FileOutputStream fos = new FileOutputStream(f); … … 322 320 } 323 321 public void actionPerformed(ActionEvent ev) { 324 322 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, 325 false, tr("Load WMS layer"));323 false, tr("Load WMS layer")); 326 324 if(fc == null) return; 327 325 File f = fc.getSelectedFile(); 328 326 if (f == null) return; … … 333 331 int sfv = ois.readInt(); 334 332 if (sfv != serializeFormatVersion) { 335 333 JOptionPane.showMessageDialog(Main.parent, 336 tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),337 tr("File Format Error"),338 JOptionPane.ERROR_MESSAGE);334 tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion), 335 tr("File Format Error"), 336 JOptionPane.ERROR_MESSAGE); 339 337 return; 340 338 } 341 339 startstop.setSelected(false); … … 354 352 // FIXME be more specific 355 353 ex.printStackTrace(System.out); 356 354 JOptionPane.showMessageDialog(Main.parent, 357 tr("Error loading file"),358 tr("Error"),359 JOptionPane.ERROR_MESSAGE);355 tr("Error loading file"), 356 tr("Error"), 357 JOptionPane.ERROR_MESSAGE); 360 358 return; 361 359 } 362 360 } -
src/wmsplugin/Map_Rectifier_WMSmenuAction.java
2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent;6 import java.awt.event.KeyEvent;7 import java.awt.datatransfer.DataFlavor;8 import java.awt.datatransfer.Transferable;9 5 import java.awt.GridBagLayout; 10 6 import java.awt.Toolkit; 11 7 import java.awt.datatransfer.DataFlavor; 8 import java.awt.datatransfer.Transferable; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.KeyEvent; 12 11 import java.util.ArrayList; 13 12 import java.util.regex.Matcher; 14 13 import java.util.regex.Pattern; … … 20 19 import javax.swing.JRadioButton; 21 20 import javax.swing.JTextField; 22 21 22 import org.openstreetmap.josm.Main; 23 23 import org.openstreetmap.josm.actions.JosmAction; 24 24 import org.openstreetmap.josm.gui.ExtendedDialog; 25 import org.openstreetmap.josm.gui.MapView;26 import org.openstreetmap.josm.Main;27 25 import org.openstreetmap.josm.tools.GBC; 28 26 import org.openstreetmap.josm.tools.Shortcut; 29 27 import org.openstreetmap.josm.tools.UrlLabel; … … 33 31 * Class that bundles all required information of a rectifier service 34 32 */ 35 33 public class rectifierService { 36 private String name;37 private String url;38 private String wmsUrl;39 private Pattern urlRegEx;40 private Pattern idValidator;34 private final String name; 35 private final String url; 36 private final String wmsUrl; 37 private final Pattern urlRegEx; 38 private final Pattern idValidator; 41 39 public JRadioButton btn; 42 40 /** 43 * @param name: Name of the rectifing service44 * @param url: URL to the service where users can register, upload, etc.45 * @param wmsUrl: URL to the WMS server where JOSM will grab the images. Insert __s__ where the ID should be placed46 * @param urlRegEx: a regular expression that determines if a given URL is one of the service and returns the WMS id if so47 * @param idValidator: regular expression that checks if a given ID is syntactically valid48 */41 * @param name: Name of the rectifing service 42 * @param url: URL to the service where users can register, upload, etc. 43 * @param wmsUrl: URL to the WMS server where JOSM will grab the images. Insert __s__ where the ID should be placed 44 * @param urlRegEx: a regular expression that determines if a given URL is one of the service and returns the WMS id if so 45 * @param idValidator: regular expression that checks if a given ID is syntactically valid 46 */ 49 47 public rectifierService(String name, String url, String wmsUrl, String urlRegEx, String idValidator) { 50 48 this.name = name; 51 49 this.url = url; … … 61 59 62 60 /** 63 61 * List of available rectifier services. May be extended from the outside 64 */62 */ 65 63 public ArrayList<rectifierService> services = new ArrayList<rectifierService>(); 66 64 67 65 public Map_Rectifier_WMSmenuAction() { 68 66 super(tr("Rectified Image..."), 69 "OLmarker",70 tr("Download Rectified Images From Various Services"),71 Shortcut.registerShortcut("wms:rectimg",72 tr("WMS: {0}", tr("Rectified Image...")),73 KeyEvent.VK_R,74 Shortcut.GROUP_NONE),75 true67 "OLmarker", 68 tr("Download Rectified Images From Various Services"), 69 Shortcut.registerShortcut("wms:rectimg", 70 tr("WMS: {0}", tr("Rectified Image...")), 71 KeyEvent.VK_R, 72 Shortcut.GROUP_NONE), 73 true 76 74 ); 77 75 78 76 // Add default services … … 80 78 new rectifierService("Metacarta Map Rectifier", 81 79 "http://labs.metacarta.com/rectifier/", 82 80 "http://labs.metacarta.com/rectifier/wms.cgi?id=__s__&srs=EPSG:4326" 83 + "&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png",81 + "&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png", 84 82 // This matches more than the "classic" WMS link, so users can pretty much 85 83 // copy any link as long as it includes the ID 86 84 "labs\\.metacarta\\.com/(?:.*?)(?:/|=)([0-9]+)(?:\\?|/|\\.|$)", … … 93 91 new rectifierService("Geothings Map Warper", 94 92 "http://warper.geothings.net/", 95 93 "http://warper.geothings.net/maps/wms/__s__?request=GetMap&version=1.1.1" 96 + "&styles=&format=image/png&srs=epsg:4326&exceptions=application/vnd.ogc.se_inimage",94 + "&styles=&format=image/png&srs=epsg:4326&exceptions=application/vnd.ogc.se_inimage", 97 95 // This matches more than the "classic" WMS link, so users can pretty much 98 96 // copy any link as long as it includes the ID 99 "(?:mapwarper\\.net|warper\\.geothings\\.net /(?:.*?)/([0-9]+)(?:\\?|/|\\.|$)",97 "(?:mapwarper\\.net|warper\\.geothings\\.net)/(?:.*?)/([0-9]+)(?:\\?|/|\\.|$)", 100 98 "^[0-9]+$") 101 99 ); 102 100 … … 126 124 // If the contents match, they will be inserted into the text field and the corresponding 127 125 // service will be pre-selected. 128 126 if(!clip.equals("") && tfWmsUrl.getText().equals("") 129 && (s.urlRegEx.matcher(clip).find() || s.idValidator.matcher(clip).matches())) {127 && (s.urlRegEx.matcher(clip).find() || s.idValidator.matcher(clip).matches())) { 130 128 serviceBtn.setSelected(true); 131 129 tfWmsUrl.setText(clip); 132 130 } … … 147 145 panel.add(tfWmsUrl, GBC.eol().fill(GBC.HORIZONTAL)); 148 146 149 147 ExtendedDialog diag = new ExtendedDialog(Main.parent, 150 tr("Add Rectified Image"),151 panel,152 new String[] {tr("Add Rectified Image"), tr("Cancel")},153 new String[] {"OLmarker.png", "cancel.png"});148 tr("Add Rectified Image"), 149 panel, 150 new String[] {tr("Add Rectified Image"), tr("Cancel")}, 151 new String[] {"OLmarker.png", "cancel.png"}); 154 152 155 153 // This repeatedly shows the dialog in case there has been an error. 156 154 // The loop is break;-ed if the users cancels … … 197 195 198 196 // and display an error message. The while(true) ensures that the dialog pops up again 199 197 JOptionPane.showMessageDialog(Main.parent, 200 tr("Couldn't match the entered link or id to the selected service. Please try again."),201 tr("No valid WMS URL or id"),202 JOptionPane.ERROR_MESSAGE);198 tr("Couldn't match the entered link or id to the selected service. Please try again."), 199 tr("No valid WMS URL or id"), 200 JOptionPane.ERROR_MESSAGE); 203 201 diag.setVisible(true); 204 202 } 205 203 } 206 204 207 205 /** 208 * Adds a WMS Layer with given title and UR :206 * Adds a WMS Layer with given title and URL 209 207 * @param title: Name of the layer as it will shop up in the layer manager 210 208 * @param url: URL to the WMS server 209 * @param cookies: Cookies to send with each image request (Format: josm=is; very=cool) 211 210 */ 212 private void addWMSLayer(String title, String url ) {213 WMSLayer wmsLayer = new WMSLayer(title, url );211 private void addWMSLayer(String title, String url, String cookies) { 212 WMSLayer wmsLayer = new WMSLayer(title, url, cookies); 214 213 Main.main.addLayer(wmsLayer); 215 214 } 216 215 217 216 /** 217 * Adds a WMS Layer with given title and URL 218 * @param title: Name of the layer as it will shop up in the layer manager 219 * @param url: URL to the WMS server 220 */ 221 private void addWMSLayer(String title, String url) { 222 addWMSLayer(title, url, ""); 223 } 224 225 /** 218 226 * Helper function that extracts a String from the Clipboard if available. 219 227 * Returns an empty String otherwise 220 228 * @return String Clipboard contents if available -
src/wmsplugin/WMSGrabber.java
16 16 import java.text.MessageFormat; 17 17 import java.text.NumberFormat; 18 18 import java.util.Locale; 19 import java.util.concurrent.TimeUnit;20 19 import java.util.regex.Matcher; 21 20 import java.util.regex.Pattern; 22 21 … … 25 24 26 25 import org.openstreetmap.josm.Main; 27 26 import org.openstreetmap.josm.data.Bounds; 28 import org.openstreetmap.josm.data.projection.Projection;29 27 import org.openstreetmap.josm.gui.MapView; 30 28 import org.openstreetmap.josm.io.CacheFiles; 31 29 import org.openstreetmap.josm.io.ProgressInputStream; … … 33 31 34 32 public class WMSGrabber extends Grabber { 35 33 protected String baseURL; 36 private static Boolean shownWarning = false; 37 private boolean urlWithPatterns; 34 private final boolean urlWithPatterns; 38 35 39 WMSGrabber(String baseURL, Bounds b, Projection proj, 40 double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 41 super(b, proj, pixelPerDegree, image, mv, layer, cache); 42 this.baseURL = baseURL; 36 WMSGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 37 super(b, image, mv, layer, cache); 38 this.baseURL = layer.baseURL; 43 39 /* URL containing placeholders? */ 44 40 urlWithPatterns = baseURL != null && baseURL.contains("{1}"); 45 41 } … … 70 66 } 71 67 } 72 68 73 public static final NumberFormat 74 latLonFormat = new DecimalFormat("###0.0000000", 69 public static final NumberFormat latLonFormat = new DecimalFormat("###0.0000000", 75 70 new DecimalFormatSymbols(Locale.US)); 76 71 77 72 protected URL getURL(double w, double s,double e,double n, 78 73 int wi, int ht) throws MalformedURLException { 79 74 String str = baseURL; 80 String bbox = latLonFormat.format(w) + "," +81 latLonFormat.format(s) + "," +82 latLonFormat.format(e) + "," +83 latLonFormat.format(n);75 String bbox = latLonFormat.format(w) + "," 76 + latLonFormat.format(s) + "," 77 + latLonFormat.format(e) + "," 78 + latLonFormat.format(n); 84 79 85 80 if (urlWithPatterns) { 86 81 String proj = Main.proj.toCode(); … … 131 126 protected BufferedImage grab(URL url) throws IOException { 132 127 BufferedImage cached = cache.getImg(url.toString()); 133 128 if(cached != null) return cached; 134 129 135 130 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 131 if(layer.cookies != null && !layer.cookies.equals("")) 132 conn.setRequestProperty("Cookie", layer.cookies); 136 133 conn.setConnectTimeout(Main.pref.getInteger("wmsplugin.timeout.connect", 30) * 1000); 137 134 conn.setReadTimeout(Main.pref.getInteger("wmsplugin.timeout.read", 30) * 1000); 138 135 … … 145 142 InputStream is = new ProgressInputStream(conn, null); 146 143 BufferedImage img = ImageIO.read(is); 147 144 is.close(); 148 145 149 146 cache.saveImg(url.toString(), img); 150 147 return img; 151 148 } -
src/wmsplugin/WMSDownloadAction.java
6 6 7 7 import org.openstreetmap.josm.Main; 8 8 import org.openstreetmap.josm.actions.JosmAction; 9 import org.openstreetmap.josm.gui.MapView;10 import org.openstreetmap.josm.gui.layer.Layer;11 import org.openstreetmap.josm.data.Bounds;12 9 13 10 public class WMSDownloadAction extends JosmAction { 14 11 15 private WMSInfo info;12 private final WMSInfo info; 16 13 17 14 public WMSDownloadAction(WMSInfo info) { 18 15 super(info.name, "wmsmenu", tr("Download WMS tile from {0}",info.name), null, false); … … 23 20 public void actionPerformed(ActionEvent e) { 24 21 System.out.println(info.url); 25 22 26 WMSLayer wmsLayer = new WMSLayer(info.name, info.url );23 WMSLayer wmsLayer = new WMSLayer(info.name, info.url, info.cookies); 27 24 Main.main.addLayer(wmsLayer); 28 25 } 29 26 30 27 public static WMSLayer getLayer(WMSInfo info) { 31 28 // FIXME: move this to WMSPlugin/WMSInfo/preferences. 32 WMSLayer wmsLayer = new WMSLayer(info.name, info.url );29 WMSLayer wmsLayer = new WMSLayer(info.name, info.url, info.cookies); 33 30 Main.main.addLayer(wmsLayer); 34 31 return wmsLayer; 35 32 } -
src/wmsplugin/YAHOOGrabber.java
1 1 package wmsplugin; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 5 3 import java.awt.image.BufferedImage; 6 import java.awt.Image;7 import java.net.URL;8 4 import java.io.IOException; 5 import java.net.URL; 9 6 import java.text.MessageFormat; 10 7 import java.util.ArrayList; 11 8 import java.util.StringTokenizer; 12 9 13 10 import javax.imageio.ImageIO; 14 11 15 import org.openstreetmap.josm.Main;16 12 import org.openstreetmap.josm.data.Bounds; 17 import org.openstreetmap.josm.data.projection.Projection;18 import org.openstreetmap.josm.io.CacheFiles;19 13 import org.openstreetmap.josm.gui.MapView; 14 import org.openstreetmap.josm.io.CacheFiles; 20 15 21 16 22 17 public class YAHOOGrabber extends WMSGrabber { 23 18 protected String browserCmd; 24 19 25 YAHOOGrabber(String baseURL, Bounds b, Projection proj, 26 double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 27 super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?" 28 , b, proj, pixelPerDegree, image, mv, layer, cache); 29 this.browserCmd = baseURL.replaceFirst("yahoo://", ""); 20 YAHOOGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) { 21 super(b, image, mv, layer, cache); 22 layer.baseURL = "file:///" + WMSPlugin.getPrefsPath() + "ymap.html?"; 23 this.browserCmd = layer.baseURL.replaceFirst("yahoo://", ""); 30 24 } 31 25 26 @Override 32 27 protected BufferedImage grab(URL url) throws IOException { 33 28 String urlstring = url.toExternalForm(); 34 29 // work around a problem in URL removing 2 slashes … … 52 47 } catch(IOException ioe) { 53 48 throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() ); 54 49 } 55 50 56 51 BufferedImage img = ImageIO.read(browser.getInputStream()); 57 52 cache.saveImg(urlstring, img); 58 53 return img; -
src/wmsplugin/WMSPlugin.java
5 5 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.io.BufferedReader; 9 import java.io.File; 10 import java.io.FileNotFoundException; 11 import java.io.FileOutputStream; 12 import java.io.IOException; 13 import java.io.InputStream; 14 import java.io.InputStreamReader; 15 import java.io.UnsupportedEncodingException; 8 16 import java.util.ArrayList; 9 17 import java.util.Collections; 10 18 import java.util.Map; 11 import java.util.TreeSet;12 19 import java.util.TreeMap; 13 import java. io.*;20 import java.util.TreeSet; 14 21 15 import javax.swing.AbstractAction;16 import javax.swing.AbstractButton;17 22 import javax.swing.JMenu; 18 23 import javax.swing.JMenuItem; 19 24 20 25 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.plugins.Plugin; 26 import org.openstreetmap.josm.actions.JosmAction; 27 import org.openstreetmap.josm.data.Bounds; 28 import org.openstreetmap.josm.gui.IconToggleButton; 22 29 import org.openstreetmap.josm.gui.MainMenu; 23 30 import org.openstreetmap.josm.gui.MapFrame; 24 import org.openstreetmap.josm.gui. IconToggleButton;31 import org.openstreetmap.josm.gui.MapView; 25 32 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 26 33 import org.openstreetmap.josm.io.CacheFiles; 27 34 import org.openstreetmap.josm.io.MirroredInputStream; 28 import org.openstreetmap.josm.actions.JosmAction; 29 import org.openstreetmap.josm.data.Bounds; 30 import org.openstreetmap.josm.data.projection.Projection; 31 import org.openstreetmap.josm.gui.MapView; 35 import org.openstreetmap.josm.plugins.Plugin; 32 36 33 37 public class WMSPlugin extends Plugin { 34 38 static CacheFiles cache = new CacheFiles("wmsplugin"); … … 103 107 int prefid = 0; 104 108 String name = null; 105 109 String url = null; 110 String cookies = ""; 106 111 int lastid = -1; 107 112 for (String key : keys) { 108 113 String[] elements = key.split("\\."); … … 119 124 name = prefs.get(key); 120 125 else if (elements[3].equals("url")) 121 126 url = prefs.get(key); 127 else if (elements[3].equals("cookies")) 128 cookies = prefs.get(key); 122 129 if (name != null && url != null) 123 wmsList.add(new WMSInfo(name, url, prefid));130 wmsList.add(new WMSInfo(name, url, cookies, prefid)); 124 131 } 125 132 String source = "http://svn.openstreetmap.org/applications/editors/josm/plugins/wmsplugin/sources.cfg"; 126 133 try 127 134 { 128 135 MirroredInputStream s = new MirroredInputStream(source, 129 Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1);136 Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1); 130 137 InputStreamReader r; 131 138 try 132 139 { … … 199 206 } 200 207 } 201 208 202 public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj, 203 double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){ 204 if(_baseURL.startsWith("yahoo://")) 205 return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache); 209 // baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this 210 // Grabber gr = WMSPlugin.getGrabber(XYtoBounds(x,y), img, mv, this); 211 public static Grabber getGrabber(Bounds bounds, GeorefImage img, MapView mv, WMSLayer layer){ 212 if(layer.baseURL.startsWith("yahoo://")) 213 return new YAHOOGrabber(bounds, img, mv, layer, cache); 206 214 else 207 return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache); 215 return new WMSGrabber(bounds, img, mv, layer, cache); 216 208 217 // OSBGrabber should be rewrite for thread support first 209 //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ) {218 //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ) 210 219 // return new OSGBGrabber(_b, _proj, _pixelPerDegree, _images, _mv, _layer); 211 //} else {212 // return new WMSGrabber(_b, _proj, _pixelPerDegree, _images, _mv, _layer);213 //}214 220 } 215 221 216 222 private static void setEnabledAll(boolean isEnabled) { … … 219 225 220 226 if(item != null) item.setEnabled(isEnabled); 221 227 } 222 menuEnabled = isEnabled;228 menuEnabled = isEnabled; 223 229 } 224 230 225 231 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 226 232 if (oldFrame==null && newFrame!=null) { 227 233 setEnabledAll(true); 228 234 Main.map.addMapMode(new IconToggleButton 229 (new WMSAdjustAction(Main.map)));235 (new WMSAdjustAction(Main.map))); 230 236 } else if (oldFrame!=null && newFrame==null ) { 231 237 setEnabledAll(false); 232 238 }
