Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 13545)
@@ -117,6 +117,5 @@
         } catch (Exception ex) {
             ex.printStackTrace(System.out);
-            JOptionPane
-                    .showMessageDialog(Main.parent, tr("Error loading file"), tr("Error"), JOptionPane.ERROR_MESSAGE);
+            JOptionPane.showMessageDialog(Main.parent, tr("Error loading file"), tr("Error"), JOptionPane.ERROR_MESSAGE);
             return false;
         }
@@ -125,19 +124,4 @@
 
 
-    public boolean existCache() {
-        try {
-            /*
-            File pathname = new File(CadastrePlugin.cacheDir);
-            String[] fileNames = pathname.list();
-            for (String fileName : fileNames) {
-                System.out.println("check file:"+fileName);
-                //WMSLayer cached = new WMSLayer(new File(cacheDir+fileName));
-            }*/
-        } catch (Exception e) {
-            e.printStackTrace(System.out);
-        }
-        return false;
-    }
-    
     public synchronized void saveCache(GeorefImage image) {
         imagesLock.lock();
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 13545)
@@ -64,5 +64,6 @@
  *                 - minor fixes due to changes in JOSM core classes
  *                 - first draft of raster image support 
- * 0.9 draft       - grab vectorized full commune bbox and save it in cache
+ * 0.9 05-Feb-2009 - grab vectorized full commune bbox, save in file, convert to OSM way
+ *                   and simplify
  */
 public class CadastrePlugin extends Plugin {
@@ -151,4 +152,5 @@
             JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone());
             JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache());
+            JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());
             
             cadastreJMenu.add(menuGrab);
@@ -158,4 +160,5 @@
             cadastreJMenu.add(menuLambertZone);
             cadastreJMenu.add(menuLoadFromCache);
+            cadastreJMenu.add(menuActionBoundaries);
         }
         setEnabledAll(menuEnabled);
@@ -187,8 +190,10 @@
             JMenuItem item = cadastreJMenu.getItem(i);
             if (item != null)
-                if (item.getText().equals(MenuActionGrab.name))
+                if (item.getText().equals(MenuActionGrab.name) ||
+                    item.getText().equals(MenuActionBoundaries.name)) {
                     item.setEnabled(isEnabled);
-                else if (item.getText().equals(MenuActionLambertZone.name))
+                } else if (item.getText().equals(MenuActionLambertZone.name)) {
                     item.setEnabled(!isEnabled);
+                }
         }
         menuEnabled = isEnabled;
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CheckSourceUploadHook.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CheckSourceUploadHook.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CheckSourceUploadHook.java	(revision 13545)
@@ -46,5 +46,5 @@
             }
             if (!sel.isEmpty()) {
-                return displaySource(sel);
+                displaySource(sel);
             }
         }
@@ -70,9 +70,7 @@
      * source="cadastre.." if it is approved.
      * @param sel the list of elements added without a key "source"
-     * @return true if it is accepted by user 
      */
-    private boolean displaySource(Collection<OsmPrimitive> sel) 
+    private void displaySource(Collection<OsmPrimitive> sel) 
     {
-        boolean bContinue = true;
         if (!sel.isEmpty()) {
             JPanel p = new JPanel(new GridBagLayout());
@@ -83,10 +81,9 @@
             l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10);
             p.add(new JScrollPane(l), GBC.eol().fill());
-            bContinue = JOptionPane.showConfirmDialog(Main.parent, p, tr("Add \"source=...\" to elements?"),
+            boolean bContinue = JOptionPane.showConfirmDialog(Main.parent, p, tr("Add \"source=Cadastre...\" to ?"),
                     JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
             if (bContinue)
                 Main.main.undoRedo.add(new ChangePropertyCommand(sel, "source", CadastrePlugin.source));
         }
-        return bContinue;
                 
     }    
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 13545)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 13545)
@@ -0,0 +1,211 @@
+package cadastre_fr;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.command.AddCommand;
+import org.openstreetmap.josm.command.Command;
+import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.io.ProgressInputStream;
+/**
+ * Grab the SVG administrative boundaries of the active commune layer (cadastre), 
+ * isolate the SVG path of the concerned commune (other municipalities are also
+ * downloaded in the SVG data), convert to OSM nodes and way plus simplify.
+ * Thanks to Frederic Rodrigo for his help.
+ */
+public class DownloadSVGTask extends PleaseWaitRunnable {
+
+    private WMSLayer wmsLayer;
+    private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
+    private CadastreInterface wmsInterface;
+    private String svg = null;
+    private EastNorthBound viewBox = null;
+    
+    public DownloadSVGTask(WMSLayer wmsLayer) {
+        super(tr("Downloading {0}", wmsLayer.name));
+
+        this.wmsLayer = wmsLayer;
+        this.wmsInterface = grabber.getWmsInterface();
+    }
+
+    @Override
+    public void realRun() throws IOException {
+        Main.pleaseWaitDlg.currentAction.setText(tr("Contacting WMS Server..."));
+        try {
+            if (wmsInterface.retrieveInterface(wmsLayer)) {
+                svg = grabBoundary(wmsLayer.getCommuneBBox());
+                if (svg == null)
+                    return;
+                Main.pleaseWaitDlg.currentAction.setText(tr("Extract SVG ViewBox..."));
+                getViewBox(svg);
+                if (viewBox == null)
+                    return;
+                Main.pleaseWaitDlg.currentAction.setText(tr("Extract best fitting boundary..."));
+                createWay(svg);
+            }
+        } catch (DuplicateLayerException e) {
+            System.err.println("removed a duplicated layer");
+        }
+    }
+
+    @Override
+    protected void cancel() {
+        grabber.getWmsInterface().cancel();
+    }
+
+    @Override
+    protected void finish() {
+    }
+
+    private boolean getViewBox(String svg) {
+        double[] box = new SVGParser().getViewBox(svg);
+        if (box != null) {
+            viewBox = new EastNorthBound(new EastNorth(box[0], box[1]), 
+                    new EastNorth(box[0]+box[2], box[1]+box[3]));
+            return true;
+        }
+        System.out.println("Unable to parse SVG data (viewBox)");
+        return false;
+    }
+    
+    /**
+     *  The svg contains more than one commune boundary defined by path elements. So detect
+     *  which path element is the best fitting to the viewBox and convert it to OSM objects
+     */
+    private void createWay(String svg) {
+        String[] SVGpaths = new SVGParser().getPaths(svg);
+        //double[] fitViewBox = new double[SVGpaths.length];
+        ArrayList<Double> fitViewBox = new ArrayList<Double>();  
+        ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>();
+        for (int i=0; i< SVGpaths.length; i++) {
+            ArrayList<EastNorth> eastNorth = new ArrayList<EastNorth>();
+            fitViewBox.add( createNodes(SVGpaths[i], eastNorth) );;
+            eastNorths.add(eastNorth);
+        }
+        // the smallest fitViewBox indicates the best fitting path in viewBox
+        Double min = Collections.min(fitViewBox);
+        int bestPath = fitViewBox.indexOf(min);
+        List<Node> nodeList = new ArrayList<Node>();
+        for (EastNorth eastNorth : eastNorths.get(bestPath)) {
+            nodeList.add(new Node(Main.proj.eastNorth2latlon(eastNorth)));
+        }
+        Way wayToAdd = new Way();
+        Collection<Command> cmds = new LinkedList<Command>();
+        for (Node node : nodeList) {
+            cmds.add(new AddCommand(node));
+            wayToAdd.nodes.add(node);
+        }
+        wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle
+        new SimplifyWay().simplifyWay(wayToAdd);
+        cmds.add(new AddCommand(wayToAdd));
+        Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), cmds));
+        Main.map.repaint();
+    }
+    
+    private double createNodes(String SVGpath, ArrayList<EastNorth> eastNorth) {
+        // looks like "M981283.38 368690.15l143.81 72.46 155.86 ..."
+        String[] coor = SVGpath.split("[MlZ ]"); //coor[1] is x, coor[2] is y
+        double dx = Double.parseDouble(coor[1]);
+        double dy = Double.parseDouble(coor[2]);
+        double minY = Double.MAX_VALUE;
+        double minX = Double.MAX_VALUE;
+        double maxY = Double.MIN_VALUE;
+        double maxX = Double.MIN_VALUE;
+        for (int i=3; i<coor.length; i+=2){
+            double east = dx+=Double.parseDouble(coor[i]);
+            double north = dy+=Double.parseDouble(coor[i+1]); 
+            eastNorth.add(new EastNorth(east,north));
+            minX = minX > east ? east : minX; 
+            minY = minY > north ? north : minY; 
+            maxX = maxX < east ? east : maxX; 
+            maxY = maxY < north ? north : maxY; 
+        }
+        // flip the image (svg using a reversed Y coordinate system)            
+        double pivot = viewBox.min.getY() + (viewBox.max.getY() - viewBox.min.getY()) / 2;
+        for (EastNorth en : eastNorth) {
+            en.setLocation(en.east(), 2 * pivot - en.north());
+        }
+        return Math.abs(minX - viewBox.min.getX())+Math.abs(maxX - viewBox.max.getX())
+        +Math.abs(minY - viewBox.min.getY())+Math.abs(maxY - viewBox.max.getY());
+    }
+    
+    private String grabBoundary(EastNorthBound bbox) throws IOException {
+
+        try {
+            URL url = null;
+            url = getURLsvg(bbox);
+            System.out.println("grab:"+url);
+            return grabSVG(url);
+        } catch (MalformedURLException e) {
+            throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
+        }
+    }
+    
+    private URL getURLsvg(EastNorthBound bbox) throws MalformedURLException {
+        String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
+        str += "&layers=";
+        str += "CDIF:COMMUNE";
+        str += "&format=image/svg";
+        str += "&bbox="+bbox.min.east()+",";
+        str += bbox.min.north() + ",";
+        str += bbox.max.east() + ",";
+        str += bbox.max.north();
+        str += "&width=800&height=600"; // maximum allowed by wms server
+        str += "&styles=";
+        str += "COMMUNE_90";
+        System.out.println("URL="+str);
+        return new URL(str.replace(" ", "%20"));
+    }
+
+    private String grabSVG(URL url) throws IOException {
+        wmsInterface.urlConn = (HttpURLConnection)url.openConnection();
+        wmsInterface.urlConn.setRequestMethod("GET");
+        wmsInterface.setCookie();
+        InputStream is = new ProgressInputStream(wmsInterface.urlConn, Main.pleaseWaitDlg);
+        File file = new File(CadastrePlugin.cacheDir + "boundary.svg");
+        String svg = new String();
+        try {
+            if (file.exists())
+                file.delete();
+            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
+            InputStreamReader isr =new InputStreamReader(is);
+            BufferedReader br = new BufferedReader(isr);
+            String line="";
+            while ( null!=(line=br.readLine())){
+                line += "\n";
+                bos.write(line.getBytes());
+                svg += line;
+            }
+            bos.close();
+        } catch (IOException e) {
+            e.printStackTrace(System.out);
+        }
+        is.close();
+        return svg;
+    }
+
+    public static void download(WMSLayer wmsLayer) {
+        Main.worker.execute(new DownloadSVGTask(wmsLayer));
+    }
+
+}
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSTask.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSTask.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSTask.java	(revision 13545)
@@ -60,5 +60,4 @@
     @Override
     protected void finish() {
-        //wmsLayer.saveToCache();
     }
 
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/EastNorthBound.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/EastNorthBound.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/EastNorthBound.java	(revision 13545)
@@ -14,4 +14,13 @@
         this.max = max;
     }
+
+    public boolean contains(EastNorth eastNorth) {
+        if (eastNorth.east() < min.east() || eastNorth.north() < min.north())
+            return false;
+        if (eastNorth.east() > max.east() || eastNorth.north() > max.north())
+            return false;
+        return true;
+    }
+
     @Override public String toString() {
         return "EastNorthBound[" + min.east() + "," + min.north() + "," + max.east() + "," + max.north() + "]";
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java	(revision 13545)
@@ -28,4 +28,6 @@
     public ImageModifier(BufferedImage bi) {
         bufferedImage = bi;
+        System.out.println("cadastrewms.alterColors="+Main.pref.getBoolean("cadastrewms.alterColors"));
+        System.out.println("cadastrewms.backgroundTransparent="+Main.pref.getBoolean("cadastrewms.backgroundTransparent"));
         if (Main.pref.getBoolean("cadastrewms.alterColors")) {
             changeColors();
@@ -47,4 +49,6 @@
         int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#FFFFFF")).getRGB();
         boolean invertGrey = (Main.pref.getBoolean("cadastrewms.invertGrey"));
+        System.out.println("cadastrewms.invertGrey="+invertGrey);
+        System.out.println("color.background="+Main.pref.get("color.background", "#FFFFFF"));
         for (int x = 0; x < w; x++) {
             for (int y = 0; y < h; y++) {
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionBoundaries.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionBoundaries.java	(revision 13545)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionBoundaries.java	(revision 13545)
@@ -0,0 +1,36 @@
+package cadastre_fr;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.JosmAction;
+
+public class MenuActionBoundaries extends JosmAction {
+    
+    public static String name = "Administrative boundary";
+
+    private static final long serialVersionUID = 1L;
+    private WMSLayer wmsLayer = null;
+   
+    public MenuActionBoundaries() {
+        super(tr(name), "cadastre_small", tr("Extract commune boundary"), null, false);
+    }
+
+    public void actionPerformed(ActionEvent arg0) {
+        wmsLayer = WMSDownloadAction.getLayer();
+        if (wmsLayer != null) {
+            if (wmsLayer.isRaster()) {
+                JOptionPane.showMessageDialog(Main.parent,
+                        tr("Only on vectorized layers"), tr("Error"),
+                        JOptionPane.ERROR_MESSAGE);
+                return;
+            }
+            DownloadSVGTask.download(wmsLayer);
+        }
+    }
+
+}
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java	(revision 13545)
@@ -48,5 +48,5 @@
             String codeCommune = "";
             boolean resetCookie = false;
-            JLabel labelSectionNewLocation = new JLabel(tr("Add new layer"));
+            JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
             JPanel p = new JPanel(new GridBagLayout());
             JLabel labelLocation = new JLabel(tr("Location"));
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java	(revision 13545)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java	(revision 13545)
@@ -0,0 +1,57 @@
+package cadastre_fr;
+
+import java.util.ArrayList;
+
+/**
+ * This class is not intended to be a real SVG parser. It's also not using existing
+ * xml parsers. It's just extracting the required strings from an SVG file coming
+ * from the French land registry cadastre.gouv.fr 
+ *
+ */
+public class SVGParser {
+
+    private String cViewBoxStart = "viewBox=\"";
+    private String cViewBoxEnd = "\"";
+    private String cPathStart = "<path d=\"";
+    private String cPathEnd = "\"/>";
+
+    /**
+     * The SVG viewBox looks like this:
+     *   viewBox="969780.0 320377.11 5466.130000000005 2846.429999999993"
+     * @param svg the SVG XML data
+     * @return double [x,y,dx,dy] of viewBox; null if parsing failed
+     */
+    public double[] getViewBox(String svg) {
+        int s = svg.indexOf(cViewBoxStart)+cViewBoxStart.length();
+        int e = svg.indexOf(cViewBoxEnd, s);
+        if (s != -1 && e != -1) {
+            try {
+                String str = svg.substring(s, e);
+                String [] viewBox = str.split(" ");
+                double[] dbox = new double[4];
+                for (int i = 0; i<4; i++)
+                    dbox[i] = Double.parseDouble(viewBox[i]); 
+                return dbox;
+            } catch (Exception ex) {
+                return null;
+            }
+        }
+        return null;
+    }
+    
+    public String [] getPaths(String svg) {
+        ArrayList<String> path = new ArrayList<String>();
+        int i = 0;
+        while (svg.indexOf(cPathStart, i) != -1) {
+            int s = svg.indexOf(cPathStart, i) + cViewBoxStart.length();
+            int e = svg.indexOf(cPathEnd, s);
+            if (s != -1 && e != -1) {
+                path.add(svg.substring(s, e));
+            } else
+                break;
+            i = e;
+        }
+        return path.toArray(new String[ path.size() ]);
+    }
+
+}
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java	(revision 13545)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java	(revision 13545)
@@ -0,0 +1,122 @@
+package cadastre_fr;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.command.ChangeCommand;
+import org.openstreetmap.josm.command.Command;
+import org.openstreetmap.josm.command.DeleteCommand;
+import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
+import static org.openstreetmap.josm.tools.I18n.trn;
+
+/**
+ * Imported from plugin UtilsPlugin
+ * @author 
+ *
+ */
+public class SimplifyWay {
+    public void simplifyWay(Way w) {
+        double threshold = Double.parseDouble(Main.pref.get("simplify-way.max-error", "3"));
+
+        Way wnew = new Way(w);
+
+        int toI = wnew.nodes.size() - 1;
+        for (int i = wnew.nodes.size() - 1; i >= 0; i--) {
+            CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(Main.ds, false);
+            backRefsV.visit(wnew.nodes.get(i));
+            boolean used = false;
+            if (backRefsV.data.size() == 1) {
+                used = Collections.frequency(w.nodes, wnew.nodes.get(i)) > 1;
+            } else {
+                backRefsV.data.remove(w);
+                used = !backRefsV.data.isEmpty();
+            }
+            if (!used)
+                used = wnew.nodes.get(i).tagged;
+
+            if (used) {
+                simplifyWayRange(wnew, i, toI, threshold);
+                toI = i;
+            }
+        }
+        simplifyWayRange(wnew, 0, toI, threshold);
+
+        HashSet<Node> delNodes = new HashSet<Node>();
+        delNodes.addAll(w.nodes);
+        delNodes.removeAll(wnew.nodes);
+
+        if (wnew.nodes.size() != w.nodes.size()) {
+            Collection<Command> cmds = new LinkedList<Command>();
+            cmds.add(new ChangeCommand(w, wnew));
+            cmds.add(new DeleteCommand(delNodes));
+            Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds));
+            Main.map.repaint();
+        }
+    }
+
+    public void simplifyWayRange(Way wnew, int from, int to, double thr) {
+        if (to - from >= 2) {
+            ArrayList<Node> ns = new ArrayList<Node>();
+            simplifyWayRange(wnew, from, to, ns, thr);
+            for (int j = to - 1; j > from; j--)
+                wnew.nodes.remove(j);
+            wnew.nodes.addAll(from + 1, ns);
+        }
+    }
+    
+    /*
+     * Takes an interval [from,to] and adds nodes from (from,to) to ns.
+     * (from and to are indices of wnew.nodes.)
+     */
+    public void simplifyWayRange(Way wnew, int from, int to, ArrayList<Node> ns, double thr) {
+        Node fromN = wnew.nodes.get(from), toN = wnew.nodes.get(to);
+
+        int imax = -1;
+        double xtemax = 0;
+        for (int i = from + 1; i < to; i++) {
+            Node n = wnew.nodes.get(i);
+            double xte = Math.abs(EARTH_RAD
+                    * xtd(fromN.coor.lat() * Math.PI / 180, fromN.coor.lon() * Math.PI / 180, toN.coor.lat() * Math.PI
+                            / 180, toN.coor.lon() * Math.PI / 180, n.coor.lat() * Math.PI / 180, n.coor.lon() * Math.PI
+                            / 180));
+            if (xte > xtemax) {
+                xtemax = xte;
+                imax = i;
+            }
+        }
+
+        if (imax != -1 && xtemax >= thr) {
+            simplifyWayRange(wnew, from, imax, ns, thr);
+            ns.add(wnew.nodes.get(imax));
+            simplifyWayRange(wnew, imax, to, ns, thr);
+        }
+    }
+    public static double EARTH_RAD = 6378137.0;
+    /* From Aviaton Formulary v1.3
+     * http://williams.best.vwh.net/avform.htm
+     */
+    public static double dist(double lat1, double lon1, double lat2, double lon2) {
+        return 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - lat2) / 2), 2) + Math.cos(lat1) * Math.cos(lat2)
+                * Math.pow(Math.sin((lon1 - lon2) / 2), 2)));
+    }
+
+    public static double course(double lat1, double lon1, double lat2, double lon2) {
+        return Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
+                * Math.cos(lat2) * Math.cos(lon1 - lon2))
+                % (2 * Math.PI);
+    }
+    public static double xtd(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3) {
+        double dist_AD = dist(lat1, lon1, lat3, lon3);
+        double crs_AD = course(lat1, lon1, lat3, lon3);
+        double crs_AB = course(lat1, lon1, lat2, lon2);
+        return Math.asin(Math.sin(dist_AD) * Math.sin(crs_AD - crs_AB));
+    }
+
+}
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java	(revision 13545)
@@ -5,4 +5,6 @@
 import java.awt.event.ActionEvent;
 import java.util.ArrayList;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -14,6 +16,4 @@
     private static final long serialVersionUID = 1L;
 
-    //private String layerName;
-	
 	public WMSDownloadAction(String layerName) {
 		super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);
@@ -38,5 +38,8 @@
             if (existingWMSlayers.size() == 1)
                 return existingWMSlayers.get(0);
-            return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
+            if (existingWMSlayers.size() == 0)
+                return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("More than one WMS layer present\nSelect one of them first, then retry"));
         }
         return null;
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 13497)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 13545)
@@ -180,5 +180,12 @@
     @Override
     public String getToolTipText() {
-        return tr("WMS layer ({0}), {1} tile(s) loaded", name, images.size());
+        String str = tr("WMS layer ({0}), {1} tile(s) loaded", name, images.size());
+        if (isRaster) {
+            str += "\n"+tr("Is not vectorized.");
+            str += "\n"+tr("Raster center: {0}", rasterCenter);
+        } else
+            str += "\n"+tr("Is vectorized.");
+            str += "\n"+tr("Commune bbox: {0}", communeBBox);
+        return str;
     }
 
