Changeset 4432 in josm
- Timestamp:
- 2011-09-17T12:20:34+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4430 r4432 70 70 private ImageryType imageryType = ImageryType.WMS; 71 71 private double pixelPerDegree = 0.0; 72 private int maxZoom = 0;73 72 private int defaultMaxZoom = 0; 74 73 private int defaultMinZoom = 0; … … 120 119 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 121 120 res.add(pixelPerDegree != 0.0 ? String.valueOf(pixelPerDegree) : null); 122 } else {123 res.add(maxZoom != 0 ? String.valueOf(maxZoom) : null);124 121 } 125 122 res.add(bounds != null ? bounds.encodeAsString(",") : null); … … 163 160 if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 164 161 this.pixelPerDegree=Double.valueOf(array.get(3)); 165 } else {166 this.maxZoom=Integer.valueOf(array.get(3));167 162 } 168 163 } … … 206 201 this.imageryType=i.imageryType; 207 202 this.defaultMinZoom=i.defaultMinZoom; 208 this.maxZoom=i.maxZoom;209 203 this.defaultMaxZoom=i.defaultMaxZoom; 210 204 this.pixelPerDegree=i.pixelPerDegree; … … 251 245 } 252 246 253 public void setMaxZoom(int maxZoom) {254 this.maxZoom = maxZoom;255 }256 257 247 public void setBounds(ImageryBounds b) { 258 248 this.bounds = b; … … 282 272 CheckParameterUtil.ensureParameterNotNull(url); 283 273 274 // Default imagery type is WMS 275 this.url = url; 276 this.imageryType = ImageryType.WMS; 277 284 278 defaultMaxZoom = 0; 285 279 defaultMinZoom = 0; … … 291 285 if(m.group(2) != null) { 292 286 defaultMaxZoom = Integer.valueOf(m.group(2)); 293 maxZoom = defaultMaxZoom;294 287 } 295 288 if(m.group(1) != null) { 296 289 defaultMinZoom = Integer.valueOf(m.group(1)); 297 290 } 298 return; 299 } 300 } 301 302 // Default imagery type is WMS 303 this.url = url; 304 this.imageryType = ImageryType.WMS; 291 break; 292 } 293 } 294 295 if(url.contains("{") && url.contains("}")) { 296 if(serverProjections == null || serverProjections.isEmpty()) { 297 try { 298 serverProjections = new ArrayList<String>(); 299 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase()); 300 if(m.matches()) { 301 for(String p : m.group(1).split(",")) 302 serverProjections.add(p); 303 } 304 } catch(Exception e) { 305 } 306 } 307 // FIXME: Remove else case in March 2012 - convert old style WMS/TMS 308 } else { 309 url = this.url; 310 if(imageryType == ImageryType.WMS) { 311 if(!url.endsWith("&") && !url.endsWith("?")) { 312 url = url + (url.contains("?") ? "&" : "?"); 313 } 314 try { 315 Matcher m = Pattern.compile(".*SRS=([a-z0-9:]+).*", Pattern.CASE_INSENSITIVE).matcher(url.toUpperCase()); 316 if(m.matches()) { 317 String newProj = m.group(1); 318 if(serverProjections == null || serverProjections.isEmpty()) 319 serverProjections = Collections.singletonList(newProj); 320 url = url.replaceAll("([sS][rR][sS]=)[a-zA-Z0-9:]+","SRS={proj("+newProj+")}"); 321 } else 322 url += "SRS={proj}&"; 323 } catch(Exception e) { 324 } 325 url += "WIDTH={width}&height={HEIGHT}&BBOX={bbox}"; 326 } 327 else if(imageryType == ImageryType.TMS) { 328 if(!url.endsWith("/")) 329 url += "/"; 330 url += "{zoom}/{x}/{y}.png"; 331 } 332 if(!url.equals(this.url)) { 333 Main.warn("Changed Imagery URL '"+this.url+"' to '"+url+"'"); 334 this.url = url; 335 } 336 } 305 337 } 306 338 … … 338 370 339 371 public int getMaxZoom() { 340 return this. maxZoom;372 return this.defaultMaxZoom; 341 373 } 342 374 … … 368 400 */ 369 401 public List<String> getServerProjections() { 370 if (serverProjections == null) return null; 402 if (serverProjections == null) 403 return Collections.emptyList(); 371 404 return Collections.unmodifiableList(serverProjections); 372 405 } … … 395 428 if(pixelPerDegree != 0.0) { 396 429 res += " ("+pixelPerDegree+")"; 397 } else if(maxZoom != 0 && maxZoom != defaultMaxZoom) {398 res += " (z"+maxZoom+")";399 430 } 400 431 return res; … … 447 478 public void setImageryType(ImageryType imageryType) { 448 479 this.imageryType = imageryType; 449 }450 451 public static boolean isUrlWithPatterns(String url) {452 return url != null && url.contains("{") && url.contains("}");453 480 } 454 481 -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r4356 r4432 905 905 } 906 906 } 907 /* Setting foreground properly handles null as default! */ 907 if(c == null) 908 c = Main.pref.getUIColor(isSelected ? "Table.selectionForeground" : "Table.foreground"); 908 909 label.setForeground(c); 909 910 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4417 r4432 236 236 public static TileSource getTileSource(ImageryInfo info) { 237 237 if (info.getImageryType() == ImageryType.TMS) { 238 if(ImageryInfo.isUrlWithPatterns(info.getUrl())) { 239 TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 240 info.setAttribution(t); 241 return t; 242 } else { 243 TMSTileSource t = new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 244 info.setAttribution(t); 245 return t; 246 } 238 TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 239 info.setAttribution(t); 240 return t; 247 241 } else if (info.getImageryType() == ImageryType.BING) 248 242 return new BingAerialTileSource(); -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r4430 r4432 109 109 private int workingThreadCount; 110 110 private boolean canceled; 111 private List<String> serverProjections = null;112 111 113 112 /** set to true if this layer uses an invalid base url */ … … 122 121 public WMSLayer(ImageryInfo info) { 123 122 super(info); 124 serverProjections = info.getServerProjections();125 123 mv = Main.map.mapView; 126 124 setBackgroundLayer(true); /* set global background variable */ … … 144 142 resolution = mv.getDist100PixelText(); 145 143 146 if(info.getUrl() != null) { 147 if (serverProjections == null) { 148 serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true); 149 } 144 if(info.getUrl() != null) 150 145 startGrabberThreads(); 151 if(info.getImageryType() == ImageryType.WMS && !ImageryInfo.isUrlWithPatterns(info.getUrl())) {152 if (!(info.getUrl().endsWith("&") || info.getUrl().endsWith("?"))) {153 if (!confirmMalformedUrl(info.getUrl())) {154 System.out.println(tr("Warning: WMS layer deactivated because of malformed base url ''{0}''", info.getUrl()));155 usesInvalidUrl = true;156 setName(getName() + tr("(deactivated)"));157 return;158 } else {159 isInvalidUrlConfirmed = true;160 }161 }162 }163 }164 146 165 147 Main.pref.addPreferenceChangeListener(this); … … 247 229 } else { 248 230 downloadAndPaintVisible(g, mv, false); 249 }250 }251 252 protected boolean confirmMalformedUrl(String url) {253 if (isInvalidUrlConfirmed)254 return true;255 String msg = tr("<html>The base URL<br>"256 + "''{0}''<br>"257 + "for this WMS layer does neither end with a ''&'' nor with a ''?''.<br>"258 + "This is likely to lead to invalid WMS request. You should check your<br>"259 + "preference settings.<br>"260 + "Do you want to fetch WMS tiles anyway?</html>",261 url);262 String [] options = new String[] {263 tr("Yes, fetch images"),264 tr("No, abort")265 };266 int ret = JOptionPane.showOptionDialog(267 Main.parent,268 msg,269 tr("Invalid URL?"),270 JOptionPane.YES_NO_OPTION,271 JOptionPane.WARNING_MESSAGE,272 null,273 options, options[1]274 );275 switch(ret) {276 case JOptionPane.YES_OPTION: return true;277 default: return false;278 231 } 279 232 } … … 918 871 } 919 872 920 /**921 * Get the list of projections supported by the WMS server corresponding to this layer.922 * @return The list of projections, if known. An empty list otherwise.923 */924 public List<String> getServerProjections() {925 if (serverProjections == null)926 return Collections.emptyList();927 else928 return Collections.unmodifiableList(serverProjections);929 }930 931 873 @Override 932 874 public boolean isProjectionSupported(Projection proj) { 933 return serverProjections == null || serverProjections.contains(proj.toCode().toUpperCase()) 875 List<String> serverProjections = info.getServerProjections(); 876 return serverProjections.contains(proj.toCode().toUpperCase()) 934 877 || (proj instanceof Mercator && serverProjections.contains("EPSG:4326")); 935 878 } … … 938 881 public String nameSupportedProjections() { 939 882 String res = ""; 940 for(String p : serverProjections) {883 for(String p : info.getServerProjections()) { 941 884 if(!res.isEmpty()) 942 885 res += ", "; -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4427 r4432 449 449 450 450 mod = listActive.getColumnModel(); 451 mod.getColumn(2).setPreferredWidth(50);452 451 mod.getColumn(1).setPreferredWidth(800); 453 452 mod.getColumn(0).setPreferredWidth(200); … … 722 721 class ImageryLayerTableModel extends DefaultTableModel { 723 722 public ImageryLayerTableModel() { 724 setColumnIdentifiers(new String[] { tr("Menu Name"), tr("Imagery URL") , trc("layer", "Zoom")});723 setColumnIdentifiers(new String[] { tr("Menu Name"), tr("Imagery URL")}); 725 724 } 726 725 … … 754 753 case 1: 755 754 return info.getExtendedUrl(); 756 case 2:757 return (info.getImageryType() == ImageryType.WMS || info.getImageryType() == ImageryType.HTML) ?758 (info.getPixelPerDegree() == 0.0 ? "" : info.getPixelPerDegree()) :759 (info.getMaxZoom() == 0 ? "" : info.getMaxZoom());760 755 default: 761 756 throw new ArrayIndexOutOfBoundsException(); … … 772 767 case 1: 773 768 info.setExtendedUrl((String)o); 774 break;775 case 2:776 info.setPixelPerDegree(0);777 info.setMaxZoom(0);778 try {779 if(info.getImageryType() == ImageryType.WMS || info.getImageryType() == ImageryType.HTML) {780 info.setPixelPerDegree(Double.parseDouble((String) o));781 } else {782 info.setMaxZoom(Integer.parseInt((String) o));783 }784 } catch (NumberFormatException e) {785 }786 769 break; 787 770 default: -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r4430 r4432 244 244 } else { 245 245 entry.setDefaultMaxZoom(val); 246 entry.setMaxZoom(val);247 246 } 248 247 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r4430 r4432 47 47 48 48 protected String baseURL; 49 private final boolean urlWithPatterns; 50 private List<String> serverProjections; 49 private ImageryInfo info; 51 50 private Map<String, String> props = new HashMap<String, String>(); 52 51 53 52 public WMSGrabber(MapView mv, WMSLayer layer) { 54 53 super(mv, layer); 55 this.baseURL = layer.getInfo().getUrl(); 56 this.serverProjections = layer.getServerProjections(); 57 /* URL containing placeholders? */ 58 urlWithPatterns = ImageryInfo.isUrlWithPatterns(baseURL); 54 this.info = layer.getInfo(); 55 this.baseURL = info.getUrl(); 59 56 if(layer.getInfo().getCookies() != null && !layer.getInfo().getCookies().equals("")) { 60 57 props.put("Cookie", layer.getInfo().getCookies()); … … 94 91 int wi, int ht) throws MalformedURLException { 95 92 String myProj = Main.getProjection().toCode(); 96 String srs = ""; 97 boolean useepsg = false; 98 // FIXME: Non-Pattern format should be dropped in future 99 try 100 { 101 Matcher m = Pattern.compile(".*SRS=([a-z0-9:]+).*", Pattern.CASE_INSENSITIVE).matcher(baseURL.toUpperCase()); 102 if(m.matches()) 103 { 104 if(m.group(1).equals("EPSG:4326") && Main.getProjection() instanceof Mercator) 105 useepsg = true; 106 } else if((Main.getProjection() instanceof Mercator) && !serverProjections.contains(myProj)) { 107 useepsg = true; 108 srs ="&srs=EPSG:4326"; 109 } else { 110 srs ="&srs="+myProj; 111 } 112 } 113 catch(Exception ex) 114 { 115 } 116 117 if(useepsg) // don't use mercator code directly 118 { 93 if((Main.getProjection() instanceof Mercator) && !info.getServerProjections().contains(myProj)) { 119 94 LatLon sw = Main.getProjection().eastNorth2latlon(new EastNorth(w, s)); 120 95 LatLon ne = Main.getProjection().eastNorth2latlon(new EastNorth(e, n)); … … 126 101 } 127 102 128 String str = baseURL; 129 String bbox = latLonFormat.format(w) + "," 130 + latLonFormat.format(s) + "," 131 + latLonFormat.format(e) + "," 132 + latLonFormat.format(n); 133 134 if (urlWithPatterns) { 135 str = str.replaceAll("\\{proj(\\([^})]+\\))?\\}", myProj) 136 .replaceAll("\\{bbox\\}", bbox) 103 return new URL(baseURL.replaceAll("\\{proj(\\([^})]+\\))?\\}", myProj) 104 .replaceAll("\\{bbox\\}", latLonFormat.format(w) + "," 105 + latLonFormat.format(s) + "," 106 + latLonFormat.format(e) + "," 107 + latLonFormat.format(n)) 137 108 .replaceAll("\\{w\\}", latLonFormat.format(w)) 138 109 .replaceAll("\\{s\\}", latLonFormat.format(s)) … … 140 111 .replaceAll("\\{n\\}", latLonFormat.format(n)) 141 112 .replaceAll("\\{width\\}", String.valueOf(wi)) 142 .replaceAll("\\{height\\}", String.valueOf(ht)); 143 } else { 144 str += "bbox=" + bbox 145 + srs 146 + "&width=" + wi + "&height=" + ht; 147 if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) { 148 System.out.println(tr("Warning: The base URL ''{0}'' for a WMS service doesn''t have a trailing ''&'' or a trailing ''?''.", baseURL)); 149 System.out.println(tr("Warning: Fetching WMS tiles is likely to fail. Please check you preference settings.")); 150 System.out.println(tr("Warning: The complete URL is ''{0}''.", str)); 151 } 152 } 153 return new URL(str.replace(" ", "%20")); 154 } 155 156 static public ArrayList<String> getServerProjections(String baseURL, Boolean warn) 157 { 158 ArrayList<String> serverProjections = new ArrayList<String>(); 159 boolean hasepsg = false; 160 161 // FIXME: Non-Pattern format should be dropped in future 162 try 163 { 164 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(baseURL.toUpperCase()); 165 if(m.matches()) 166 { 167 for(String p : m.group(1).split(",")) 168 { 169 serverProjections.add(p); 170 if(p.equals("EPSG:4326")) 171 hasepsg = true; 172 } 173 } 174 else 175 { 176 m = Pattern.compile(".*SRS=([a-z0-9:]+).*", Pattern.CASE_INSENSITIVE).matcher(baseURL.toUpperCase()); 177 if(m.matches()) 178 { 179 serverProjections.add(m.group(1)); 180 if(m.group(1).equals("EPSG:4326")) 181 hasepsg = true; 182 } 183 /* TODO: here should be an "else" code checking server capabilities */ 184 } 185 } 186 catch(Exception e) 187 { 188 } 189 if(serverProjections.isEmpty()) 190 return null; 191 if(warn) 192 { 193 String myProj = Main.getProjection().toCode().toUpperCase(); 194 if(!serverProjections.contains(myProj) && 195 !(Main.getProjection() instanceof Mercator && serverProjections.contains("EPSG:4326"))) 196 { 197 JOptionPane.showMessageDialog(Main.parent, 198 tr("The projection ''{0}'' in URL and current projection ''{1}'' mismatch.\n" 199 + "This may lead to wrong coordinates.", 200 serverProjections.get(0), myProj), 201 tr("Warning"), 202 JOptionPane.WARNING_MESSAGE); 203 } 204 } 205 return serverProjections; 113 .replaceAll("\\{height\\}", String.valueOf(ht)) 114 .replace(" ", "%20")); 206 115 } 207 116
Note:
See TracChangeset
for help on using the changeset viewer.