OpenLayers OpenLayers

Ticket #1176: Capabilities.patch

File Capabilities.patch, 40.2 kB (added by openlayers, 2 years ago)
  • Format/WMSCapabilities/v1_1_1.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/WMSCapabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WMSCapabilities.v1_1_1 
     5 * Read WMS Capabilities version 1.1.1. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.WMSCapabilities> 
     9 */ 
     10OpenLayers.Format.WMSCapabilities.v1_1_1 = OpenLayers.Class( 
     11    OpenLayers.Format.WMSCapabilities, { 
     12     
     13    /** 
     14     * Constant: VERSION 
     15     * {String} 1.1.1 
     16     */ 
     17    VERSION: "1.1.1", 
     18     
     19    /** 
     20     * Constructor: OpenLayers.Format.WMSCapabilities.v1_1_1 
     21     * Create a new parser for WMS capabilities version 1_1_1. 
     22     * 
     23     * Parameters: 
     24     * options - {Object} An optional object whose properties will be set on 
     25     *     this instance. 
     26     */ 
     27    initialize: function(options) { 
     28        OpenLayers.Format.WMSCapabilities.prototype.initialize.apply( 
     29            this, [options] 
     30        ); 
     31    }, 
     32 
     33    /** 
     34     * APIMethod: read 
     35     * Read capabilities data from a string, and return a list of layers.  
     36     *  
     37     * Parameters:  
     38     * data - {String} or {DOMElement} data to read/parse. 
     39     * 
     40     * Returns: 
     41     * {Array} List of named layers. 
     42     */ 
     43    read: function(data) { 
     44        if(typeof data == "string") { 
     45            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
     46        } 
     47        var capabilities = {}; 
     48        var root = data.documentElement; 
     49        this.runChildNodes(capabilities, root); 
     50        return capabilities; 
     51    }, 
     52 
     53     
     54    /** 
     55     * Method: read_wms_SRS 
     56     */ 
     57    read_wms_SRS: function(obj, node) { 
     58        var srs = this.getChildValue(node); 
     59        if(srs) { 
     60            srs = srs.split(' '); 
     61             
     62            // do not duplicate values 
     63            for(var i=0; i<srs.length; ++i) { 
     64                var test = false; 
     65                for(var j=0; j<obj.srs.length; ++j) 
     66                    if(srs[i] == obj.srs[j]) { 
     67                        test = true; 
     68                        break; 
     69                    } 
     70                if(!test) 
     71                    obj.srs.push(srs[i]); 
     72            } 
     73        } 
     74    }, 
     75 
     76     
     77    /** 
     78     * Method: read_wms_BoundingBox 
     79     */ 
     80    read_wms_BoundingBox: function(layer, node) { 
     81        var srs = node.getAttribute("SRS"); 
     82         
     83        layer.bbox[srs] = new OpenLayers.Bounds( 
     84            parseFloat(node.getAttribute("minx")), 
     85            parseFloat(node.getAttribute("miny")), 
     86            parseFloat(node.getAttribute("maxx")), 
     87            parseFloat(node.getAttribute("maxy")) 
     88        ); 
     89    }, 
     90 
     91    /** 
     92     * Method: read_wms_LatLonBoundingBox 
     93     */ 
     94    read_wms_LatLonBoundingBox: function(layer, node) { 
     95        layer.bbox["default"] = new OpenLayers.Bounds( 
     96            parseFloat(node.getAttribute("minx")), 
     97            parseFloat(node.getAttribute("miny")), 
     98            parseFloat(node.getAttribute("maxx")), 
     99            parseFloat(node.getAttribute("maxy")) 
     100        ); 
     101    }, 
     102     
     103    /** 
     104     * Method: processScalehint 
     105     */ 
     106    read_wms_ScaleHint: function(obj, node) { 
     107        obj.scaleHint = { 
     108            min: parseFloat(node.getAttribute('min')), 
     109            max: parseFloat(node.getAttribute('max')) 
     110        } 
     111    }, 
     112     
     113    CLASS_NAME: "OpenLayers.Format.WMSCapabilities.v1_1_1"  
     114 
     115}); 
  • Format/WMSCapabilities/v1_3_0.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/WMSCapabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WMSCapabilities.v1_3_0 
     5 * Read WMS Capabilities version 1.3.0. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.WMSCapabilities> 
     9 */ 
     10OpenLayers.Format.WMSCapabilities.v1_3_0 = OpenLayers.Class( 
     11    OpenLayers.Format.WMSCapabilities, { 
     12     
     13    /** 
     14     * Constant: VERSION 
     15     * {String} 1.3.0 
     16     */ 
     17    VERSION: "1.3.0", 
     18     
     19    /** 
     20     * Constructor: OpenLayers.Format.WMSCapabilities.v1_3_0 
     21     * Create a new parser for WMS capabilities version 1_3_0. 
     22     * 
     23     * Parameters: 
     24     * options - {Object} An optional object whose properties will be set on 
     25     *     this instance. 
     26     */ 
     27    initialize: function(options) { 
     28        OpenLayers.Format.WMSCapabilities.prototype.initialize.apply( 
     29            this, [options] 
     30        ); 
     31    }, 
     32 
     33    /** 
     34     * APIMethod: read 
     35     * Read capabilities data from a string, and return a list of layers.  
     36     *  
     37     * Parameters:  
     38     * data - {String} or {DOMElement} data to read/parse. 
     39     * 
     40     * Returns: 
     41     * {Array} List of named layers. 
     42     */ 
     43    read: function(data) { 
     44        if(typeof data == "string") { 
     45            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
     46        } 
     47        var capabilities = {}; 
     48        var root = data.documentElement; 
     49        this.runChildNodes(capabilities, root); 
     50        return capabilities; 
     51    }, 
     52 
     53 
     54    /** 
     55     * Method: read_wms_CRS 
     56     */ 
     57    read_wms_CRS: function(obj, node) { 
     58        var crs = this.getChildValue(node); 
     59        if(crs) { 
     60            crs = crs.split(' '); 
     61             
     62            // do not duplicate values 
     63            for(var i=0; i<crs.length; ++i) { 
     64                var test = false; 
     65                for(var j=0; j<obj.srs.length; ++j) 
     66                    if(crs[i] == obj.srs[j]) { 
     67                        test = true; 
     68                        break; 
     69                    } 
     70                if(!test) 
     71                    obj.srs.push(crs[i]); 
     72            } 
     73        } 
     74    }, 
     75     
     76     
     77    /** 
     78     * Method: read_wms_BoundingBox 
     79     */ 
     80    read_wms_BoundingBox: function(layer, node) { 
     81        var srs = node.getAttribute("CRS"); 
     82         
     83        layer.bbox[srs] = new OpenLayers.Bounds( 
     84            parseFloat(node.getAttribute("minx")), 
     85            parseFloat(node.getAttribute("miny")), 
     86            parseFloat(node.getAttribute("maxx")), 
     87            parseFloat(node.getAttribute("maxy")) 
     88        ); 
     89    }, 
     90     
     91    /** 
     92     * Method: read_wms_EX_GeographicBoundingBox 
     93     */ 
     94    read_wms_EX_GeographicBoundingBox: function(layer, node) { 
     95        var children = node.childNodes; 
     96        var minx, miny, maxx, maxy; 
     97        for(var i=0; i<children.length; ++i) { 
     98            childNode = children[i]; 
     99            if(childNode.nodeType == 1) { 
     100                if(childNode.nodeName == "westBoundLongitude") 
     101                    minx = this.getChildValue(childNode); 
     102                if(childNode.nodeName == "southBoundLatitude") 
     103                    miny = this.getChildValue(childNode); 
     104                if(childNode.nodeName == "eastBoundLongitude") 
     105                    maxx = this.getChildValue(childNode); 
     106                if(childNode.nodeName == "northBoundLatitude") 
     107                    maxy = this.getChildValue(childNode); 
     108            } 
     109        } 
     110 
     111        layer.bbox["default"] = new OpenLayers.Bounds(minx, miny, maxx, maxy); 
     112    }, 
     113     
     114    CLASS_NAME: "OpenLayers.Format.WMSCapabilities.v1_3_0"  
     115 
     116}); 
  • Format/WFSCapabilities.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/Capabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WFSCapabilities 
     5 * Read WFS Capabilities. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.Capabilities> 
     9 */ 
     10OpenLayers.Format.WFSCapabilities = OpenLayers.Class(OpenLayers.Format.Capabilities, { 
     11     
     12    /** 
     13     * Constant: PROTOCOL 
     14     * {String} Protocol 
     15     */ 
     16    PROTOCOL: 'WFS', 
     17     
     18    /** 
     19     * APIProperty: defaultVersion 
     20     * {String} Version number to assume if none found.  Default is "1.1.0". 
     21     */ 
     22    defaultVersion: "1.1.0", 
     23     
     24    /** 
     25     * Property: defaultPrefix 
     26     */ 
     27    defaultPrefix: "ows", 
     28     
     29    /** 
     30     * Constructor: OpenLayers.Format.WFSCapabilities 
     31     * Create a new parser for WFS capabilities. 
     32     * 
     33     * Parameters: 
     34     * options - {Object} An optional object whose properties will be set on 
     35     *     this instance. 
     36     */ 
     37    initialize: function(options) { 
     38        OpenLayers.Format.Capabilities.prototype.initialize.apply(this, [options]); 
     39        this.options = options; 
     40    }, 
     41 
     42 
     43 
     44    /************************************ 
     45     *                                  * 
     46     *           WFS namespace          * 
     47     *                                  * 
     48     ************************************/ 
     49 
     50    /** 
     51     * Method: read_wfs_FeatureTypeList 
     52     */ 
     53    read_wfs_FeatureTypeList: function(obj, node) { 
     54        obj.featureTypeList = []; 
     55        this.runChildNodes(obj.featureTypeList, node); 
     56    }, 
     57 
     58    /** 
     59     * Method: read_wfs_FeatureType 
     60     */ 
     61    read_wfs_FeatureType: function(array, node) { 
     62        var featureType = { 
     63            srs: [], 
     64            bbox: {}, 
     65            formats: [] 
     66        }; 
     67        this.runChildNodes(featureType, node); 
     68        array.push(featureType); 
     69    }, 
     70 
     71    /** 
     72     * Method: read_wfs_Name 
     73     */ 
     74    read_wfs_Name: function(obj, node) { 
     75        var n = this.getChildValue(node); 
     76        if(n) 
     77            obj["name"] = n; 
     78    }, 
     79 
     80    /** 
     81     * Method: read_wfs_Title 
     82     */ 
     83    read_wfs_Title: function(obj, node) { 
     84        var title = this.getChildValue(node); 
     85        if(title) 
     86            obj.title = title; 
     87    }, 
     88 
     89    /** 
     90     * Method: read_wfs_Abstract 
     91     */ 
     92    read_wfs_Abstract: function(obj, node) { 
     93        var abst = this.getChildValue(node); 
     94        if(abst) { 
     95            obj["abstract"] = abst; 
     96        } 
     97    }, 
     98 
     99    /** 
     100     * Method: read_wfs_DefaultSRS 
     101     */ 
     102    read_wfs_DefaultSRS: function(obj, node) { 
     103        var srs = this.getChildValue(node); 
     104        if(srs) 
     105            obj["defaultSrs"] = srs; 
     106    }, 
     107 
     108    /** 
     109     * Method: read_wfs_DefaultSRS 
     110     */ 
     111    read_wfs_OtherSRS: function(obj, node) { 
     112        var srs = this.getChildValue(node); 
     113        if(srs) 
     114            obj.srs.push(srs); 
     115    }, 
     116 
     117    /** 
     118     * Method: read_wfs_OutputFormats 
     119     */ 
     120    read_wfs_OutputFormats: function(obj, node) { 
     121        this.runChildNodes(obj, node); 
     122    }, 
     123 
     124    /** 
     125     * Method: read_wfs_Format 
     126     */ 
     127    read_wfs_Format: function(obj, node) { 
     128        var formats = this.getChildValue(node).split(';'); 
     129        for(var i=0; i<formats.length; ++i) { 
     130            var format = formats[i].replace(/\s*/g,"");  // delete spaces 
     131            format = format.replace(/subtype=/,"");     // delete 'subtype=' 
     132            obj.formats.push(format); 
     133        } 
     134    }, 
     135 
     136    /** 
     137     * Method: read_wfs_ServesGMLObjectTypeList 
     138     */ 
     139    read_wfs_ServesGMLObjectTypeList: function(obj, node) { 
     140        obj.serversGMLObjectTypeList = []; 
     141        this.runChildNodes(obj.serversGMLObjectTypeList, node); 
     142    }, 
     143     
     144    /** 
     145     * Method: read_wfs_GMLObjectType 
     146     */ 
     147    read_wfs_GMLObjectType: function(array, node) { 
     148        var GMLObjectType = { 
     149            formats: [] 
     150        }; 
     151        this.runChildNodes(GMLObjectType, node); 
     152        array.push(GMLObjectType); 
     153    }, 
     154     
     155    /** 
     156     * Method: read_wfs_SupportsGMLObjectTypeList 
     157     */ 
     158    read_wfs_SupportsGMLObjectTypeList: function(obj, node) { 
     159        obj.supportsGMLObjectTypeList = []; 
     160        this.runChildNodes(obj.supportsGMLObjectTypeList, node); 
     161    }, 
     162     
     163 
     164 
     165    /************************************ 
     166     *                                  * 
     167     *           OWS namespace          * 
     168     *                                  * 
     169     ************************************/ 
     170      
     171    /** 
     172     * Method: read_ows__ServiceIdentification 
     173     */ 
     174    read_ows_ServiceIdentification: function(obj, node) { 
     175        var service = {}; 
     176        this.runChildNodes(service, node); 
     177        obj.service = service; 
     178    }, 
     179 
     180    /** 
     181     * Method: read_ows_Title 
     182     */ 
     183    read_ows_Title: function(obj, node) { 
     184        var title = this.getChildValue(node); 
     185        if(title) { 
     186            obj.title = title; 
     187        } 
     188    }, 
     189     
     190    /** 
     191     * Method: read_ows_Abstract 
     192     */ 
     193    read_ows_Abstract: function(obj, node) { 
     194        var abst = this.getChildValue(node); 
     195        if(abst) { 
     196            obj["abstract"] = abst; 
     197        } 
     198    }, 
     199 
     200    /** 
     201     * Method: read_ows_Keywords 
     202     */ 
     203    read_ows_Keywords: function(obj, node) { 
     204        obj.keywords = []; 
     205        this.runChildNodes(obj, node); 
     206    }, 
     207 
     208    /** 
     209     * Method: read_ows_Keyword 
     210     */ 
     211    read_ows_Keyword: function(obj, node) { 
     212        var keyword = this.getChildValue(node); 
     213        obj.keywords.push(keyword); 
     214    }, 
     215 
     216 
     217    /** 
     218     * Method: read_ows_OperationsMetadata 
     219     */ 
     220    read_ows_OperationsMetadata: function(obj, node) { 
     221        var requests = {}; 
     222        this.runChildNodes(requests, node); 
     223        obj.requests = requests; 
     224    },     
     225 
     226    /** 
     227     * Method: read_ows_Operation 
     228     */ 
     229    read_ows_Operation: function(operations, node) { 
     230        var operation = {}; 
     231        var operationName = node.getAttribute("name"); 
     232        this.runChildNodes(operation, node); 
     233        operations[operationName] = operation; 
     234    }, 
     235 
     236    /** 
     237     * Method: read_ows_Parameter 
     238     */ 
     239    read_ows_Parameter: function(operation, node) { 
     240        var parameter = []; 
     241        var parameterName = node.getAttribute("name"); 
     242        this.runChildNodes(parameter, node); 
     243         
     244        if(!("parameters" in operation)) 
     245            operation["parameters"] = {}; 
     246        operation.parameters[parameterName] = parameter; 
     247    }, 
     248 
     249    /** 
     250     * Method: read_ows_Value 
     251     */ 
     252    read_ows_Value: function(parameter, node) { 
     253        var format = this.getChildValue(node); 
     254        parameter.push(format); 
     255    }, 
     256 
     257    /** 
     258     * Method: read_ows_DCP 
     259     */ 
     260    read_ows_DCP: function(operation, node) { 
     261        this.runChildNodes(operation, node); 
     262    }, 
     263 
     264    /** 
     265     * Method: read_ows_HTTP 
     266     */ 
     267    read_ows_HTTP: function(operation, node) { 
     268        this.runChildNodes(operation, node); 
     269    }, 
     270 
     271    /** 
     272     * Method: read_ows_Get 
     273     */ 
     274    read_ows_Get: function(operation, node) { 
     275        this.readMethod(operation, "GET", node); 
     276    }, 
     277 
     278    /** 
     279     * Method: read_ows_Post 
     280     */ 
     281    read_ows_Post: function(operation, node) { 
     282        this.readMethod(operation, "POST", node); 
     283    }, 
     284     
     285    readMethod: function(operation, method, node) { 
     286        var href = this.getAttributeNS( 
     287            node, "http://www.w3.org/1999/xlink", "href" 
     288        ); 
     289         
     290        if(href.indexOf("?") < 0) { 
     291            href += "?"; 
     292        } 
     293        else if(href.lastIndexOf("?", href.length-1) != href.length-1 
     294                && href.lastIndexOf("&", href.length-1) != href.length-1) { 
     295            href += "&"; 
     296        } 
     297         
     298        operation[method] = href; 
     299    }, 
     300 
     301 
     302 
     303 
     304 
     305    /************************************ 
     306     *                                  * 
     307     *           ogc namespace          * 
     308     *                                  * 
     309     ************************************/ 
     310 
     311    /** 
     312     * Method: read_ogc_Filter_Capabilities 
     313     */ 
     314    read_ogc_Filter_Capabilities: function(obj, node) { 
     315        obj.filter = {}; 
     316        this.runChildNodes(obj.filter, node); 
     317    }, 
     318 
     319    /* 
     320     * Method: read_ogc_Spatial_Capabilities 
     321     */ 
     322    read_ogc_Spatial_Capabilities: function(obj, node) { 
     323        obj.spatial = {}; 
     324        this.runChildNodes(obj.spatial, node); 
     325    }, 
     326 
     327    /* 
     328     * Method: read_ogc_GeometryOperands 
     329     */ 
     330    read_ogc_GeometryOperands: function(obj, node) { 
     331        obj.geometryOperands = []; 
     332        this.runChildNodes(obj.geometryOperands, node); 
     333    }, 
     334 
     335    /* 
     336     * Method: read_ogc_GeometryOperand 
     337     */ 
     338    read_ogc_GeometryOperand: function(array, node) { 
     339        var operand = this.getChildValue(node); 
     340        if(operand) 
     341            array.push(operand); 
     342    }, 
     343 
     344    /* 
     345     * Method: read_ogc_Capabilities 
     346     */ 
     347    read_ogc_Scalar_Capabilities: function(obj, node) { 
     348        obj.scalar = {}; 
     349        this.runChildNodes(obj.scalar, node); 
     350    }, 
     351 
     352    /* 
     353     * Method: read_ogc_Functions 
     354     */ 
     355    read_ogc_Functions: function(obj, node) { 
     356        this.runChildNodes(obj, node); 
     357    }, 
     358 
     359 
     360    CLASS_NAME: "OpenLayers.Format.WFSCapabilities"  
     361}); 
  • Format/WMSCapabilities.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/Capabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WMSCapabilities 
     5 * Read WMS Capabilities. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.Capabilities> 
     9 */ 
     10OpenLayers.Format.WMSCapabilities = OpenLayers.Class(OpenLayers.Format.Capabilities, { 
     11     
     12    /** 
     13     * Constant: PROTOCOL 
     14     * {String} Protocol 
     15     */ 
     16    PROTOCOL: 'WMS', 
     17     
     18    /** 
     19     * APIProperty: defaultVersion 
     20     * {String} Version number to assume if none found.  Default is "1.1.1". 
     21     */ 
     22    defaultVersion: "1.1.1", 
     23     
     24    /** 
     25     * Property: defaultPrefix 
     26     */ 
     27    defaultPrefix: "wms", 
     28     
     29    /** 
     30     * Constructor: OpenLayers.Format.WMSCapabilities 
     31     * Create a new parser for WMS capabilities. 
     32     * 
     33     * Parameters: 
     34     * options - {Object} An optional object whose properties will be set on 
     35     *     this instance. 
     36     */ 
     37    initialize: function(options) { 
     38        OpenLayers.Format.Capabilities.prototype.initialize.apply(this, [options]); 
     39        this.options = options; 
     40    }, 
     41     
     42    /** 
     43     * Method: read_wms_Service 
     44     */ 
     45    read_wms_Service: function(capabilities, node) { 
     46        var service = {}; 
     47        this.runChildNodes(service, node); 
     48        capabilities.service = service; 
     49    }, 
     50 
     51    /** 
     52     * Method: read_wms_Name 
     53     */ 
     54    read_wms_Name: function(obj, node) { 
     55        var id = this.getChildValue(node); 
     56        if(id) { 
     57            obj["name"] = id; 
     58        } 
     59    }, 
     60 
     61    /** 
     62     * Method: read_wms_Abstract 
     63     */ 
     64    read_wms_Abstract: function(obj, node) { 
     65        var abst = this.getChildValue(node); 
     66        if(abst) { 
     67            obj["abstract"] = abst; 
     68        } 
     69    }, 
     70 
     71    /** 
     72     * Method: read_wms_KeywordList 
     73     */ 
     74    read_wms_KeywordList: function(obj, node) { 
     75        obj.keywords = []; 
     76        this.runChildNodes(obj, node); 
     77    }, 
     78 
     79    /** 
     80     * Method: read_wms_Keyword 
     81     */ 
     82    read_wms_Keyword: function(obj, node) { 
     83        var keyword = this.getChildValue(node); 
     84        obj.keywords.push(keyword); 
     85    }, 
     86 
     87 
     88    /** 
     89     * Method: read_wms_Capability 
     90     */ 
     91    read_wms_Capability: function(capabilities, node) { 
     92        var capability = { 
     93            layers: [] 
     94        }; 
     95        this.runChildNodes(capability, node); 
     96        capabilities.capability = capability; 
     97    }, 
     98     
     99    /** 
     100     * Method: read_wms_Request 
     101     */ 
     102    read_wms_Request: function(capabilities, node) { 
     103        var requests = {}; 
     104        this.runChildNodes(requests, node); 
     105        capabilities.requests = requests; 
     106    },     
     107 
     108    /** 
     109     * Method: read_wms_GetCapabilities 
     110     */ 
     111    read_wms_GetCapabilities: function(requests, node) { 
     112        var GetCapabilities = { 
     113            formats: [] 
     114        }; 
     115        this.runChildNodes(GetCapabilities, node); 
     116        requests.GetCapabilities = GetCapabilities; 
     117    }, 
     118 
     119    /** 
     120     * Method: read_wms_GetMap 
     121     */ 
     122    read_wms_GetMap: function(requests, node) { 
     123        var GetMap = { 
     124            formats: [] 
     125        }; 
     126        this.runChildNodes(GetMap, node); 
     127        requests.GetMap = GetMap; 
     128    }, 
     129 
     130    /** 
     131     * Method: read_wms_GetFeatureInfo 
     132     */ 
     133    read_wms_GetFeatureInfo: function(requests, node) { 
     134        var GetFeatureInfo = { 
     135            formats: [] 
     136        }; 
     137        this.runChildNodes(GetFeatureInfo, node); 
     138        requests.GetFeatureInfo = GetFeatureInfo; 
     139    }, 
     140     
     141    /** 
     142     * Method: read_wms_Format 
     143     */ 
     144    read_wms_Format: function(request, node) { 
     145        var format = this.getChildValue(node); 
     146        request.formats.push(format); 
     147    }, 
     148 
     149    /** 
     150     * Method: read_wms_DCPType 
     151     */ 
     152    read_wms_DCPType: function(request, node) { 
     153        this.runChildNodes(request, node); 
     154    }, 
     155 
     156    /** 
     157     * Method: read_wms_HTTP 
     158     */ 
     159    read_wms_HTTP: function(request, node) { 
     160        this.runChildNodes(request, node); 
     161    }, 
     162 
     163    /** 
     164     * Method: read_wms_Get 
     165     */ 
     166    read_wms_Get: function(request, node) { 
     167        this.readMethod(request, "GET", node); 
     168    }, 
     169 
     170    /** 
     171     * Method: read_wms_Post 
     172     */ 
     173    read_wms_Post: function(request, node) { 
     174        this.readMethod(request, "POST", node); 
     175    }, 
     176     
     177    readMethod: function(request, method, node) { 
     178        var children = node.childNodes; 
     179        for(var i=0; i<children.length; ++i) { 
     180            childNode = children[i]; 
     181            if(childNode.nodeType == 1) { 
     182                var href = this.getAttributeNS( 
     183                    childNode, "http://www.w3.org/1999/xlink", "href" 
     184                ); 
     185                 
     186                if(href.indexOf("?") < 0) { 
     187                    href += "?"; 
     188                } 
     189                else if(href.lastIndexOf("?", href.length-1) != href.length-1 
     190                        && href.lastIndexOf("&", href.length-1) != href.length-1) { 
     191                    href += "&"; 
     192                } 
     193                 
     194                request[method] = href; 
     195            } 
     196        } 
     197    }, 
     198     
     199     
     200    /** 
     201     * Method: read_wms_Layer 
     202     */ 
     203    read_wms_Layer: function(capability, node, parentLayer) { 
     204        var layer = { 
     205            styles: [], 
     206            bbox: {}, 
     207            srs: [] 
     208        }; 
     209         
     210        // deal with property inheritance 
     211        if(parentLayer) { 
     212            if("styles" in parentLayer) 
     213                layer.styles = layer.styles.concat(parentLayer.styles); 
     214            if("srs" in parentLayer) 
     215                layer.srs = layer.srs.concat(parentLayer.srs); 
     216            if("bbox" in parentLayer) 
     217                OpenLayers.Util.applyDefaults(layer.bbox, parentLayer.bbox); 
     218        } 
     219         
     220        // if the layer supports GetFeatureInfo request 
     221        if(node.getAttribute("queryable")) 
     222            layer.queryable = node.getAttribute("queryable") == "1"; 
     223        // this attribute can be inherited 
     224        else if(parentLayer && "queryable" in parentLayer) 
     225            layer.queryable = parentLayer.queryable; 
     226        else 
     227            layer.queryable = false; 
     228         
     229         
     230        var children = node.childNodes; 
     231        var childNode, processor, prefix, local; 
     232        for(var i=0, len=children.length; i<len; ++i) { 
     233            childNode = children[i]; 
     234            if(childNode.nodeType == 1) { 
     235                prefix = this.getNamespacePrefix(childNode.namespaceURI); 
     236                local = childNode.nodeName.split(":").pop(); 
     237                processor = this["read_" + prefix + "_" + local]; 
     238                if(processor) { 
     239                if(childNode.nodeName == "Layer") { 
     240                    processor.apply(this, [capability, childNode, layer]); 
     241                } else { 
     242                    processor.apply(this, [layer, childNode]); 
     243                } 
     244                } 
     245            } 
     246        } 
     247         
     248        if("name" in layer) { 
     249            var index = layer.name.indexOf(":"); 
     250            if(index > 0) { 
     251                layer.prefix = layer.name.substring(0, index); 
     252            } 
     253            capability.layers.push(layer); 
     254        } 
     255    }, 
     256     
     257    /** 
     258     * Method: read_wms_Title 
     259     */ 
     260    read_wms_Title: function(obj, node) { 
     261        var title = this.getChildValue(node); 
     262        if(title) { 
     263            obj.title = title; 
     264        } 
     265    }, 
     266     
     267    /** 
     268     * Method: read_wms_Style 
     269     */ 
     270    read_wms_Style: function(layer, node) { 
     271        var style = {}; 
     272        this.runChildNodes(style, node); 
     273        layer.styles.push(style); 
     274    }, 
     275 
     276    /** 
     277     * Method: read_wms_LegendURL 
     278     */ 
     279    read_wms_LegendURL: function(style, node) { 
     280        var legend = { 
     281            width: parseInt(node.getAttribute('width')), 
     282            height: parseInt(node.getAttribute('height')) 
     283        }; 
     284        // TODO 
     285        var links = node.getElementsByTagName("OnlineResource"); 
     286        if(links.length > 0) { 
     287            this.read_xlink_OnlineResource(legend, links[0]); 
     288        } 
     289        style.legend = legend; 
     290    }, 
     291     
     292    /** 
     293     * Method: read_xlink_OnlineResource 
     294     */ 
     295    read_xlink_OnlineResource: function(obj, node) { 
     296        obj.href = this.getAttributeNS( 
     297            node, "http://www.w3.org/1999/xlink", "href" 
     298        ); 
     299    }, 
     300     
     301    CLASS_NAME: "OpenLayers.Format.WMSCapabilities"  
     302 
     303}); 
  • Format/Capabilities.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/XML.js 
     3 * 
     4 * Class: OpenLayers.Format.Capabilities 
     5 * Read Capabilities. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.XML> 
     9 */ 
     10OpenLayers.Format.Capabilities = OpenLayers.Class(OpenLayers.Format.XML, { 
     11 
     12    /** 
     13     * APIProperty: version 
     14     * {String} Specify a version string if one is known. 
     15     */ 
     16    version: null, 
     17     
     18    /** 
     19     * APIProperty: protocol 
     20     * {String} Specify the protocol (WMS or WFS) 
     21     */ 
     22    protocol: null, 
     23     
     24    /** 
     25     * APIProperty: defaultProtocol 
     26     * {String} Protocol to assume if none found.  Default is "WMS". 
     27     */ 
     28    defaultProtocol: 'WMS', 
     29     
     30    /** 
     31     * Property: parser 
     32     * {Object} Instance of the versioned parser.  Cached for multiple read and 
     33     *     write calls of the same version. 
     34     */ 
     35    parser: null, 
     36     
     37    /** 
     38     * Property: namespaces 
     39     * {Object} Mapping of namespace aliases to namespace URIs. 
     40     */ 
     41    namespaces: { 
     42        ows: "http://www.opengis.net/ows", 
     43        wms: "http://www.opengis.net/wms", 
     44        wfs: "http://www.opengis.net/wfs", 
     45        gml: "http://www.opengis.net/gml", 
     46        ogc: "http://www.opengis.net/ogc", 
     47        xlink: "http://www.w3.org/1999/xlink", 
     48        xsi: "http://www.w3.org/2001/XMLSchema-instance" 
     49    }, 
     50     
     51    /** 
     52     * Constructor: OpenLayers.Format.Capabilities 
     53     * Create a new parser for capabilities. 
     54     * 
     55     * Parameters: 
     56     * options - {Object} An optional object whose properties will be set on 
     57     *     this instance. 
     58     */ 
     59    initialize: function(options) { 
     60        OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); 
     61        this.options = options; 
     62    }, 
     63 
     64    /** 
     65     * APIMethod: read 
     66     * Read capabilities data from a string, and return a list of layers.  
     67     *  
     68     * Parameters:  
     69     * data - {String} or {DOMElement} data to read/parse. 
     70     * 
     71     * Returns: 
     72     * {Array} List of named layers. TODO ! 
     73     */ 
     74    read: function(data) { 
     75        if(typeof data == "string") { 
     76            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
     77        } 
     78        var root = data.documentElement; 
     79        var version = this.version; 
     80        if(!version) { 
     81            version = root.getAttribute("version"); 
     82            if(!version) { 
     83                version = this.defaultVersion; 
     84            } 
     85        } 
     86        var protocol = this.protocol; 
     87        if(!this.protocol) { 
     88            var nodeName = root.nodeName.split(":").pop(); 
     89            if(nodeName == "WMT_MS_Capabilities") 
     90                protocol = "WMS"; 
     91            if(nodeName == "WMS_Capabilities") 
     92                protocol = "WMS"; 
     93            else if(nodeName == "WFS_Capabilities") 
     94                protocol = "WFS"; 
     95            else 
     96                protocol = this.defaultProtocol; 
     97        } 
     98         
     99        if(!this.parser || this.parser.VERSION != version || this.parser.PROTOCOL != protocol) { 
     100            var p_format = OpenLayers.Format[ 
     101                protocol + "Capabilities" 
     102            ]; 
     103            if(!p_format) { 
     104                throw "Can't find a capabilities parser for protocol " + protocol; 
     105            } 
     106             
     107            var format = p_format[ 
     108                "v" + version.replace(/\./g, "_") 
     109            ]; 
     110            if(!format) { 
     111                throw "Can't find a WMS capabilities parser for version " + version; 
     112            } 
     113            this.parser = new format(this.options); 
     114        } 
     115        var capabilities = this.parser.read(data); 
     116        return capabilities; 
     117    }, 
     118 
     119 
     120    /** 
     121     * Method: getNamespacePrefix 
     122     * Get the namespace prefix for a given uri from the <namespaces> object. 
     123     * 
     124     * Returns: 
     125     * {String} A namespace prefix or null if none found. 
     126     */ 
     127    getNamespacePrefix: function(uri) { 
     128        if(uri == null) { 
     129            return this.defaultPrefix; 
     130        } else { 
     131            var gotPrefix = false; 
     132            var prefix = null; 
     133            for(prefix in this.namespaces) { 
     134                if(this.namespaces[prefix] == uri) { 
     135                    gotPrefix = true; 
     136                    break; 
     137                } 
     138            } 
     139            if(!gotPrefix) { 
     140                prefix = null; 
     141            } 
     142            return prefix; 
     143        } 
     144    }, 
     145     
     146    /** 
     147     * Method: runChildNodes 
     148     */ 
     149    runChildNodes: function(obj, node) { 
     150        var children = node.childNodes; 
     151        var childNode, processor, prefix, local; 
     152        for(var i=0, len=children.length; i<len; ++i) { 
     153            childNode = children[i]; 
     154            if(childNode.nodeType == 1) { 
     155                prefix = this.getNamespacePrefix(childNode.namespaceURI); 
     156                local = childNode.nodeName.split(":").pop(); 
     157                processor = this["read_" + prefix + "_" + local]; 
     158                if(processor) { 
     159                    processor.apply(this, [obj, childNode]); 
     160                } else { 
     161                    window.console.log("no read_" + prefix + "_" + local); 
     162                } 
     163            } 
     164        } 
     165    }, 
     166 
     167     
     168    CLASS_NAME: "OpenLayers.Format.Capabilities"  
     169}); 
  • Format/WFSCapabilities/v1_0_0.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/WFSCapabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WFSCapabilities.v1_0_0 
     5 * Read WFS Capabilities version 1.0.0. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.WFSCapabilities> 
     9 */ 
     10OpenLayers.Format.WFSCapabilities.v1_0_0 = OpenLayers.Class( 
     11    OpenLayers.Format.WFSCapabilities, { 
     12     
     13    /** 
     14     * Constant: VERSION 
     15     * {String} 1.0.0 
     16     */ 
     17    VERSION: "1.0.0", 
     18     
     19    /** 
     20     * Constructor: OpenLayers.Format.WFSCapabilities.v1_0_0 
     21     * Create a new parser for WFS capabilities version 1_0_0. 
     22     * 
     23     * Parameters: 
     24     * options - {Object} An optional object whose properties will be set on 
     25     *     this instance. 
     26     */ 
     27    initialize: function(options) { 
     28        OpenLayers.Format.WFSCapabilities.prototype.initialize.apply( 
     29            this, [options] 
     30        ); 
     31    }, 
     32 
     33    /** 
     34     * APIMethod: read 
     35     * Read capabilities data from a string, and return a list of layers.  
     36     *  
     37     * Parameters:  
     38     * data - {String} or {DOMElement} data to read/parse. 
     39     * 
     40     * Returns: 
     41     * {Array} List of named layers. 
     42     */ 
     43    read: function(data) { 
     44        if(typeof data == "string") { 
     45            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
     46        } 
     47        var capabilities = {}; 
     48        var root = data.documentElement; 
     49        this.runChildNodes(capabilities, root); 
     50        return capabilities; 
     51    }, 
     52 
     53 
     54    /** 
     55     * Method: read_wfs_LatLonBoundingBox 
     56     */ 
     57    read_wfs_LatLongBoundingBox: function(obj, node) { 
     58        obj.bbox["default"] = new OpenLayers.Bounds( 
     59            parseFloat(node.getAttribute("minx")), 
     60            parseFloat(node.getAttribute("miny")), 
     61            parseFloat(node.getAttribute("maxx")), 
     62            parseFloat(node.getAttribute("maxy")) 
     63        ); 
     64    }, 
     65 
     66 
     67 
     68    /************************************ 
     69     *                                  * 
     70     *           ogc namespace          * 
     71     *                                  * 
     72     ************************************/ 
     73 
     74    /* 
     75     * Method: read_ogc_Spatial_Operators 
     76     */ 
     77    read_ogc_Spatial_Operators: function(obj, node) { 
     78        obj.spatialOperators = []; 
     79        this.readOperators(obj.spatialOperators, node); 
     80    }, 
     81 
     82    /* 
     83     * Method: read_ogc_Logical_Operators 
     84     */ 
     85    read_ogc_Logical_Operators: function(obj, node) { 
     86        obj.logicalOperators = []; 
     87        this.readOperators(obj.logicalOperators, node); 
     88    }, 
     89 
     90    /* 
     91     * Method: read_ogc_Comparison_Operators 
     92     */ 
     93    read_ogc_Comparison_Operators: function(obj, node) { 
     94        obj.comparisonOperators = []; 
     95        this.readOperators(obj.comparisonOperators, node); 
     96    }, 
     97 
     98    /* 
     99     * Method: readOperators 
     100     */ 
     101    readOperators: function(array, node) { 
     102        var children = node.childNodes; 
     103         
     104        for(var i=0; i<children.length; ++i) { 
     105            childNode = children[i]; 
     106            local = childNode.nodeName.split(":").pop(); 
     107            if(childNode.nodeType == 1) 
     108                array.push(local); 
     109        } 
     110    }, 
     111 
     112    /* 
     113     * Method: read_ogc_Arithmetic_Operators 
     114     */ 
     115    read_ogc_Arithmetic_Operators: function(obj, node) { 
     116        obj.arithmeticOperators = {}; 
     117        this.runChildNodes(obj.arithmeticOperators, node); 
     118    }, 
     119     
     120    /* 
     121     * Method: read_ogc_Function_Names 
     122     */ 
     123    read_ogc_Function_Names: function(obj, node) { 
     124        obj.functionNames = []; 
     125        this.runChildNodes(obj.functionNames, node); 
     126    }, 
     127 
     128    /* 
     129     * Method: read_ogc_Function_Name 
     130     */ 
     131    read_ogc_Function_Name: function(array, node) { 
     132        var func = this.getChildValue(node); 
     133        var nArgs = parseInt(node.getAttribute("nArgs")); 
     134        if(func && nArgs) 
     135            array.push({"function": func, "arity": nArgs}); 
     136    }, 
     137 
     138    CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_0_0"  
     139}); 
  • Format/WFSCapabilities/v1_1_0.js

    old new  
     1/** 
     2 * @requires OpenLayers/Format/WFSCapabilities.js 
     3 * 
     4 * Class: OpenLayers.Format.WFSCapabilities.v1_1_0 
     5 * Read WFS Capabilities version 1.1.0. 
     6 *  
     7 * Inherits from: 
     8 *  - <OpenLayers.Format.WFSCapabilities> 
     9 */ 
     10OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class( 
     11    OpenLayers.Format.WFSCapabilities, { 
     12     
     13    /** 
     14     * Constant: VERSION 
     15     * {String} 1.1.0 
     16     */ 
     17    VERSION: "1.1.0", 
     18     
     19    /** 
     20     * Constructor: OpenLayers.Format.WFSCapabilities.v1_1_0 
     21     * Create a new parser for WFS capabilities version 1_1_0. 
     22     * 
     23     * Parameters: 
     24     * options - {Object} An optional object whose properties will be set on 
     25     *     this instance. 
     26     */ 
     27    initialize: function(options) { 
     28        OpenLayers.Format.WFSCapabilities.prototype.initialize.apply( 
     29            this, [options] 
     30        ); 
     31    }, 
     32 
     33    /** 
     34     * APIMethod: read 
     35     * Read capabilities data from a string, and return a list of layers.  
     36     *  
     37     * Parameters:  
     38     * data - {String} or {DOMElement} data to read/parse. 
     39     * 
     40     * Returns: 
     41     * {Array} List of named layers. 
     42     */ 
     43    read: function(data) { 
     44        if(typeof data == "string") { 
     45            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 
     46        } 
     47        var capabilities = {}; 
     48        var root = data.documentElement; 
     49        this.runChildNodes(capabilities, root); 
     50        return capabilities; 
     51    }, 
     52 
     53 
     54 
     55    /************************************ 
     56     *                                  * 
     57     *           OWS namespace          * 
     58     *                                  * 
     59     ************************************/ 
     60 
     61    /** 
     62     * Method: read_ows_WGS84BoundingBox 
     63     */ 
     64    read_ows_WGS84BoundingBox: function(obj, node) { 
     65        var children = node.childNodes; 
     66        var minx, miny, maxx, maxy; 
     67        for(var i=0; i<children.length; ++i) { 
     68            childNode = children[i]; 
     69            local = childNode.nodeName.split(":").pop(); 
     70            if(childNode.nodeType == 1) { 
     71                if(local == "LowerCorner") { 
     72                    var corner = this.getChildValue(childNode).split(' '); 
     73                    minx = corner[0]; 
     74                    miny = corner[1]; 
     75                } 
     76                if(local == "UpperCorner") { 
     77                    var corner = this.getChildValue(childNode).split(' '); 
     78                    maxx = corner[0]; 
     79                    maxy = corner[1]; 
     80                } 
     81            } 
     82        } 
     83 
     84        obj.bbox["default"] = new OpenLayers.Bounds(minx, miny, maxx, maxy); 
     85    }, 
     86 
     87    /** 
     88     * Method: read_ows_BoundingBox 
     89     */ 
     90    read_ows_BoundingBox: function(obj, node) { 
     91        var children = node.childNodes; 
     92        var minx, miny, maxx, maxy, srs; 
     93 
     94        var srs = node.getAttribute("crs"); 
     95         
     96        if(srs) { 
     97            for(var i=0; i<children.length; ++i) { 
     98                childNode = children[i]; 
     99                local = childNode.nodeName.split(":").pop(); 
     100                if(childNode.nodeType == 1) { 
     101                    if(local == "LowerCorner") { 
     102                        var corner = this.getChildValue(childNode).split(' '); 
     103                        minx = corner[0]; 
     104                        miny = corner[1]; 
     105                    } 
     106                    if(local == "UpperCorner") { 
     107                        var corner = this.getChildValue(childNode).split(' '); 
     108                        maxx = corner[0]; 
     109                        maxy = corner[1]; 
     110                    } 
     111                } 
     112            } 
     113 
     114            obj.bbox[srs] = new OpenLayers.Bounds(minx, miny, maxx, maxy); 
     115        } 
     116    }, 
     117 
     118 
     119 
     120    /************************************ 
     121     *                                  * 
     122     *           ogc namespace          * 
     123     *                                  * 
     124     ************************************/ 
     125 
     126    /* 
     127     * Method: read_ogc_SpatialOperators 
     128     */ 
     129    read_ogc_SpatialOperators: function(obj, node) { 
     130        obj.spatialOperators = []; 
     131        this.runChildNodes(obj.spatialOperators, node); 
     132    }, 
     133 
     134    /* 
     135     * Method: read_ogc_SpatialOperator 
     136     */ 
     137    read_ogc_SpatialOperator: function(array, node) { 
     138        var operator = node.getAttribute("name"); 
     139        if(operator) 
     140            array.push(operator); 
     141    }, 
     142     
     143    /* 
     144     * Method: read_ogc_LogicalOperators 
     145     */ 
     146    read_ogc_LogicalOperators: function(obj, node) { 
     147        obj.logicalOperators = []; 
     148        this.runChildNodes(obj.logicalOperators, node); 
     149    }, 
     150 
     151    /* 
     152     * Method: read_ogc_LogicalOperator 
     153     */ 
     154    read_ogc_LogicalOperator: function(array, node) { 
     155        var operator = node.getAttribute("name"); 
     156        if(operator) 
     157            array.push(operator); 
     158    }, 
     159 
     160    /* 
     161     * Method: read_ogc_ComparisonOperators 
     162     */ 
     163    read_ogc_ComparisonOperators: function(obj, node) { 
     164        obj.comparisonOperators = []; 
     165        this.runChildNodes(obj.comparisonOperators, node); 
     166    }, 
     167 
     168    /* 
     169     * Method: read_ogc_ComparisonOperator 
     170     */ 
     171    read_ogc_ComparisonOperator: function(array, node) { 
     172        var operator = this.getChildValue(node); 
     173        if(operator) 
     174            array.push(operator); 
     175    }, 
     176 
     177    /* 
     178     * Method: read_ogc_ArithmeticOperators 
     179     */ 
     180    read_ogc_ArithmeticOperators: function(obj, node) { 
     181        obj.arithmeticOperators = {}; 
     182        this.runChildNodes(obj.arithmeticOperators, node); 
     183    }, 
     184 
     185 
     186    /* 
     187     * Method: read_ogc_FunctionNames 
     188     */ 
     189    read_ogc_FunctionNames: function(obj, node) { 
     190        obj.functionNames = []; 
     191        this.runChildNodes(obj.functionNames, node); 
     192    }, 
     193 
     194    /* 
     195     * Method: read_ogc_FunctionName 
     196     */ 
     197    read_ogc_FunctionName: function(array, node) { 
     198        var func = this.getChildValue(node); 
     199        var nArgs = parseInt(node.getAttribute("nArgs")); 
     200        if(func && nArgs) 
     201            array.push({"function": func, "arity": nArgs}); 
     202    }, 
     203     
     204 
     205    CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_1_0"  
     206});