Changeset 4881 in josm
- Timestamp:
- 2012-01-31T18:41:36+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4861 r4881 245 245 } 246 246 247 public ImageryInfo(Collection<String> list) {248 ArrayList<String> array = new ArrayList<String>(list);249 this.name=array.get(0);250 if(array.size() >= 2 && !array.get(1).isEmpty()) {251 setExtendedUrl(array.get(1));252 }253 if(array.size() >= 3 && !array.get(2).isEmpty()) {254 this.cookies=array.get(2);255 }256 if(array.size() >= 4 && !array.get(3).isEmpty()) {257 if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {258 this.pixelPerDegree=Double.valueOf(array.get(3));259 }260 }261 if(array.size() >= 5 && !array.get(4).isEmpty()) {262 try {263 bounds = new ImageryBounds(array.get(4), ",");264 } catch (IllegalArgumentException e) {265 Main.warn(e.toString());266 }267 }268 if(array.size() >= 6 && !array.get(5).isEmpty()) {269 setAttributionText(array.get(5));270 }271 if(array.size() >= 7 && !array.get(6).isEmpty()) {272 setAttributionLinkURL(array.get(6));273 }274 if(array.size() >= 8 && !array.get(7).isEmpty()) {275 setAttributionImage(array.get(7));276 }277 if(array.size() >= 9 && !array.get(8).isEmpty()) {278 setTermsOfUseURL(array.get(8));279 }280 if(bounds != null && array.size() >= 10 && !array.get(9).isEmpty()) {281 try {282 for (String s : array.get(9).split(";")) {283 bounds.addShape(new Shape(s, ","));284 }285 } catch (IllegalArgumentException e) {286 Main.warn(e.toString());287 }288 }289 if(array.size() >= 11 && !array.get(10).isEmpty()) {290 serverProjections = Arrays.asList(array.get(10).split(","));291 }292 }293 294 247 public ImageryInfo(ImageryInfo i) { 295 248 this.name=i.name; … … 440 393 } 441 394 442 if(url.contains("{") && url.contains("}")) { 443 if(serverProjections == null || serverProjections.isEmpty()) { 444 try { 445 serverProjections = new ArrayList<String>(); 446 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase()); 447 if(m.matches()) { 448 for(String p : m.group(1).split(",")) 449 serverProjections.add(p); 450 } 451 } catch(Exception e) { 452 } 453 } 454 // FIXME: Remove else case in March 2012 - convert old style WMS/TMS 455 } else { 456 url = this.url; 457 if(imageryType == ImageryType.WMS) { 458 if(!url.endsWith("&") && !url.endsWith("?")) { 459 url = url + (url.contains("?") ? "&" : "?"); 460 } 461 try { 462 Matcher m = Pattern.compile(".*SRS=([a-z0-9:]+).*", Pattern.CASE_INSENSITIVE).matcher(url.toUpperCase()); 463 if(m.matches()) { 464 String newProj = m.group(1); 465 if(serverProjections == null || serverProjections.isEmpty()) 466 serverProjections = Collections.singletonList(newProj); 467 url = url.replaceAll("([sS][rR][sS]=)[a-zA-Z0-9:]+","SRS={proj("+newProj+")}"); 468 } else 469 url += "SRS={proj}&"; 470 } catch(Exception e) { 471 } 472 url += "WIDTH={width}&height={height}&BBOX={bbox}"; 473 } 474 else if(imageryType == ImageryType.TMS) { 475 if(!url.endsWith("/")) 476 url += "/"; 477 url += "{zoom}/{x}/{y}.png"; 478 } 479 if(!url.equals(this.url)) { 480 Main.warn("Changed Imagery URL '"+this.url+"' to '"+url+"'"); 481 this.url = url; 395 if(serverProjections == null || serverProjections.isEmpty()) { 396 try { 397 serverProjections = new ArrayList<String>(); 398 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase()); 399 if(m.matches()) { 400 for(String p : m.group(1).split(",")) 401 serverProjections.add(p); 402 } 403 } catch(Exception e) { 482 404 } 483 405 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r4853 r4881 44 44 boolean addedDefault = layers.size() != 0; 45 45 List<ImageryPreferenceEntry> entries = Main.pref.getListOfStructs("imagery.entries", null, ImageryPreferenceEntry.class); 46 if (entries == null) { 47 /* FIXME: Remove old format ~ March 2012 */ 48 boolean hasOld = loadOld(); 49 if (hasOld) { 50 save(); 51 } 52 } else { 46 if (entries != null) { 53 47 for (ImageryPreferenceEntry prefEntry : entries) { 54 48 try { … … 64 58 save(); 65 59 } 66 }67 68 public boolean loadOld() {69 Collection<Collection<String>> entries = Main.pref.getArray("imagery.layers", null);70 if (entries != null) {71 for (Collection<String> c : Main.pref.getArray("imagery.layers",72 Collections.<Collection<String>>emptySet())) {73 ImageryInfo i = new ImageryInfo(c);74 String url = i.getUrl();75 if(url != null) {76 /* FIXME: Remove the attribution copy stuff end of 2011 */77 if(!i.hasAttribution()) {78 for(ImageryInfo d : defaultLayers) {79 if(url.equals(d.getUrl())) {80 i.copyAttribution(d);81 i.setBounds(d.getBounds());82 break;83 }84 }85 }86 add(i);87 }88 }89 Collections.sort(layers);90 return true;91 }92 return false;93 60 } 94 61
Note:
See TracChangeset
for help on using the changeset viewer.