Ignore:
Timestamp:
2009-07-03T12:34:14+02:00 (15 years ago)
Author:
stoecker
Message:

adapted plugins to JOSm 1722, UtilsPlugin still has a problem

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

Legend:

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

    r15858 r16290  
    99
    1010import org.openstreetmap.josm.Main;
    11 import org.openstreetmap.josm.data.Bounds;
    12 import org.openstreetmap.josm.data.coor.LatLon;
     11import org.openstreetmap.josm.data.ProjectionBounds;
     12import org.openstreetmap.josm.data.coor.EastNorth;
    1313import org.openstreetmap.josm.data.projection.Projection;
    1414import org.openstreetmap.josm.gui.MapView;
     
    1616
    1717abstract public class Grabber implements Runnable {
    18     protected Bounds b;
     18    protected ProjectionBounds b;
    1919    protected Projection proj;
    2020    protected double pixelPerDegree;
     
    2424    protected CacheFiles cache;
    2525
    26     Grabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache)
     26    Grabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache)
    2727    {
    28         if (b.min != null && b.max != null && WMSPlugin.doOverlap)
    29         {
    30             double latCent = (b.min.lat() + b.max.lat()) / 2;
    31             double lonCent = (b.min.lon() + b.max.lon()) / 2;
    32 
    33             double latSize =  b.max.lat() - b.min.lat();
    34             double lonSize =  b.max.lon() - b.min.lon();
    35 
    36             double latCoef = (100.0 + WMSPlugin.overlapLat) / 100.0 / 2.0;
    37             double lonCoef = (100.0 + WMSPlugin.overlapLon) / 100.0 / 2.0;
    38 
    39             this.b = new Bounds( new LatLon(latCent - latCoef * latSize,
    40                                             lonCent - lonCoef * lonSize),
    41                                  new LatLon(latCent + latCoef * latSize,
    42                                             lonCent + lonCoef * lonSize));
    43         }
    44         else
    45             this.b = b;
    46 
     28        this.b = b;
    4729        this.proj = Main.main.proj;
    4830        this.pixelPerDegree = layer.pixelPerDegree;
     
    5638
    5739    int width(){
    58         return (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
     40        return (int) ((b.max.north() - b.min.north()) * pixelPerDegree);
    5941    }
    6042    int height(){
    61         return (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
     43        return (int) ((b.max.east() - b.min.east()) * pixelPerDegree);
    6244    }
    6345
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r15961 r16290  
    2424
    2525import org.openstreetmap.josm.Main;
    26 import org.openstreetmap.josm.data.Bounds;
     26import org.openstreetmap.josm.data.ProjectionBounds;
     27import org.openstreetmap.josm.data.coor.EastNorth;
     28import org.openstreetmap.josm.data.coor.LatLon;
     29import org.openstreetmap.josm.data.projection.Epsg4326;
     30import org.openstreetmap.josm.data.projection.Mercator;
    2731import org.openstreetmap.josm.gui.MapView;
    2832import org.openstreetmap.josm.io.CacheFiles;
     
    3539    private final boolean urlWithPatterns;
    3640
    37     WMSGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
     41    WMSGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
    3842        super(b, image, mv, layer, cache);
    3943        this.baseURL = layer.baseURL;
     
    5155        try {
    5256            url = getURL(
    53                 b.min.lon(), b.min.lat(),
    54                 b.max.lon(), b.max.lat(),
     57                b.min.east(), b.min.north(),
     58                b.max.east(), b.max.north(),
    5559                width(), height());
    5660
    57             image.min = proj.latlon2eastNorth(b.min);
    58             image.max = proj.latlon2eastNorth(b.max);
     61            image.min = b.min;
     62            image.max = b.max;
    5963
     64System.out.println(url + " " + b + " " + image.min + " " + image.max);
    6065            if(image.isVisible(mv)) { //don't download, if the image isn't visible already
    6166                image.image = grab(url);
     
    7378    protected URL getURL(double w, double s,double e,double n,
    7479            int wi, int ht) throws MalformedURLException {
     80        String proj = Main.proj.toCode();
     81        if(Main.proj instanceof Mercator) // don't use mercator code directly
     82        {
     83            LatLon sw = Main.proj.eastNorth2latlon(new EastNorth(s, w));
     84            LatLon ne = Main.proj.eastNorth2latlon(new EastNorth(n, e));
     85            proj = "EPSG:4326";
     86            s = sw.lat();
     87            w = sw.lon();
     88            n = ne.lat();
     89            e = ne.lon();
     90        }
     91/*        else if(!(Main.proj instanceof Epsg4326))
     92        {
     93            EastNorth sw = Main.proj.latlon2eastNorth(new LatLon(s, w));
     94            EastNorth ne = Main.proj.latlon2eastNorth(new LatLon(n, e));
     95            s = sw.north();
     96            w = sw.east();
     97            n = ne.north();
     98            e = ne.east();
     99        }
     100*/
    75101        String str = baseURL;
    76102        String bbox = latLonFormat.format(w) + ","
     
    80106
    81107        if (urlWithPatterns) {
    82             String proj = Main.proj.toCode();
    83             if(Main.proj instanceof org.openstreetmap.josm.data.projection.Mercator) // don't use mercator code directly
    84                 proj = "EPSG:4326";
    85 
    86108            str = MessageFormat.format(str, proj, bbox, wi, ht);
    87109        } else {
     
    99121    {
    100122        String projname = Main.proj.toCode();
    101         if(Main.proj instanceof org.openstreetmap.josm.data.projection.Mercator) // don't use mercator code
     123        if(Main.proj instanceof Mercator) // don't use mercator code
    102124            projname = "EPSG:4326";
    103125        String res = "";
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r15858 r16290  
    2626import org.openstreetmap.josm.Main;
    2727import org.openstreetmap.josm.actions.DiskAccessAction;
    28 import org.openstreetmap.josm.data.Bounds;
     28import org.openstreetmap.josm.data.ProjectionBounds;
    2929import org.openstreetmap.josm.data.coor.EastNorth;
    3030import org.openstreetmap.josm.data.coor.LatLon;
     
    7979        WMSGrabber.getProjection(baseURL, true);
    8080        mv = Main.map.mapView;
    81         getPPD();
     81        pixelPerDegree = getPPD();
    8282
    8383        executor = Executors.newFixedThreadPool(3);
     
    9292    }
    9393
    94     public void getPPD(){
    95         pixelPerDegree = mv.getWidth() / (bounds().max.lon() - bounds().min.lon());
     94    public double getPPD(){
     95        ProjectionBounds bounds = mv.getProjectionBounds();
     96        return mv.getWidth() / (bounds.max.east() - bounds.min.east());
    9697    }
    9798
     
    128129    }
    129130
    130     private Bounds XYtoBounds (int x, int y) {
    131         return new Bounds(
    132             new LatLon(      x * ImageSize / pixelPerDegree,       y * ImageSize / pixelPerDegree),
    133             new LatLon((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree));
     131    private ProjectionBounds XYtoBounds (int x, int y) {
     132        return new ProjectionBounds(
     133            new EastNorth(      x * ImageSize / pixelPerDegree,       y * ImageSize / pixelPerDegree),
     134            new EastNorth((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree));
    134135    }
    135136
     
    138139    }
    139140
    140     protected Bounds bounds(){
    141         return new Bounds(
    142             mv.getLatLon(0, mv.getHeight()),
    143             mv.getLatLon(mv.getWidth(), 0));
    144     }
    145 
    146141    @Override public void paint(Graphics g, final MapView mv) {
    147142        if(baseURL == null) return;
    148143
    149         if( !startstop.isSelected() || (pixelPerDegree / (mv.getWidth() / (bounds().max.lon() - bounds().min.lon())) > minZoom) ){ //don't download when it's too outzoomed
     144        if( !startstop.isSelected() || (pixelPerDegree / getPPD() > minZoom) ){ //don't download when it's too outzoomed
    150145            for(int x = 0; x<dax; ++x)
    151146                for(int y = 0; y<day; ++y)
     
    161156
    162157    protected void downloadAndPaintVisible(Graphics g, final MapView mv){
    163         int bminx= (int)Math.floor ((bounds().min.lat() * pixelPerDegree ) / ImageSize );
    164         int bminy= (int)Math.floor ((bounds().min.lon() * pixelPerDegree ) / ImageSize );
    165         int bmaxx= (int)Math.ceil  ((bounds().max.lat() * pixelPerDegree ) / ImageSize );
    166         int bmaxy= (int)Math.ceil  ((bounds().max.lon() * pixelPerDegree ) / ImageSize );
     158        ProjectionBounds bounds = mv.getProjectionBounds();
     159        int bminx= (int)Math.floor ((bounds.min.east() * pixelPerDegree ) / ImageSize );
     160        int bminy= (int)Math.floor ((bounds.min.north() * pixelPerDegree ) / ImageSize );
     161        int bmaxx= (int)Math.ceil  ((bounds.max.east() * pixelPerDegree ) / ImageSize );
     162        int bmaxy= (int)Math.ceil  ((bounds.max.north() * pixelPerDegree ) / ImageSize );
    167163
    168164        if((bmaxx - bminx > dax) || (bmaxy - bminy > day)){
     
    241237            initializeImages();
    242238            resolution = scale();
    243             getPPD();
     239            pixelPerDegree = getPPD();
    244240            mv.repaint();
    245241        }
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r15858 r16290  
    2525import org.openstreetmap.josm.Main;
    2626import org.openstreetmap.josm.actions.JosmAction;
    27 import org.openstreetmap.josm.data.Bounds;
     27import org.openstreetmap.josm.data.ProjectionBounds;
    2828import org.openstreetmap.josm.gui.IconToggleButton;
    2929import org.openstreetmap.josm.gui.MainMenu;
     
    4343    static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
    4444    static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
    45 
    46     static boolean doOverlap = false;
    47     static int overlapLat = 4;
    48     static int overlapLon = 14;
    4945
    5046    // remember state of menu item to restore on changed preferences
     
    8985
    9086        TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
    91 
    92         // Here we load the settings for "overlap" checkbox and spinboxes.
    93 
    94         try {
    95             doOverlap = Boolean.valueOf(prefs.get("wmsplugin.url.overlap"));
    96         } catch (Exception e) {} // If sth fails, we drop to default settings.
    97 
    98         try {
    99             overlapLat = Integer.valueOf(prefs.get("wmsplugin.url.overlapLat"));
    100         } catch (Exception e) {} // If sth fails, we drop to default settings.
    101 
    102         try {
    103             overlapLon = Integer.valueOf(prefs.get("wmsplugin.url.overlapLon"));
    104         } catch (Exception e) {} // If sth fails, we drop to default settings.
    10587
    10688        // And then the names+urls of WMS servers
     
    207189    }
    208190
    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){
     191    public static Grabber getGrabber(ProjectionBounds bounds, GeorefImage img, MapView mv, WMSLayer layer){
    212192        if(layer.baseURL.startsWith("yahoo://"))
    213193            return new YAHOOGrabber(bounds, img, mv, layer, cache);
    214194        else
    215195            return new WMSGrabber(bounds, img, mv, layer, cache);
    216 
    217         // OSBGrabber should be rewrite for thread support first
    218         //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") )
    219         //  return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
    220196    }
    221197
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r15940 r16290  
    3333    private DefaultTableModel model;
    3434    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
    35 
    36     JCheckBox overlapCheckBox;
    37     JSpinner spinLat;
    38     JSpinner spinLon;
    3935
    4036    public void addGui(final PreferenceDialog gui) {
     
    117113        p.add(buttonPanel);
    118114        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
    119 
    120         overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );
    121         JLabel labelLat = new JLabel(tr("% of lat:"));
    122         JLabel labelLon = new JLabel(tr("% of lon:"));
    123         spinLat = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLat, 1, 50, 1));
    124         spinLon = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLon, 1, 50, 1));
    125 
    126         JPanel overlapPanel = new JPanel(new FlowLayout());
    127         overlapPanel.add(overlapCheckBox);
    128         overlapPanel.add(labelLat);
    129         overlapPanel.add(spinLat);
    130         overlapPanel.add(labelLon);
    131         overlapPanel.add(spinLon);
    132 
    133         p.add(overlapPanel);
    134115    }
    135116
     
    170151
    171152        if (change) WMSPlugin.refreshMenu();
    172 
    173         WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
    174         WMSPlugin.overlapLat = (Integer) spinLat.getModel().getValue();
    175         WMSPlugin.overlapLon = (Integer) spinLon.getModel().getValue();
    176 
    177         Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
    178         Main.pref.put("wmsplugin.url.overlapLat", String.valueOf(WMSPlugin.overlapLat));
    179         Main.pref.put("wmsplugin.url.overlapLon", String.valueOf(WMSPlugin.overlapLon));
    180153
    181154        return false;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java

    r15890 r16290  
    1010import javax.imageio.ImageIO;
    1111
    12 import org.openstreetmap.josm.data.Bounds;
     12import org.openstreetmap.josm.data.ProjectionBounds;
    1313import org.openstreetmap.josm.gui.MapView;
    1414import org.openstreetmap.josm.io.CacheFiles;
     
    1818    protected String browserCmd;
    1919
    20     YAHOOGrabber(Bounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
     20    YAHOOGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
    2121        super(b, image, mv, layer, cache);
    2222        this.baseURL = "file:///" + WMSPlugin.getPrefsPath() + "ymap.html?";
Note: See TracChangeset for help on using the changeset viewer.