Changeset 22941 in osm for applications
- Timestamp:
- 2010-09-02T13:51:19+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/AddWMSLayerPanel.java
r22936 r22941 18 18 import java.net.URL; 19 19 import java.net.URLConnection; 20 import java.util.Hash Map;20 import java.util.HashSet; 21 21 import java.util.Iterator; 22 22 import java.util.LinkedList; 23 23 import java.util.List; 24 import java.util. Map;24 import java.util.Set; 25 25 26 26 import javax.swing.JButton; … … 46 46 import org.openstreetmap.josm.data.Bounds; 47 47 import org.openstreetmap.josm.data.projection.Projection; 48 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs; 48 49 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 49 50 import org.openstreetmap.josm.tools.GBC; … … 55 56 import org.xml.sax.SAXException; 56 57 58 57 59 public class AddWMSLayerPanel extends JPanel { 58 60 private List<LayerDetails> selectedLayers; … … 68 70 69 71 private boolean previouslyShownUnsupportedCrsError = false; 70 71 private static final Map<String, Projection> supportedProjections = new HashMap<String, Projection>();72 static {73 for (Projection proj : Projection.allProjections) {74 supportedProjections.put(proj.toCode().trim().toUpperCase(), proj);75 }76 }77 72 78 73 public AddWMSLayerPanel() { … … 280 275 Element capabilityElem = getChild(document.getDocumentElement(), "Capability"); 281 276 List<Element> children = getChildren(capabilityElem, "Layer"); 282 List<LayerDetails> layers = parseLayers(children );277 List<LayerDetails> layers = parseLayers(children, new HashSet<String>()); 283 278 284 279 updateTreeList(layers); … … 298 293 } 299 294 300 private List<LayerDetails> parseLayers(List<Element> children ) {295 private List<LayerDetails> parseLayers(List<Element> children, Set<String> parentCrs) { 301 296 List<LayerDetails> details = new LinkedList<LayerDetails>(); 302 297 for (Element element : children) { 303 details.add(parseLayer(element ));298 details.add(parseLayer(element, parentCrs)); 304 299 } 305 300 return details; 306 301 } 307 302 308 private LayerDetails parseLayer(Element element ) {303 private LayerDetails parseLayer(Element element, Set<String> parentCrs) { 309 304 String name = getChildContent(element, "Title", null, null); 310 305 String ident = getChildContent(element, "Name", null, null); 311 306 312 boolean josmSupportsThisLayer = false; 313 List<String> crsList = new LinkedList<String>(); 307 // The set of supported CRS/SRS for this layer 308 Set<String> crsList = new HashSet<String>(); 309 // ...including this layer's already-parsed parent projections 310 crsList.addAll(parentCrs); 311 312 // Parse the CRS/SRS pulled out of this layer's XML element 314 313 // I think CRS and SRS are the same at this point 315 314 List<Element> crsChildren = getChildren(element, "CRS"); … … 320 319 String upperCase = crs.trim().toUpperCase(); 321 320 crsList.add(upperCase); 322 josmSupportsThisLayer |= supportedProjections.containsKey(upperCase); 323 } 321 } 322 } 323 324 // Check to see if any of the specified projections are supported by JOSM 325 boolean josmSupportsThisLayer = false; 326 for (String crs : crsList) { 327 josmSupportsThisLayer |= isProjSupported(crs); 324 328 } 325 329 … … 346 350 347 351 List<Element> layerChildren = getChildren(element, "Layer"); 348 List<LayerDetails> childLayers = parseLayers(layerChildren );352 List<LayerDetails> childLayers = parseLayers(layerChildren, crsList); 349 353 350 354 return new LayerDetails(name, ident, crsList, josmSupportsThisLayer, bounds, childLayers); 355 } 356 357 private boolean isProjSupported(String crs) { 358 for (Projection proj : Projection.allProjections) { 359 if (proj instanceof ProjectionSubPrefs) { 360 return ((ProjectionSubPrefs) proj).getPreferencesFromCode(crs) == null; 361 } else { 362 return proj.toCode().equals(crs); 363 } 364 } 365 return false; 351 366 } 352 367 … … 417 432 private String name; 418 433 private String ident; 419 private List<String> crsList;434 private Set<String> crsList; 420 435 private List<LayerDetails> children; 421 436 private Bounds bounds; 422 437 private boolean supported; 423 438 424 public LayerDetails(String name, String ident, List<String> crsList,439 public LayerDetails(String name, String ident, Set<String> crsList, 425 440 boolean supportedLayer, Bounds bounds, 426 441 List<LayerDetails> childLayers) {
Note:
See TracChangeset
for help on using the changeset viewer.