Ignore:
Timestamp:
2010-09-02T13:51:19+02:00 (14 years ago)
Author:
yellowbkpk
Message:

Should be handling all of the available projections and subprojections now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/AddWMSLayerPanel.java

    r22936 r22941  
    1818import java.net.URL;
    1919import java.net.URLConnection;
    20 import java.util.HashMap;
     20import java.util.HashSet;
    2121import java.util.Iterator;
    2222import java.util.LinkedList;
    2323import java.util.List;
    24 import java.util.Map;
     24import java.util.Set;
    2525
    2626import javax.swing.JButton;
     
    4646import org.openstreetmap.josm.data.Bounds;
    4747import org.openstreetmap.josm.data.projection.Projection;
     48import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;
    4849import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    4950import org.openstreetmap.josm.tools.GBC;
     
    5556import org.xml.sax.SAXException;
    5657
     58
    5759public class AddWMSLayerPanel extends JPanel {
    5860    private List<LayerDetails> selectedLayers;
     
    6870
    6971    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     }
    7772
    7873    public AddWMSLayerPanel() {
     
    280275        Element capabilityElem = getChild(document.getDocumentElement(), "Capability");
    281276        List<Element> children = getChildren(capabilityElem, "Layer");
    282         List<LayerDetails> layers = parseLayers(children);
     277        List<LayerDetails> layers = parseLayers(children, new HashSet<String>());
    283278
    284279        updateTreeList(layers);
     
    298293    }
    299294
    300     private List<LayerDetails> parseLayers(List<Element> children) {
     295    private List<LayerDetails> parseLayers(List<Element> children, Set<String> parentCrs) {
    301296        List<LayerDetails> details = new LinkedList<LayerDetails>();
    302297        for (Element element : children) {
    303             details.add(parseLayer(element));
     298            details.add(parseLayer(element, parentCrs));
    304299        }
    305300        return details;
    306301    }
    307302
    308     private LayerDetails parseLayer(Element element) {
     303    private LayerDetails parseLayer(Element element, Set<String> parentCrs) {
    309304        String name = getChildContent(element, "Title", null, null);
    310305        String ident = getChildContent(element, "Name", null, null);
    311306
    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
    314313        // I think CRS and SRS are the same at this point
    315314        List<Element> crsChildren = getChildren(element, "CRS");
     
    320319                String upperCase = crs.trim().toUpperCase();
    321320                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);
    324328        }
    325329
     
    346350
    347351        List<Element> layerChildren = getChildren(element, "Layer");
    348         List<LayerDetails> childLayers = parseLayers(layerChildren);
     352        List<LayerDetails> childLayers = parseLayers(layerChildren, crsList);
    349353
    350354        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;
    351366    }
    352367
     
    417432        private String name;
    418433        private String ident;
    419         private List<String> crsList;
     434        private Set<String> crsList;
    420435        private List<LayerDetails> children;
    421436        private Bounds bounds;
    422437        private boolean supported;
    423438
    424         public LayerDetails(String name, String ident, List<String> crsList,
     439        public LayerDetails(String name, String ident, Set<String> crsList,
    425440                boolean supportedLayer, Bounds bounds,
    426441                List<LayerDetails> childLayers) {
Note: See TracChangeset for help on using the changeset viewer.