Changeset 4183 in josm for trunk/src/org
- Timestamp:
- 2011-06-29T10:06:35+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r4126 r4183 16 16 import javax.swing.Action; 17 17 import javax.swing.Icon; 18 import javax.swing.JOptionPane; 18 19 import javax.swing.JSeparator; 19 20 21 import org.openstreetmap.josm.Main; 20 22 import org.openstreetmap.josm.actions.GpxExportAction; 21 23 import org.openstreetmap.josm.actions.SaveAction; … … 75 77 static public final String NAME_PROP = Layer.class.getName() + ".name"; 76 78 77 78 79 /** keeps track of property change listeners */ 79 80 protected PropertyChangeSupport propertyChangeSupport; … … 308 309 309 310 /** 310 * 311 * Check changed status of layer 311 312 * 312 313 * @return True if layer was changed since last paint … … 314 315 public boolean isChanged() { 315 316 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"); 316 335 } 317 336 … … 370 389 @Override 371 390 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 } 373 399 } 374 400 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4126 r4183 34 34 import javax.swing.JCheckBoxMenuItem; 35 35 import javax.swing.JMenuItem; 36 import javax.swing.JOptionPane; 36 37 import javax.swing.JPopupMenu; 37 38 import javax.swing.SwingUtilities; … … 62 63 import org.openstreetmap.josm.data.preferences.IntegerProperty; 63 64 import org.openstreetmap.josm.data.preferences.StringProperty; 65 import org.openstreetmap.josm.data.projection.Epsg4326; 66 import org.openstreetmap.josm.data.projection.Mercator; 67 import org.openstreetmap.josm.data.projection.Projection; 64 68 import org.openstreetmap.josm.gui.MapView; 65 69 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; … … 314 318 public TMSLayer(ImageryInfo info) { 315 319 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 } 316 329 317 330 setBackgroundLayer(true); … … 1311 1324 return needRedraw; 1312 1325 } 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 } 1313 1336 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r4080 r4183 38 38 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 39 39 import org.openstreetmap.josm.data.ProjectionBounds; 40 import org.openstreetmap.josm.data.projection.Projection; 40 41 import org.openstreetmap.josm.data.coor.EastNorth; 41 42 import org.openstreetmap.josm.data.imagery.GeorefImage; … … 107 108 private int workingThreadCount; 108 109 private boolean canceled; 109 110 private ArrayList<String> serverProjections = null; 110 111 111 112 /** set to true if this layer uses an invalid base url */ … … 142 143 143 144 if(info.getUrl() != null) { 144 WMSGrabber.getProjection(info.getUrl(), true);145 serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true); 145 146 startGrabberThreads(); 146 147 if(info.getImageryType() == ImageryType.WMS && !ImageryInfo.isUrlWithPatterns(info.getUrl())) { … … 913 914 } 914 915 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 } 915 931 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r4172 r4183 18 18 import java.text.DecimalFormatSymbols; 19 19 import java.text.NumberFormat; 20 import java.util.ArrayList; 20 21 import java.util.Locale; 21 22 import java.util.regex.Matcher; … … 73 74 int wi, int ht) throws MalformedURLException { 74 75 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 76 97 { 77 98 LatLon sw = Main.getProjection().eastNorth2latlon(new EastNorth(w, s)); … … 101 122 } else { 102 123 str += "bbox=" + bbox 103 + getProjection(baseURL, false)124 + srs 104 125 + "&width=" + wi + "&height=" + ht; 105 126 if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) { … … 112 133 } 113 134 114 static public String getProjection(String baseURL, Boolean warn)135 static public ArrayList<String> getServerProjections(String baseURL, Boolean warn) 115 136 { 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>(); 121 138 try 122 139 { 123 Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.to LowerCase());140 Matcher m = Pattern.compile(".*srs=([a-z0-9:]+).*").matcher(baseURL.toUpperCase()); 124 141 if(m.matches()) 125 142 { 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 */ 139 148 } 140 149 catch(Exception e) 141 150 { 142 151 } 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; 144 168 } 145 169
Note:
See TracChangeset
for help on using the changeset viewer.