OpenLayers OpenLayers

Changeset 5615

Show
Ignore:
Timestamp:
01/01/08 13:09:16 (8 months ago)
Author:
tschaub
Message:

partial update to wmc parsers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/wmc/examples/wmc.html

    r5565 r5615  
    4242 
    4343        } 
    44         var output = document.getElementById('output'); 
    4544             
    4645    </script> 
  • sandbox/tschaub/wmc/lib/OpenLayers.js

    r5565 r5615  
    183183            "OpenLayers/Format/GeoJSON.js", 
    184184            "OpenLayers/Format/WMC.js", 
     185            "OpenLayers/Format/WMC/v1.js", 
    185186            "OpenLayers/Format/WMC/v1_0_0.js", 
    186187            "OpenLayers/Format/WMC/v1_1_0.js", 
  • sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC.js

    r5565 r5615  
    2121     */ 
    2222    version: null, 
     23     
     24    /** 
     25     * Property: parser 
     26     * {Object} Instance of the versioned parser.  Cached for multiple read and 
     27     *     write calls of the same version. 
     28     */ 
     29    parser: null, 
    2330 
    2431    /** 
     
    5865            } 
    5966        } 
    60         var format = OpenLayers.Format.WMC[ 
    61             "v" + version.replace(/\./g, "_") 
    62         ]; 
    63         if(!format) { 
    64             throw "Can't find a WMS capabilities parser for version " + version; 
     67        if(!this.parser || this.parser.VERSION != version) { 
     68            var format = OpenLayers.Format.WMC[ 
     69                "v" + version.replace(/\./g, "_") 
     70            ]; 
     71            if(!format) { 
     72                throw "Can't find a WMS capabilities parser for version " + 
     73                      version; 
     74            } 
     75            this.parser = new format(this.options); 
    6576        } 
    66         var parser = new format(this.options); 
    67         var context = parser.read(data); 
     77        var context = this.parser.read(data); 
    6878        return context; 
    6979    }, 
    7080     
     81    /** 
     82     * Method: contextToMap 
     83     * Create a map given a context object. 
     84     * 
     85     * Parameters: 
     86     * context - {Object} The context object. 
     87     * id - {String | Element} The dom element or element id that will contain 
     88     *     the map. 
     89     * options - {Object} 
     90     * 
     91     * Returns: 
     92     * {<OpenLayers.Map>} A map based on the context object. 
     93     */ 
     94    contextToMap: function(context, id, options) { 
     95    }, 
     96 
     97    /** 
     98     * APIMethod: write 
     99     * Write a WMC document given a map. 
     100     * 
     101     * Parameters: 
     102     * obj - {<OpenLayers.Map> | Object} A map or context object. 
     103     * 
     104     * Returns: 
     105     * {String} A WMC document string. 
     106     */ 
     107    write: function(obj) { 
     108        if(obj.CLASS_NAME == "OpenLayers.Map") { 
     109            obj = this.mapToContext(obj); 
     110        } 
     111        var version = this.version || this.defaultVersion; 
     112        if(!this.parser || this.parser.VERSION != version) { 
     113            var format = OpenLayers.Format.WMC[ 
     114                "v" + version.replace(/\./g, "_") 
     115            ]; 
     116            if(!format) { 
     117                throw "Can't find a WMS capabilities parser for version " + 
     118                      version; 
     119            } 
     120            this.parser = new format(this.options); 
     121        } 
     122        var wmc = this.parser.write(obj); 
     123        return wmc; 
     124    }, 
     125     
     126    /** 
     127     * Method: mapToContext 
     128     * Create a context object given a map. 
     129     * 
     130     * Parameters: 
     131     * map - {<OpenLayers.Map>} The map. 
     132     * 
     133     * Returns: 
     134     * {Object} A context object. 
     135     */ 
     136    mapToContext: function(map) { 
     137        var context = {}; 
     138    }, 
     139 
    71140    CLASS_NAME: "OpenLayers.Format.WMC"  
    72141 
  • sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_0_0.js

    r5565 r5615  
    66 *  
    77 * Inherits from: 
    8  *  - <OpenLayers.Format.WMC
     8 *  - <OpenLayers.Format.WMC.v1
    99 */ 
    1010OpenLayers.Format.WMC.v1_0_0 = OpenLayers.Class( 
    11     OpenLayers.Format.WMC, { 
     11    OpenLayers.Format.WMC.v1, { 
    1212     
    1313    /** 
     14     * Constant: VERSION 
     15     * {String} 1.0.0 
     16     */ 
     17    VERSION: "1.0.0", 
     18 
     19    /** 
    1420     * Constructor: OpenLayers.Format.WMC.v1_0_0 
    15      * Create a new parser for WMC version 1.0. 
     21     * Instances of this class are not created directly.  Use the 
     22     *     <OpenLayers.Format.WMC> constructor instead. 
    1623     * 
    1724     * Parameters: 
     
    2027     */ 
    2128    initialize: function(options) { 
    22         OpenLayers.Format.WMC.prototype.initialize.apply( 
     29        OpenLayers.Format.WMC.v1.prototype.initialize.apply( 
    2330            this, [options] 
    2431        ); 
    2532    }, 
    2633 
    27     /** 
    28      * APIMethod: read 
    29      * Read capabilities data from a string, and return a list of layers.  
    30      *  
    31      * Parameters:  
    32      * data - {String} or {DOMElement} data to read/parse. 
    33      * 
    34      * Returns: 
    35      * {Array} List of named layers. 
    36      */ 
    37     read: function(data) { 
    38         if(typeof data == "string") { 
    39             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
    40         } 
    41         var root = data.documentElement; 
    42         var context = { 
    43             version: root.getAttribute("version") 
    44         }; 
    45         this.runChildNodes(context, root); 
    46         return context; 
    47     }, 
    48      
    49     /** 
    50      * Method: runChildNodes 
    51      */ 
    52     runChildNodes: function(obj, node) { 
    53         var children = node.childNodes; 
    54         var childNode, processor; 
    55         for(var i=0; i<children.length; ++i) { 
    56             childNode = children[i]; 
    57             if(childNode.nodeType == 1) { 
    58                 processor = this["read" + childNode.nodeName]; 
    59                 if(processor) { 
    60                     processor.apply(this, [obj, childNode]); 
    61                 } 
    62             } 
    63         } 
    64     }, 
    65      
    66     /** 
    67      * Method: readGeneral 
    68      */ 
    69     readGeneral: function(context, node) { 
    70         this.runChildNodes(context, node); 
    71     }, 
    72      
    73     /** 
    74      * Method: readBoundingBox 
    75      */ 
    76     readBoundingBox: function(context, node) { 
    77         context.srs = node.getAttribute("SRS"); 
    78         context.bounds = new OpenLayers.Bounds( 
    79             parseFloat(node.getAttribute("minx")), 
    80             parseFloat(node.getAttribute("miny")), 
    81             parseFloat(node.getAttribute("maxx")), 
    82             parseFloat(node.getAttribute("maxy")) 
    83         ); 
    84     }, 
    85      
    86     /** 
    87      * Method: readLayerList 
    88      */ 
    89     readLayerList: function(context, node) { 
    90         context.layers = []; 
    91         this.runChildNodes(context, node); 
    92     }, 
    93      
    94     /** 
    95      * Method: readLayer 
    96      */ 
    97     readLayer: function(context, node) { 
    98         var layerInfo = { 
    99             visibility: (node.getAttribute("hidden") != "1"), 
    100             queryable: (node.getAttribute("queryable") == "1"), 
    101             formats: [], 
    102             styles: [] 
    103         }; 
    104         this.runChildNodes(layerInfo, node); 
    105         var layer = new OpenLayers.Layer.WMS( 
    106             layerInfo.title, 
    107             layerInfo.href, 
    108             { 
    109                 layers: layerInfo.name, 
    110                 styles: (layerInfo.currentStyle) ? layerInfo.currentStyle.name : "", 
    111                 format: layerInfo.currentFormat, 
    112                 version: layerInfo.version 
    113                  
    114             } 
    115         ); 
    116         context.layers.push(layer); 
    117     }, 
    118      
    119     /** 
    120      * Method: readServer 
    121      */ 
    122     readServer: function(layerInfo, node) { 
    123         layerInfo.version = node.getAttribute("version"); 
    124         this.runChildNodes(layerInfo, node); 
    125     }, 
    126  
    127     /** 
    128      * Method: readFormatList 
    129      */ 
    130     readFormatList: function(layerInfo, node) { 
    131         this.runChildNodes(layerInfo, node); 
    132     }, 
    133  
    134     /** 
    135      * Method: readFormat 
    136      */ 
    137     readFormat: function(layerInfo, node) { 
    138         var format = this.getChildValue(node) 
    139         layerInfo.formats.push(format); 
    140         if(node.getAttribute("current") == "1") { 
    141             layerInfo.currentFormat = format; 
    142         } 
    143     }, 
    144      
    145     /** 
    146      * Method: readStyleList 
    147      */ 
    148     readStyleList: function(layerInfo, node) { 
    149         this.runChildNodes(layerInfo, node); 
    150     }, 
    151  
    152     /** 
    153      * Method: readStyle 
    154      */ 
    155     readStyle: function(layerInfo, node) { 
    156         var style = {}; 
    157         this.runChildNodes(style, node); 
    158         if(node.getAttribute("current") == "1") { 
    159             layerInfo.currentStyle = style; 
    160         } 
    161         layerInfo.styles.push(style); 
    162     }, 
    163  
    164     /** 
    165      * Method: readOnlineResource 
    166      */ 
    167     readOnlineResource: function(obj, node) { 
    168         obj.href = this.getAttributeNS( 
    169             node, "http://www.w3.org/1999/xlink", "href" 
    170         ); 
    171     }, 
    172      
    173     /** 
    174      * Method: readName 
    175      */ 
    176     readName: function(obj, node) { 
    177         var name = this.getChildValue(node); 
    178         if(name) { 
    179             obj.name = name; 
    180         } 
    181     }, 
    182  
    183     /** 
    184      * Method: readTitle 
    185      */ 
    186     readTitle: function(obj, node) { 
    187         var title = this.getChildValue(node); 
    188         if(title) { 
    189             obj.title = title; 
    190         } 
    191     }, 
    192  
    193     /** 
    194      * Method: readAbstract 
    195      */ 
    196     readAbstract: function(obj, node) { 
    197         var abst = this.getChildValue(node); 
    198         if(abst) { 
    199             obj["abstract"] = abst; 
    200         } 
    201     }, 
    202      
    203     /** 
    204      * Method: readLatLonBoundingBox 
    205      */ 
    206     readLatLonBoundingBox: function(layer, node) { 
    207         layer.llbbox = [ 
    208             parseFloat(node.getAttribute("minx")), 
    209             parseFloat(node.getAttribute("miny")), 
    210             parseFloat(node.getAttribute("maxx")), 
    211             parseFloat(node.getAttribute("maxy")) 
    212         ]; 
    213     }, 
    214  
    215     /** 
    216      * Method: readLegendURL 
    217      */ 
    218     readLegendURL: function(style, node) { 
    219         var legend = { 
    220             width: node.getAttribute('width'), 
    221             height: node.getAttribute('height') 
    222         }; 
    223         var links = node.getElementsByTagName("OnlineResource"); 
    224         if(links.length > 0) { 
    225             this.readOnlineResource(legend, links[0]); 
    226         } 
    227         style.legend = legend; 
    228     }, 
    229      
    230  
    23134    CLASS_NAME: "OpenLayers.Format.WMC.v1_0_0"  
    23235 
  • sandbox/tschaub/wmc/lib/OpenLayers/Format/WMC/v1_1_0.js

    r5565 r5615  
    44 * Class: OpenLayers.Format.WMC.v1_1_0 
    55 * Read and write WMC version 1.1.0. 
     6 * 
     7 * Differences between 1.1.0 and 1.0.0: 
     8 *     - 1.1.0 Layers have optional sld:MinScaleDenominator and 
     9 *       sld:MaxScaleDenominator 
    610 *  
    711 * Inherits from: 
    8  *  - <OpenLayers.Format.WMC
     12 *  - <OpenLayers.Format.WMC.v1
    913 */ 
    1014OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class( 
    11     OpenLayers.Format.WMC.v1_0_0, { 
     15    OpenLayers.Format.WMC.v1, { 
    1216     
    1317    /** 
     18     * Constant: VERSION 
     19     * {String} 1.1.0 
     20     */ 
     21    VERSION: "1.1.0", 
     22 
     23    /** 
    1424     * Constructor: OpenLayers.Format.WMC.v1_1_0 
    15      * Create a new parser for WMS capabilities version 1.1.0. 
     25     * Instances of this class are not created directly.  Use the 
     26     *     <OpenLayers.Format.WMC> constructor instead. 
    1627     * 
    1728     * Parameters: 
     
    2031     */ 
    2132    initialize: function(options) { 
    22         OpenLayers.Format.WMC.v1_0_0.prototype.initialize.apply( 
     33        OpenLayers.Format.WMC.v1.prototype.initialize.apply( 
    2334            this, [options] 
    2435        );