Ignore:
Timestamp:
2010-08-26T19:47:34+02:00 (14 years ago)
Author:
jttt
Message:

Fix #5378 Ghost images appear when wmsplugin.url.overlap=true

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

Legend:

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

    r22779 r22794  
    9999
    100100        private BufferedImage createImage() {
    101                 int left = layer.getImageX(xIndex);
    102                 int bottom = layer.getImageY(yIndex);
    103                 int width = layer.getImageX(xIndex + 1) - left;
    104                 int height = layer.getImageY(yIndex + 1) - bottom;
    105 
    106                 return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     101                return new BufferedImage(layer.getImageWidth(xIndex), layer.getImageHeight(yIndex), BufferedImage.TYPE_INT_RGB);
    107102        }
    108103
     
    117112                int left = layer.getImageX(xIndex);
    118113                int bottom = layer.getImageY(yIndex);
    119                 int width = layer.getImageX(xIndex + 1) - left;
    120                 int height = layer.getImageY(yIndex + 1) - bottom;
     114                int width = layer.getImageWidth(xIndex);
     115                int height = layer.getImageHeight(yIndex);
    121116
    122117                int x = left - leftEdge;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java

    r22720 r22794  
    1818        protected Projection proj;
    1919        protected double pixelPerDegree;
     20        protected WMSRequest request;
    2021        protected volatile boolean canceled;
    2122
     
    3031                                layer.getEastNorth(request.getXIndex(), request.getYIndex()),
    3132                                layer.getEastNorth(request.getXIndex() + 1, request.getYIndex() + 1));
    32                 if (b.min != null && b.max != null && WMSPlugin.doOverlap) {
     33                if (b.min != null && b.max != null && WMSPlugin.PROP_OVERLAP.get()) {
    3334                        double eastSize =  b.max.east() - b.min.east();
    3435                        double northSize =  b.max.north() - b.min.north();
    3536
    36                         double eastCoef = WMSPlugin.overlapEast / 100.0;
    37                         double northCoef = WMSPlugin.overlapNorth / 100.0;
     37                        double eastCoef = WMSPlugin.PROP_OVERLAP_EAST.get() / 100.0;
     38                        double northCoef = WMSPlugin.PROP_OVERLAP_NORTH.get() / 100.0;
    3839
    3940                        this.b = new ProjectionBounds( new EastNorth(b.min.east(),
     
    4546                this.proj = Main.proj;
    4647                this.pixelPerDegree = request.getPixelPerDegree();
     48                this.request = request;
    4749        }
    4850
     
    5052
    5153        int width(){
    52                 return (int) ((b.max.north() - b.min.north()) * pixelPerDegree);
     54                return layer.getImageWidth(request.getXIndex());
    5355        }
    5456        int height(){
    55                 return (int) ((b.max.east() - b.min.east()) * pixelPerDegree);
     57                return layer.getImageHeight(request.getYIndex());
    5658        }
    5759
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r22779 r22794  
    5353 */
    5454public class WMSLayer extends Layer implements PreferenceChangedListener {
     55
    5556        protected static final Icon icon =
    5657                new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
     
    6768        protected int minZoom = 3;
    6869
    69         protected boolean deltaChanged;
    7070        protected double dx = 0.0;
    7171        protected double dy = 0.0;
     
    7777        protected final int serializeFormatVersion = 5;
    7878        protected boolean autoDownloadEnabled = true;
     79        protected boolean settingsChanged;
    7980
    8081        // Image index boundary for current view
     
    8687        private volatile int bottomEdge;
    8788
    88 
     89        // Request queue
    8990        private final List<WMSRequest> requestQueue = new ArrayList<WMSRequest>();
    9091        private final List<WMSRequest> finishedRequests = new ArrayList<WMSRequest>();
     
    202203
    203204        @Override public void paint(Graphics2D g, final MapView mv, Bounds b) {
    204                 deltaChanged = false;
    205205                if(baseURL == null) return;
    206206                if (usesInvalidUrl && !isInvalidUrlConfirmed) return;
     207
     208                settingsChanged = false;
    207209
    208210                ProjectionBounds bounds = mv.getProjectionBounds();
     
    261263
    262264        public void displace(double dx, double dy) {
    263                 deltaChanged = true;
     265                settingsChanged = true;
    264266                this.dx += dx;
    265267                this.dy += dy;
     
    280282        public int getImageY(int imageIndex) {
    281283                return (int)(imageIndex * imageSize * (getPPD() / pixelPerDegree) + dy * getPPD());
     284        }
     285
     286        public int getImageWidth(int xIndex) {
     287                int overlap = (int)(WMSPlugin.PROP_OVERLAP.get()?WMSPlugin.PROP_OVERLAP_EAST.get() * imageSize * getPPD() / pixelPerDegree / 100:0);
     288                return getImageX(xIndex + 1) - getImageX(xIndex) + overlap;
     289        }
     290
     291        public int getImageHeight(int yIndex) {
     292                int overlap = (int)(WMSPlugin.PROP_OVERLAP.get()?WMSPlugin.PROP_OVERLAP_NORTH.get() * imageSize * getPPD() / pixelPerDegree / 100:0);
     293                return getImageY(yIndex + 1) - getImageY(yIndex) + overlap;
    282294        }
    283295
     
    514526                        resolution = mv.getDist100PixelText();
    515527                        pixelPerDegree = getPPD();
     528                        settingsChanged = true;
    516529                        mv.repaint();
    517530                }
     
    627640                                ois.close();
    628641                                fis.close();
     642                                settingsChanged = true;
    629643                                mv.repaint();
    630644                        }
     
    743757                requestQueueLock.lock();
    744758                try {
    745                         return !finishedRequests.isEmpty() || deltaChanged;
     759                        return !finishedRequests.isEmpty() || settingsChanged;
    746760                } finally {
    747761                        requestQueueLock.unlock();
     
    753767                        cancelGrabberThreads(true);
    754768                        startGrabberThreads();
    755                 }
    756         }
     769                } else if (
     770                                event.getKey().equals(WMSPlugin.PROP_OVERLAP.getKey())
     771                                || event.getKey().equals(WMSPlugin.PROP_OVERLAP_EAST.getKey())
     772                                || event.getKey().equals(WMSPlugin.PROP_OVERLAP_NORTH.getKey())) {
     773                        for (int i=0; i<images.length; i++) {
     774                                for (int k=0; k<images[i].length; k++) {
     775                                        images[i][k] = new GeorefImage(this);
     776                                }
     777                        }
     778
     779                        settingsChanged = true;
     780                }
     781        }
     782
    757783}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r22735 r22794  
    3030import org.openstreetmap.josm.actions.ExtensionFileFilter;
    3131import org.openstreetmap.josm.actions.JosmAction;
     32import org.openstreetmap.josm.data.preferences.BooleanProperty;
    3233import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3334import org.openstreetmap.josm.gui.IconToggleButton;
     
    5051
    5152        public static final IntegerProperty PROP_SIMULTANEOUS_CONNECTIONS = new IntegerProperty("wmsplugin.simultaneousConnections", 3);
     53        public static final BooleanProperty PROP_OVERLAP = new BooleanProperty("wmsplugin.url.overlap", false);
     54        public static final IntegerProperty PROP_OVERLAP_EAST = new IntegerProperty("wmsplugin.url.overlapEast", 14);
     55        public static final IntegerProperty PROP_OVERLAP_NORTH = new IntegerProperty("wmsplugin.url.overlapNorth", 4);
    5256
    5357        WMSLayer wmsLayer;
     
    5761        static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
    5862
    59         static boolean doOverlap = false;
    60         static int overlapEast = 14;
    61         static int overlapNorth = 4;
    6263        // remember state of menu item to restore on changed preferences
    6364        static private boolean menuEnabled = false;
     
    255256                TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
    256257
    257                 // Here we load the settings for "overlap" checkbox and spinboxes.
    258 
    259                 try {
    260                         doOverlap = Boolean.valueOf(prefs.get("wmsplugin.url.overlap"));
    261                 } catch (Exception e) {} // If sth fails, we drop to default settings.
    262 
    263                 try {
    264                         overlapEast = Integer.valueOf(prefs.get("wmsplugin.url.overlapEast"));
    265                 } catch (Exception e) {} // If sth fails, we drop to default settings.
    266 
    267                 try {
    268                         overlapNorth = Integer.valueOf(prefs.get("wmsplugin.url.overlapNorth"));
    269                 } catch (Exception e) {} // If sth fails, we drop to default settings.
    270 
    271258                // And then the names+urls of WMS servers
    272259                int prefid = 0;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r22712 r22794  
    169169                p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    170170
    171                 overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );
     171                overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.PROP_OVERLAP.get() );
    172172                JLabel labelEast = new JLabel(tr("% of east:"));
    173173                JLabel labelNorth = new JLabel(tr("% of north:"));
    174                 spinEast = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapEast, 1, 50, 1));
    175                 spinNorth = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapNorth, 1, 50, 1));
     174                spinEast = new JSpinner(new SpinnerNumberModel(WMSPlugin.PROP_OVERLAP_EAST.get(), 1, 50, 1));
     175                spinNorth = new JSpinner(new SpinnerNumberModel(WMSPlugin.PROP_OVERLAP_NORTH.get(), 1, 50, 1));
    176176
    177177                JPanel overlapPanel = new JPanel(new FlowLayout());
     
    240240                if (change) WMSPlugin.refreshMenu();
    241241
    242                 WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
    243                 WMSPlugin.overlapEast = (Integer) spinEast.getModel().getValue();
    244                 WMSPlugin.overlapNorth = (Integer) spinNorth.getModel().getValue();
     242                WMSPlugin.PROP_OVERLAP.put(overlapCheckBox.getModel().isSelected());
     243                WMSPlugin.PROP_OVERLAP_EAST.put((Integer) spinEast.getModel().getValue());
     244                WMSPlugin.PROP_OVERLAP_NORTH.put((Integer) spinNorth.getModel().getValue());
    245245                WMSPlugin.PROP_SIMULTANEOUS_CONNECTIONS.put((Integer) spinSimConn.getModel().getValue());
    246246                allowRemoteControl = remoteCheckBox.getModel().isSelected();
    247 
    248                 Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
    249                 Main.pref.put("wmsplugin.url.overlapEast", String.valueOf(WMSPlugin.overlapEast));
    250                 Main.pref.put("wmsplugin.url.overlapNorth", String.valueOf(WMSPlugin.overlapNorth));
    251247
    252248                Main.pref.put("wmsplugin.browser", browser.getEditor().getItem().toString());
Note: See TracChangeset for help on using the changeset viewer.