Changeset 18207 in osm for applications


Ignore:
Timestamp:
2009-10-18T18:11:09+02:00 (15 years ago)
Author:
pieren
Message:

Use the new cadastre projection LambertCC9Zones

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java

    r17719 r18207  
    2121import javax.swing.JOptionPane;
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    2324
    2425public class CacheControl implements Runnable {
     26   
     27    public static final String cLambertCC9Z = "CC";
    2528
    2629    public class ObjectOutputStreamAppend extends ObjectOutputStream {
     
    8184    public boolean loadCacheIfExist() {
    8285        try {
    83             File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + String.valueOf(wmsLayer.lambertZone+1));
     86            String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
     87            if (Main.proj instanceof LambertCC9Zones)
     88                extension = cLambertCC9Z + extension;
     89            File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
    8490            if (file.exists()) {
    8591                JOptionPane pane = new JOptionPane(
     
    96102
    97103                if (reply == JOptionPane.OK_OPTION) {
    98                     return loadCache(file, wmsLayer.lambertZone);
     104                    return loadCache(file, wmsLayer.getLambertZone());
    99105                } else
    100106                    file.delete();
     
    108114    public void deleteCacheFile() {
    109115        try {
    110             File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + String.valueOf(wmsLayer.lambertZone+1));
     116            String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
     117            if (Main.proj instanceof LambertCC9Zones)
     118                extension = cLambertCC9Z + extension;
     119            File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
    111120            if (file.exists())
    112121                file.delete();
     
    155164            imagesLock.unlock();
    156165            if (images != null && !images.isEmpty()) {
    157                 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + String.valueOf((wmsLayer.lambertZone + 1)));
     166                String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
     167                if (Main.proj instanceof LambertCC9Zones)
     168                    extension = cLambertCC9Z + extension;
     169                File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
    158170                try {
    159171                    if (file.exists()) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java

    r17089 r18207  
    7474        //str += "&width=800&height=600"; // maximum allowed by wms server
    7575        str += "&width=1000&height=800"; // maximum allowed by wms server
     76        //str += "&exception=application/vnd.ogc.se_inimage"; // used by normal client but not required
    7677        str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90";
    7778        str += ",SUBSECTION_90";
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java

    r17710 r18207  
    77import java.awt.event.ActionListener;
    88import java.awt.event.KeyEvent;
    9 import java.util.LinkedList;
    109
    1110import javax.swing.JCheckBoxMenuItem;
     
    7574 * 1.3 23-Aug-2009 - improve georeferencing action cancellation
    7675 *                 - fixed bug of raster image loaded from cache not working on Java1.6
    77  *                 - improve mouse click bounce detection during georeferencing process
     76 *                 - improve mouse click bounce detection during georeferencing process
     77 * 1.4 17-Oct-2009 - add support for new Lambert CC 9 Zones projection
    7878 */
    7979public class CadastrePlugin extends Plugin {
    80     static String VERSION = "1.3";
     80    static String VERSION = "1.4";
    8181
    8282    static JMenu cadastreJMenu;
     
    121121
    122122        refreshConfiguration();
    123         refreshMenu();
    124123
    125124        UploadAction.registerUploadHook(new CheckSourceUploadHook());
    126125    }
    127126
    128     public void refreshMenu() throws Exception {
     127    public static void refreshMenu() {
    129128        MainMenu menu = Main.main.menu;
    130129
     
    207206        } else
    208207            System.out.println("shortcut F11 already redefined; do not change");
     208
     209        refreshMenu();
    209210    }
    210211
     
    214215    }
    215216
    216     private void setEnabledAll(boolean isEnabled) {
     217    private static void setEnabledAll(boolean isEnabled) {
     218        boolean isLambertCC9Zones = Main.proj instanceof LambertCC9Zones;
    217219        for (int i = 0; i < cadastreJMenu.getItemCount(); i++) {
    218220            JMenuItem item = cadastreJMenu.getItem(i);
    219221            if (item != null)
    220                 if (item.getText().equals(MenuActionGrab.name) ||
    221                     item.getText().equals(MenuActionGrabPlanImage.name) /* ||
     222                if (item.getText().equals(MenuActionGrabPlanImage.name) /*||
     223                    item.getText().equals(MenuActionGrab.name) ||
    222224                    item.getText().equals(MenuActionBoundaries.name) ||
    223225                    item.getText().equals(MenuActionBuildings.name)*/) {
     
    239241                setEnabledAll(false);
    240242                Lambert.layoutZone = -1;
     243                LambertCC9Zones.layoutZone = -1;
    241244            }
    242245        }
     
    248251            || Main.proj.toString().equals(new UTM_20N_Guadeloupe_Ste_Anne().toString())
    249252            || Main.proj.toString().equals(new UTM_20N_Martinique_Fort_Desaix().toString())
    250             || Main.proj.toString().equals(new GaussLaborde_Reunion().toString());
     253            || Main.proj.toString().equals(new GaussLaborde_Reunion().toString())
     254            || Main.proj.toString().equals(new LambertCC9Zones().toString());
    251255    }
    252256
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java

    r17215 r18207  
    240240        CacheControl.cacheEnabled = enableCache.isSelected();
    241241        CadastrePlugin.refreshConfiguration();
     242        CadastrePlugin.refreshMenu();
    242243
    243244        return false;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java

    r17089 r18207  
    77import org.openstreetmap.josm.Main;
    88import org.openstreetmap.josm.data.Bounds;
     9import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    910import org.openstreetmap.josm.gui.MapView;
    1011import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    3839                        }
    3940                    }
    40                     if (wmsLayer.isRaster())
     41                    if (wmsLayer.isRaster()) {
    4142                        // set raster image commune bounding box based on current view (before adjustment)
    4243                        wmsLayer.setRasterBounds(bounds);
    43                     else
     44                    } else {
    4445                        // set vectorized commune bounding box by opening the standard web window
    4546                        wmsLayer.setCommuneBBox( grabber.getWmsInterface().retrieveCommuneBBox());
     47                        // if it is the first layer, use the communeBBox as grab bbox
     48                        if (Main.proj instanceof LambertCC9Zones && Main.map.mapView.getAllLayers().size() == 1 ) {
     49                            bounds = wmsLayer.getCommuneBBox().toBounds();
     50                            Main.map.mapView.zoomTo(bounds);
     51                        }
     52                    }
    4653                }
    4754                // grab new images from wms server into active layer
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/EastNorthBound.java

    r15961 r18207  
    33import java.io.Serializable;
    44
     5import org.openstreetmap.josm.Main;
     6import org.openstreetmap.josm.data.Bounds;
    57import org.openstreetmap.josm.data.coor.EastNorth;
    68
     
    2830        return enb;
    2931    }
     32   
     33    public Bounds toBounds() {
     34        return new Bounds(Main.proj.eastNorth2latlon(min), Main.proj.eastNorth2latlon(max));
     35    }
    3036
    3137    @Override public String toString() {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java

    r17181 r18207  
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.actions.JosmAction;
     12import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    1213import org.openstreetmap.josm.tools.Shortcut;
    1314
     
    2829
    2930    public void actionPerformed(ActionEvent e) {
    30         if (Main.map != null) {
     31        // with the new projection LambertCC9Zones, we are able to determin the zone and thus lat/lon of
     32        // downloaded commune bounding box
     33        if (Main.map != null || Main.proj instanceof LambertCC9Zones) {
    3134            if (CadastrePlugin.isCadastreProjection()) {
    3235                WMSLayer wmsLayer = WMSDownloadAction.getLayer();
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLambertZone.java

    r13611 r18207  
    1414import org.openstreetmap.josm.actions.JosmAction;
    1515import org.openstreetmap.josm.data.projection.Lambert;
     16import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    1617import org.openstreetmap.josm.tools.GBC;
    1718
     
    2223    public static String name = "Change Lambert zone";
    2324
     25    public static String[] lambert4zones = { "", "1 (51.30 to 48.15 degrees)", "2 (48.15 to 45.45 degrees)", "3 (45.45 to 42.76 degrees)", "4 (Corsica)" };
     26    public static String[] lambert9zones = { "", "1 (41 to 43 degrees)", "2 (42 to 44 degrees)",
     27            "3 (43 to 45 degrees)", "4 (44 to 46 degrees)", "5 (45 to 47 degrees)",
     28            "6 (46 to 48 degrees)", "7 (47 to 49 degrees)", "8 (48 to 50 degrees)",
     29            "9 (49 to 51 degrees)" };
     30
    2431    public MenuActionLambertZone() {
    25         super(tr(name), "cadastre_small", tr("Set manually the Lambert zone (e.g. for locations between two zones)"),
     32        super(tr(name), "cadastre_small", tr("Set manually the Lambert zone"),
    2633                null, false);
    2734    }
     
    2936    public void actionPerformed(ActionEvent e) {
    3037        JPanel p = new JPanel(new GridBagLayout());
    31         String[] zones = { "", "1 (51.30 to 48.15 degrees)", "2 (48.15 to 45.45 degrees)", "3 (45.45 to 42.76 degrees)", "4 (Corsica)" };
    32         final JComboBox inputLambertZone = new JComboBox(zones);
     38        final JComboBox inputLambertZone;
     39        if (Main.proj instanceof LambertCC9Zones)
     40            inputLambertZone = new JComboBox(lambert9zones);
     41        else
     42            inputLambertZone = new JComboBox(lambert4zones);
    3343        JLabel newLambertZone = new JLabel(tr("Zone"));
    3444        p.add(newLambertZone, GBC.std());
     
    4757        if (inputLambertZone.getSelectedIndex() > 0) {
    4858            Lambert.layoutZone = inputLambertZone.getSelectedIndex() - 1;
     59            LambertCC9Zones.layoutZone = Lambert.layoutZone;
    4960        }
    5061    }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java

    r17719 r18207  
    66import java.io.File;
    77import javax.swing.JFileChooser;
     8import javax.swing.JOptionPane;
     9
    810import org.openstreetmap.josm.Main;
    911import org.openstreetmap.josm.actions.JosmAction;
    1012import org.openstreetmap.josm.data.projection.Lambert;
     13import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    1114import org.openstreetmap.josm.gui.layer.Layer;
    1215
     
    3134                String filename = file.getName();
    3235                String ext = (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length());
    33                 String location = filename.substring(0, filename.lastIndexOf("."));
    34                 // check the extension and its Lambert zone consistency
    35                 try {
    36                     int cacheZone = Integer.parseInt(ext) - 1;
    37                     if (cacheZone >=0 && cacheZone <= 3) {
    38                         if (Lambert.layoutZone == -1) {
    39                             Lambert.layoutZone = cacheZone;
    40                             System.out.println("Load cache \"" + filename + "\" in Lambert Zone " + (Lambert.layoutZone+1));
    41                         } else if (cacheZone != Lambert.layoutZone) {
    42                             System.out.println("Cannot load cache \"" + filename + "\" which is not in current Lambert Zone "
    43                                     + Lambert.layoutZone);
    44                             continue nextFile;
    45                         } else
    46                             System.out.println("Load cache " + filename);
     36                if ((ext.length() > 2 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z) &&
     37                    !(Main.proj instanceof LambertCC9Zones))
     38                    || (ext.length() == 1) && !(Main.proj instanceof Lambert)) {
     39                        JOptionPane.showMessageDialog(Main.parent, tr("{0} not allowed with the current projection", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
     40                        continue;
     41                } else {
     42                    String location = filename.substring(0, filename.lastIndexOf("."));
     43                    if (ext.length() > 2 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z))
     44                        ext = ext.substring(2);
     45                    // check the extension and its Lambert zone consistency
     46                    try {
     47                        int cacheZone = Integer.parseInt(ext) - 1;
     48                        if (cacheZone >=0 && cacheZone <= 3) {
     49                            if (Lambert.layoutZone == -1) {
     50                                Lambert.layoutZone = cacheZone;
     51                                System.out.println("Load cache \"" + filename + "\" in Lambert Zone " + (Lambert.layoutZone+1));
     52                            } else if (cacheZone != Lambert.layoutZone) {
     53                                System.out.println("Cannot load cache \"" + filename + "\" which is not in current Lambert Zone "
     54                                        + Lambert.layoutZone);
     55                                continue nextFile;
     56                            } else
     57                                System.out.println("Load cache " + filename);
     58                        }
     59                    } catch (NumberFormatException ex) {
     60                        System.out.println("Selected file \"" + filename + "\" is not a WMS cache file (invalid extension)");
     61                        continue;
    4762                    }
    48                 } catch (NumberFormatException ex) {
    49                     System.out.println("Selected file \"" + filename + "\" is not a WMS cache file (invalid extension)");
    50                     continue;
    51                 }
    52                 // check if the selected cache is not already displayed
    53                 if (Main.map != null) {
    54                     for (Layer l : Main.map.mapView.getAllLayers()) {
    55                         if (l instanceof WMSLayer && l.getName().equals(location)) {
    56                             System.out.println("The location " + filename + " is already on screen. Cache not loaded.");
    57                             continue nextFile;
     63                    // check if the selected cache is not already displayed
     64                    if (Main.map != null) {
     65                        for (Layer l : Main.map.mapView.getAllLayers()) {
     66                            if (l instanceof WMSLayer && l.getName().equals(location)) {
     67                                System.out.println("The location " + filename + " is already on screen. Cache not loaded.");
     68                                continue nextFile;
     69                            }
    5870                        }
    5971                    }
     72                    // create layer and load cache
     73                    WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1);
     74                    if (wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone))
     75                        Main.main.addLayer(wmsLayer);
     76                   
    6077                }
    61                 // create layer and load cache
    62                 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1);
    63                 if (wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone))
    64                     Main.main.addLayer(wmsLayer);
    6578            }
    6679        }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java

    r17089 r18207  
    1616import org.openstreetmap.josm.actions.JosmAction;
    1717import org.openstreetmap.josm.data.projection.Lambert;
     18import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    1819import org.openstreetmap.josm.gui.layer.Layer;
    1920import org.openstreetmap.josm.tools.GBC;
     
    3435
    3536    public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
    36         if (Main.map == null) {
     37        /*if (Main.map == null) {
    3738            JOptionPane.showMessageDialog(Main.parent,
    3839                    tr("Open a layer first (GPX, OSM, cache)"));
    3940            return null;
    40             /*
    41         } else if (existingLayers != null && existingLayers.size() > 0) {
    42             JOptionPane.showMessageDialog(Main.parent,
    43                     tr("Select one cadastre layer first"));
    44             return null;*/
    45         } else {
     41        } else {*/
    4642            String location = "";
    4743            String codeDepartement = "";
     
    7874                Main.pref.put("cadastrewms.location", location);
    7975                Main.pref.put("cadastrewms.codeCommune", codeCommune);
    80                 for (Layer l : Main.map.mapView.getAllLayers()) {
    81                     if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
    82                         return null;
     76                if (Main.map != null) {
     77                    for (Layer l : Main.map.mapView.getAllLayers()) {
     78                        if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
     79                            return null;
     80                        }
    8381                    }
    8482                }
    8583                // add the layer if it doesn't exist
    86                 wmsLayer = new WMSLayer(location, codeCommune, Lambert.layoutZone);
     84                if (Main.proj instanceof LambertCC9Zones)
     85                    wmsLayer = new WMSLayer(location, codeCommune, LambertCC9Zones.layoutZone);
     86                else
     87                    wmsLayer = new WMSLayer(location, codeCommune, Lambert.layoutZone);
    8788                Main.main.addLayer(wmsLayer);
    8889                System.out.println("Add new layer with Location:" + inputTown.getText());
     
    9596                CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
    9697            return wmsLayer;
    97         }
     98        //}
    9899    }
    99100
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java

    r17089 r18207  
    2626    public static WMSLayer getLayer() {
    2727        // check if we already have a layer created. if not, create; if yes, reuse.
     28        ArrayList<WMSLayer> existingWMSlayers = new ArrayList<WMSLayer>();
    2829        if (Main.map != null) {
    2930            Layer activeLayer = Main.map.mapView.getActiveLayer();
    3031            if (activeLayer instanceof WMSLayer)
    3132                return (WMSLayer) activeLayer;
    32             ArrayList<WMSLayer> existingWMSlayers = new ArrayList<WMSLayer>();
    3333            for (Layer l : Main.map.mapView.getAllLayers()) {
    3434                if (l instanceof WMSLayer) {
     
    4242            JOptionPane.showMessageDialog(Main.parent,
    4343                    tr("More than one WMS layer present\nSelect one of them first, then retry"));
     44        } else {
     45            return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
    4446        }
    4547        return null;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r17719 r18207  
    1919import javax.swing.Icon;
    2020import javax.swing.ImageIcon;
     21import javax.swing.JDialog;
    2122import javax.swing.JMenuItem;
    2223import javax.swing.JOptionPane;
     
    2526import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2627import org.openstreetmap.josm.data.projection.Lambert;
     28import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    2729import org.openstreetmap.josm.data.Bounds;
    2830import org.openstreetmap.josm.gui.MapView;
     
    4244    Component[] component = null;
    4345
    44     public int lambertZone = -1;
     46    private int lambertZone = -1;
    4547
    4648    protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
     
    7779        this.location = location;
    7880        this.codeCommune = codeCommune;
    79         this.lambertZone = Lambert.layoutZone;
     81        this.lambertZone = lambertZone;
    8082        // enable auto-sourcing option
    8183        CadastrePlugin.pluginUsed = true;
     
    380382        }
    381383        this.communeBBox = (EastNorthBound) ois.readObject();
    382         if (this.lambertZone != currentLambertZone) {
     384        if (this.lambertZone != currentLambertZone && currentLambertZone != -1) {
    383385            JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+
    384386                    "incompatible with current Lambert zone {1}",
     
    484486    public void setCommuneBBox(EastNorthBound entireCommune) {
    485487        this.communeBBox = entireCommune;
     488        if (Main.proj instanceof LambertCC9Zones)
     489            setLambertCC9Zone(communeBBox.min.north());
    486490    }
    487491
     
    493497    }
    494498
     499    public int getLambertZone() {
     500        return lambertZone;
     501    }
     502
     503    public void setLambertCC9Zone(double north) {
     504        int lambertZone = LambertCC9Zones.north2ZoneNumber(north);
     505        this.lambertZone = lambertZone;
     506        if (LambertCC9Zones.layoutZone != lambertZone) {
     507            String currentZone = MenuActionLambertZone.lambert9zones[LambertCC9Zones.layoutZone+1];
     508            String destZone = MenuActionLambertZone.lambert9zones[lambertZone+1];
     509            if (Main.map.mapView.getAllLayers().size() == 1) {
     510                /* Enable this code below when JOSM will have a proper support of dynamic projection change
     511                 *
     512                System.out.println("close all layers and change current Lambert zone from "+LambertCC9Zones.layoutZone+" to "+lambertZone);
     513                Bounds b = null;
     514                if (Main.map != null && Main.map.mapView != null)
     515                    b = Main.map.mapView.getRealBounds();
     516                LambertCC9Zones.layoutZone = lambertZone;
     517                Main.map.mapView.zoomTo(b);
     518                */
     519            } else {
     520                JOptionPane.showMessageDialog(Main.parent, tr("Current layer is in Lambert CC9 Zone \"{0}\"\n"+
     521                        "where the commune is in Lambert CC9 Zone \"{1}\".\n"+
     522                        "Upload your changes, close all layers and change\n"+
     523                        "manually the Lambert zone from the Cadastre menu"
     524                        , currentZone, destZone));
     525            }
     526        }
     527    }
     528
    495529}
Note: See TracChangeset for help on using the changeset viewer.