Changeset 4183 in josm


Ignore:
Timestamp:
Jun 29, 2011 10:06:35 AM (2 years ago)
Author:
stoecker
Message:

fix #6432 - projection handling for TMS and WMS

Location:
trunk
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r4126 r4183  
    1616import javax.swing.Action; 
    1717import javax.swing.Icon; 
     18import javax.swing.JOptionPane; 
    1819import javax.swing.JSeparator; 
    1920 
     21import org.openstreetmap.josm.Main; 
    2022import org.openstreetmap.josm.actions.GpxExportAction; 
    2123import org.openstreetmap.josm.actions.SaveAction; 
     
    7577    static public final String NAME_PROP = Layer.class.getName() + ".name"; 
    7678 
    77  
    7879    /** keeps track of property change listeners */ 
    7980    protected PropertyChangeSupport propertyChangeSupport; 
     
    308309 
    309310    /** 
    310      * 
     311     * Check changed status of layer 
    311312     * 
    312313     * @return True if layer was changed since last paint 
     
    314315    public boolean isChanged() { 
    315316        return true; 
     317    } 
     318 
     319    /** 
     320     * allows to check whether a projection is supported or not 
     321     * 
     322     * @return True if projection is supported for this layer 
     323     */ 
     324    public boolean isProjectionSupported(Projection proj) { 
     325        return true; 
     326    } 
     327 
     328    /** 
     329     * Specify user information about projections 
     330     * 
     331     * @return User readable text telling about supported projections 
     332     */ 
     333    public String nameSupportedProjections() { 
     334        return tr("All projections are supported"); 
    316335    } 
    317336 
     
    370389    @Override 
    371390    public void projectionChanged(Projection oldValue, Projection newValue) { 
    372         // default implementation does nothing - override in subclasses 
     391        if(!isProjectionSupported(newValue)) { 
     392              JOptionPane.showMessageDialog(Main.parent, 
     393                  tr("The layer {0} does not support the new projection {1}.\n{2}\n" 
     394                  + "Change the projection again or remove the layer.", 
     395                      getName(), newValue.toCode(), nameSupportedProjections()), 
     396                      tr("Warning"), 
     397                      JOptionPane.WARNING_MESSAGE); 
     398        } 
    373399    } 
    374400} 
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4126 r4183  
    3434import javax.swing.JCheckBoxMenuItem; 
    3535import javax.swing.JMenuItem; 
     36import javax.swing.JOptionPane; 
    3637import javax.swing.JPopupMenu; 
    3738import javax.swing.SwingUtilities; 
     
    6263import org.openstreetmap.josm.data.preferences.IntegerProperty; 
    6364import org.openstreetmap.josm.data.preferences.StringProperty; 
     65import org.openstreetmap.josm.data.projection.Epsg4326; 
     66import org.openstreetmap.josm.data.projection.Mercator; 
     67import org.openstreetmap.josm.data.projection.Projection; 
    6468import org.openstreetmap.josm.gui.MapView; 
    6569import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 
     
    314318    public TMSLayer(ImageryInfo info) { 
    315319        super(info); 
     320 
     321        if(!isProjectionSupported(Main.getProjection())) { 
     322              JOptionPane.showMessageDialog(Main.parent, 
     323                  tr("TMS layers do not support the projection {1}.\n{2}\n" 
     324                  + "Change the projection or remove the layer.", 
     325                      Main.getProjection().toCode(), nameSupportedProjections()), 
     326                      tr("Warning"), 
     327                      JOptionPane.WARNING_MESSAGE); 
     328        } 
    316329 
    317330        setBackgroundLayer(true); 
     
    13111324        return needRedraw; 
    13121325    } 
     1326 
     1327    @Override 
     1328    public boolean isProjectionSupported(Projection proj) { 
     1329        return proj instanceof Mercator || proj instanceof Epsg4326; 
     1330    } 
     1331 
     1332    @Override 
     1333    public String nameSupportedProjections() { 
     1334        return tr("EPSG:4326 and Mercator projection are supported"); 
     1335    } 
    13131336} 
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r4080 r4183  
    3838import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 
    3939import org.openstreetmap.josm.data.ProjectionBounds; 
     40import org.openstreetmap.josm.data.projection.Projection; 
    4041import org.openstreetmap.josm.data.coor.EastNorth; 
    4142import org.openstreetmap.josm.data.imagery.GeorefImage; 
     
    107108    private int workingThreadCount; 
    108109    private boolean canceled; 
    109  
     110    private ArrayList<String> serverProjections = null; 
    110111 
    111112    /** set to true if this layer uses an invalid base url */ 
     
    142143 
    143144        if(info.getUrl() != null) { 
    144             WMSGrabber.getProjection(info.getUrl(), true); 
     145            serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true); 
    145146            startGrabberThreads(); 
    146147            if(info.getImageryType() == ImageryType.WMS && !ImageryInfo.isUrlWithPatterns(info.getUrl())) { 
     
    913914    } 
    914915 
     916    @Override 
     917    public boolean isProjectionSupported(Projection proj) { 
     918        return serverProjections == null || serverProjections.contains(proj.toCode().toUpperCase()); 
     919    } 
     920 
     921    @Override 
     922    public String nameSupportedProjections() { 
     923        String res = ""; 
     924        for(String p : serverProjections) { 
     925            if(!res.isEmpty()) 
     926                res += ", "; 
     927            res += p; 
     928        } 
     929        return tr("Supported projections are: {1}", res); 
     930    } 
    915931} 
  • 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.