Changeset 6780 in osm for applications


Ignore:
Timestamp:
2008-02-06T16:45:02+01:00 (17 years ago)
Author:
gabriel
Message:

wmsplugin: Move graber chooser out of WMSDownloadAction.

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/DownloadWMSTask.java

    r6777 r6780  
    3535        @Override protected void finish() {}
    3636
    37         public static void download(String name, String wmsurl,
    38                         Bounds b, double pixelPerDegree) {
    39                 WMSLayer wmsLayer = null;
    40 
    41                 // simply check if we already have a layer created. if not, create; if yes, reuse.
    42                 for (Layer l : Main.main.map.mapView.getAllLayers()) {
    43                         if (l instanceof WMSLayer && l.name.equals(name)) {
    44                                 wmsLayer = (WMSLayer) l;
    45                         }
    46                 }
    47 
    48                 // FIXME: move this to WMSPlugin/WMSInfo/preferences.
    49                 if (wmsLayer == null) {
    50                         if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
    51                                 wmsLayer = new WMSLayer(name, new OSGBGrabber(wmsurl));
    52                         } else {
    53                                 wmsLayer = new WMSLayer(name, new WMSGrabber(wmsurl));
    54                         }
    55                         Main.main.addLayer(wmsLayer);
    56                 }
    57 
    58                 Main.worker.execute(new DownloadWMSTask(wmsLayer, b, pixelPerDegree));
    59         }
    60 
    61         public static void download(String name, String wmsurl) {
     37        public static void download(WMSLayer wmsLayer) {
    6238                MapView mv = Main.map.mapView;
    6339
     
    6642                        mv.getLatLon(mv.getWidth(), 0));
    6743
    68                 download(name, wmsurl, b, mv.getWidth() / (b.max.lon() - b.min.lon()));
     44                Main.worker.execute(new DownloadWMSTask(wmsLayer, b,
     45                        mv.getWidth() / (b.max.lon() - b.min.lon())));
    6946        }
    7047}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java

    r6777 r6780  
    66import org.openstreetmap.josm.actions.JosmAction;
    77import org.openstreetmap.josm.gui.MapView;
     8import org.openstreetmap.josm.gui.layer.Layer;
    89
    910public class WMSDownloadAction extends JosmAction {
     
    1920                System.out.println(info.url);
    2021               
    21                 MapView mv = Main.map.mapView;
    22                
    23                 DownloadWMSTask.download(info.name, info.url);
     22                DownloadWMSTask.download(getLayer(info));
     23        }
     24
     25        public static WMSLayer getLayer(WMSInfo info) {
     26                // simply check if we already have a layer created. if not, create; if yes, reuse.
     27                for (Layer l : Main.main.map.mapView.getAllLayers()) {
     28                        if (l instanceof WMSLayer && l.name.equals(info.name)) {
     29                                return (WMSLayer) l;
     30                        }
     31                }
     32
     33                // FIXME: move this to WMSPlugin/WMSInfo/preferences.
     34                WMSLayer wmsLayer = new WMSLayer(info.name, info.grabber);
     35                Main.main.addLayer(wmsLayer);
     36                return wmsLayer;
    2437        }
    2538};
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java

    r6776 r6780  
    1212        String name;
    1313        String url;
     14        Grabber grabber;
    1415        int prefid;
    1516       
     17        public WMSInfo(String name, String url, Grabber grabber, int prefid) {
     18                this.name=name; this.url=url; this.prefid=prefid;
     19                this.grabber = grabber;
     20        }
     21
    1622        public WMSInfo(String name, String url, int prefid) {
    17                 this.name=name; this.url=url; this.prefid=prefid;
     23                this(name, url, WMSPlugin.getGrabber(url), prefid);
    1824        }
    1925       
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r6776 r6780  
    120120                setEnabledAll(false);
    121121        }
     122
     123        public static Grabber getGrabber(String wmsurl) {
     124                if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
     125                        return new OSGBGrabber(wmsurl);
     126                } else {
     127                        return new WMSGrabber(wmsurl);
     128                }
     129        }
    122130       
    123131        private static void setEnabledAll(boolean isEnabled) {
Note: See TracChangeset for help on using the changeset viewer.