Ticket #2589: patch-wms-adding-overlap.diff

File patch-wms-adding-overlap.diff, 8.9 KB (added by Radomír Černoch <radomir.cernoch@…>, 16 years ago)

Patch for WMSPlugin

  • src/wmsplugin/WMSLayer.java

     
    8383        executor = Executors.newFixedThreadPool(3);
    8484    }
    8585   
     86    @Override
    8687    public void destroy() {
    8788        try {
    8889            executor.shutdown(); 
     
    175176        for(int x = bminx; x<bmaxx; ++x)
    176177            for(int y = bminy; y<bmaxy; ++y){
    177178                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
     179                g.drawRect(x, y, dax, bminy);
    178180                if(!img.paint(g, mv, dx, dy) && !img.downloadingStarted){
    179181                    img.downloadingStarted = true;
    180182                    img.image = null;
  • src/wmsplugin/Grabber.java

     
    1111import java.awt.Color;
    1212import java.awt.Font;
    1313import javax.swing.JOptionPane;
     14import org.openstreetmap.josm.data.coor.LatLon;
    1415
    1516abstract public class Grabber implements Runnable {
    1617    protected Bounds b;
     
    2223
    2324    Grabber(Bounds b, Projection proj,
    2425            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    25         this.b = b;
     26
     27
     28        if (b.min != null && b.max != null && WMSPlugin.doOverlap) {
     29            double latCent = (b.min.lat() + b.max.lat()) / 2;
     30            double lonCent = (b.min.lon() + b.max.lon()) / 2;
     31           
     32            double latSize =  b.max.lat() - b.min.lat();
     33            double lonSize =  b.max.lon() - b.min.lon();
     34
     35            double latCoef = (100.0 + WMSPlugin.overlapLat) / 100.0 / 2.0;
     36            double lonCoef = (100.0 + WMSPlugin.overlapLon) / 100.0 / 2.0;
     37           
     38            this.b = new Bounds( new LatLon(latCent - latCoef * latSize,
     39                                            lonCent - lonCoef * lonSize),
     40                                 new LatLon(latCent + latCoef * latSize,
     41                                            lonCent + lonCoef * lonSize));           
     42        } else
     43            this.b = b;
     44           
    2645        this.proj = proj;
    2746        this.pixelPerDegree = pixelPerDegree;
    2847        this.image = image;
  • src/wmsplugin/WMSPlugin.java

     
    3737    static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
    3838    static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
    3939
     40    static boolean doOverlap = false;
     41    static int overlapLat = 4;
     42    static int overlapLon = 14;
     43   
    4044    // remember state of menu item to restore on changed preferences
    4145    static private boolean menuEnabled = false;
    4246
     
    7680        Map<String,String> prefs = Main.pref.getAllPrefix("wmsplugin.url.");
    7781
    7882        TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
     83       
     84        // Here we load the settings for "overlap" checkbox and spinboxes.
     85       
     86        try {
     87            doOverlap = Boolean.valueOf(prefs.get("wmsplugin.url.overlap"));           
     88        } catch (Exception e) {} // If sth fails, we drop to default settings.
     89
     90        try {
     91            overlapLat = Integer.valueOf(prefs.get("wmsplugin.url.overlapLat"));           
     92        } catch (Exception e) {} // If sth fails, we drop to default settings.
     93
     94        try {
     95            overlapLon = Integer.valueOf(prefs.get("wmsplugin.url.overlapLon"));           
     96        } catch (Exception e) {} // If sth fails, we drop to default settings.
     97       
     98        // And then the names+urls of WMS servers       
    7999        int prefid = 0;
    80100        String name = null;
    81101        String url = null;
  • src/wmsplugin/GeorefImage.java

     
    11package wmsplugin;
    22
     3import java.awt.Color;
    34import java.awt.Dimension;
    45import java.awt.Graphics;
    56import java.awt.Image;
     
    7980        // but the performance improvements when moving are huge
    8081        // Zooming is still slow because the images need to be resized
    8182        if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) {
     83            /*g.setColor(Color.RED);
     84              g.drawRect(minPt.x, minPt.y-height, width, height);*/
    8285            g.drawImage(reImg, minPt.x, maxPt.y, null);
    8386            return true;
    8487        }
     
    119122                reImg.getGraphics().dispose();
    120123
    121124                reImgHash.setSize(width, height);
     125                /*g.setColor(Color.RED);
     126                  g.drawRect(minPt.x, minPt.y-height, width, height);*/
    122127                g.drawImage(reImg, minPt.x, maxPt.y, null);
    123128            }
    124129        } catch(Exception e) {
  • src/wmsplugin/WMSPreferenceEditor.java

     
    11package wmsplugin;
    22
     3import java.awt.BorderLayout;
     4import java.awt.FlowLayout;
     5import javax.swing.JCheckBox;
     6import javax.swing.JSpinner;
     7import javax.swing.SpinnerNumberModel;
     8import org.openstreetmap.josm.Main;
    39import static org.openstreetmap.josm.tools.I18n.tr;
    410
    511import java.awt.Dimension;
     
    3137    private DefaultTableModel model;
    3238    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
    3339
     40    JCheckBox overlapCheckBox;
     41    JSpinner spinLat;
     42    JSpinner spinLon;
     43   
    3444    public void addGui(final PreferenceDialog gui) {
    3545        JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu"));
    36 
     46       
    3747        model = new DefaultTableModel(new String[]{tr("Menu Name"), tr("WMS URL")}, 0);
    3848        final JTable list = new JTable(model);
    3949        JScrollPane scroll = new JScrollPane(list);
     
    5868            modeldef.addRow(new String[]{i.getKey(), i.getValue()});
    5969        }
    6070
     71        JPanel buttonPanel = new JPanel(new FlowLayout());
     72       
    6173        JButton add = new JButton(tr("Add"));
    62         p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    63         p.add(add, GBC.std().insets(0,5,0,0));
     74        buttonPanel.add(add, GBC.std().insets(0,5,0,0));
    6475        add.addActionListener(new ActionListener(){
    6576            public void actionPerformed(ActionEvent e) {
    6677                JPanel p = new JPanel(new GridBagLayout());
     
    7889        });
    7990
    8091        JButton delete = new JButton(tr("Delete"));
    81         p.add(delete, GBC.std().insets(0,5,0,0));
     92        buttonPanel.add(delete, GBC.std().insets(0,5,0,0));
    8293        delete.addActionListener(new ActionListener(){
    8394            public void actionPerformed(ActionEvent e) {
    8495                if (list.getSelectedRow() == -1)
     
    93104        });
    94105
    95106        JButton copy = new JButton(tr("Copy Default"));
    96         p.add(copy, GBC.std().insets(0,5,0,0));
     107        buttonPanel.add(copy, GBC.std().insets(0,5,0,0));
    97108        copy.addActionListener(new ActionListener(){
    98109            public void actionPerformed(ActionEvent e) {
    99110                Integer line = listdef.getSelectedRow();
     
    106117                }
    107118            }
    108119        });
     120
     121        p.add(buttonPanel);       
     122        p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
     123       
     124        overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );
     125        JLabel labelLat = new JLabel(tr("% of lat:"));
     126        JLabel labelLon = new JLabel(tr("% of lon:"));
     127        spinLat = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLat, 1, 50, 1));
     128        spinLon = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLon, 1, 50, 1));
     129       
     130        JPanel overlapPanel = new JPanel(new FlowLayout());
     131        overlapPanel.add(overlapCheckBox);
     132        overlapPanel.add(labelLat);
     133        overlapPanel.add(spinLat);
     134        overlapPanel.add(labelLon);
     135        overlapPanel.add(spinLon);
     136       
     137        p.add(overlapPanel);
    109138    }
    110139
    111140    public boolean ok() {
     
    144173        }
    145174
    146175        if (change) WMSPlugin.refreshMenu();
     176       
     177        WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
     178        WMSPlugin.overlapLat = (Integer) spinLat.getModel().getValue();
     179        WMSPlugin.overlapLon = (Integer) spinLon.getModel().getValue();
     180       
     181        Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
     182        Main.pref.put("wmsplugin.url.overlapLat", String.valueOf(WMSPlugin.overlapLat));
     183        Main.pref.put("wmsplugin.url.overlapLon", String.valueOf(WMSPlugin.overlapLon));
     184       
    147185        return false;
    148186    }
    149187