Ignore:
Timestamp:
2011-06-29T10:06:35+02:00 (13 years ago)
Author:
stoecker
Message:

fix #6432 - projection handling for TMS and WMS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java

    r4172 r4183  
    1818import java.text.DecimalFormatSymbols;
    1919import java.text.NumberFormat;
     20import java.util.ArrayList;
    2021import java.util.Locale;
    2122import java.util.regex.Matcher;
     
    7374            int wi, int ht) throws MalformedURLException {
    7475        String myProj = Main.getProjection().toCode();
    75         if(Main.getProjection() instanceof Mercator) // don't use mercator code directly
     76        String srs = "";
     77        boolean useepsg = false;
     78        try
     79        {
     80            Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toUpperCase());
     81            if(m.matches())
     82            {
     83                if(m.group(1).equals("EPSG:4326") && Main.getProjection() instanceof Mercator)
     84                    useepsg = true;
     85            } else if(Main.getProjection() instanceof Mercator) {
     86                useepsg = true;
     87                srs ="&srs=EPSG:4326";
     88            } else {
     89                srs ="&srs="+myProj;
     90            }
     91        }
     92        catch(Exception ex)
     93        {
     94        }
     95
     96        if(useepsg) // don't use mercator code directly
    7697        {
    7798            LatLon sw = Main.getProjection().eastNorth2latlon(new EastNorth(w, s));
     
    101122        } else {
    102123            str += "bbox=" + bbox
    103             + getProjection(baseURL, false)
     124            + srs
    104125            + "&width=" + wi + "&height=" + ht;
    105126            if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) {
     
    112133    }
    113134
    114     static public String getProjection(String baseURL, Boolean warn)
     135    static public ArrayList<String> getServerProjections(String baseURL, Boolean warn)
    115136    {
    116         String projname = Main.getProjection().toCode();
    117         if(Main.getProjection() instanceof Mercator) {
    118             projname = "EPSG:4326";
    119         }
    120         String res = "";
     137        ArrayList<String> serverProjections = new ArrayList<String>();
    121138        try
    122139        {
    123             Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toLowerCase());
     140            Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toUpperCase());
    124141            if(m.matches())
    125142            {
    126                 projname = projname.toLowerCase();
    127                 if(!projname.equals(m.group(1)) && warn)
    128                 {
    129                     JOptionPane.showMessageDialog(Main.parent,
    130                             tr("The projection ''{0}'' in URL and current projection ''{1}'' mismatch.\n"
    131                                     + "This may lead to wrong coordinates.",
    132                                     m.group(1), projname),
    133                                     tr("Warning"),
    134                                     JOptionPane.WARNING_MESSAGE);
    135                 }
    136             } else {
    137                 res ="&srs="+projname;
    138             }
     143                serverProjections.add(m.group(1));
     144                if(m.group(1).equals("EPSG:4326"))
     145                    serverProjections.add(new Mercator().toCode());
     146            }
     147            /* TODO: here should be an "else" code checking server capabilities */
    139148        }
    140149        catch(Exception e)
    141150        {
    142151        }
    143         return res;
     152        if(serverProjections.isEmpty())
     153            return null;
     154        if(warn)
     155        {
     156            String myProj = Main.getProjection().toCode().toUpperCase();
     157            if(!serverProjections.contains(myProj))
     158            {
     159                JOptionPane.showMessageDialog(Main.parent,
     160                        tr("The projection ''{0}'' in URL and current projection ''{1}'' mismatch.\n"
     161                                + "This may lead to wrong coordinates.",
     162                                serverProjections.get(0), myProj),
     163                                tr("Warning"),
     164                                JOptionPane.WARNING_MESSAGE);
     165            }
     166        }
     167        return serverProjections;
    144168    }
    145169
Note: See TracChangeset for help on using the changeset viewer.