OpenLayers OpenLayers

Changeset 7506

Show
Ignore:
Timestamp:
07/14/08 15:13:44 (2 months ago)
Author:
tschaub
Message:

Breaking wfs protocol to make it work like I want - based on the belief that featureType and featureNS are all the client needs to specify. Also, removing use of params which hearkens back to the day when WFS was just about GET and you could pile parameters together in a query string.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html

    r7496 r7506  
    1616         
    1717            function init(){ 
    18                 OpenLayers.ProxyHost= "/proxy/?url="; 
     18                OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url="; 
    1919                map = new OpenLayers.Map('map'); 
    2020                var wms = new OpenLayers.Layer.WMS( 
     
    2424 
    2525                var layer = new OpenLayers.Layer.Vector("GML", { 
    26                     strategy: new OpenLayers.Strategy.BBOX(), 
    27                     protocol: new OpenLayers.Protocol.WFS.v1_0_0({ 
    28                         url:  "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp", 
    29                         params: {typename: "OWLS", maxfeatures: 10} 
     26                    strategies: [new OpenLayers.Strategy.BBOX()], 
     27                    protocol: new OpenLayers.Protocol.WFS({ 
     28                        url:  "http://sigma.openplans.org/geoserver/wfs", 
     29                        featureType: "topp:tasmania_cities", 
     30                        featureNS: "http://www.openplans.org/topp" 
    3031                    }), 
    3132                    format: new OpenLayers.Format.GML() 
     
    3334 
    3435                map.addLayers([wms, layer]); 
    35                 map.zoomToExtent(new OpenLayers.Bounds( 
    36                     -3.92, 44.34, 4.87, 49.55 
    37                 )); 
     36                map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6); 
    3837            } 
    3938        </script> 
     
    4241        <h1 id="title">Vector Behavior Example</h1> 
    4342        <p id="shortdesc"> 
    44             Uses a new strategy, protocol, and format combination
     43            Uses a BBOX strategy, WFS protocol, and GML format
    4544        </p> 
    4645        <div id="map"></div> 
    4746        <div id="docs"> 
    48             <p>The vector layer shown uses the Fixed strategy, the HTTP protocol, 
     47            <p>The vector layer shown uses the BBOX strategy, the WFS protocol, 
    4948            and the GML format.</p> 
    5049            <p>The BBOX strategy fetches features within a bounding box.  When the map bounds invalidate the data bounds, another request is triggered 
  • sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS.js

    r7496 r7506  
    33 * A namespace for versioned WFS protocols. 
    44 */ 
    5 OpenLayers.Protocol.WFS = {}; 
     5OpenLayers.Protocol.WFS = function(options) { 
     6    options = OpenLayers.Util.applyDefaults( 
     7        options, OpenLayers.Protocol.WFS.DEFAULTS 
     8    ); 
     9    var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")]; 
     10    if(!cls) { 
     11        throw "Unsupported WFS version: " + options.version; 
     12    } 
     13    return new cls(options); 
     14
     15 
     16OpenLayers.Protocol.WFS.DEFAULTS = { 
     17    "version": "1.0.0" 
     18}; 
  • sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js

    r7496 r7506  
    1919     * Array of parameters that should be set in a WFS request's outer envelope. 
    2020     */ 
    21      
    22     ENVELOPE_PARAMS : ['service','version','maxFeatures', 'outputFormat'], 
     21    ENVELOPE_PARAMS : ['service', 'version', 'maxFeatures', 'outputFormat'], 
    2322     
    2423    /** 
     
    4039    }, 
    4140     
    42      
    43     /**   
    44      * Property: DEFAULT_PARAMS 
    45      * {Object} Hashtable of default key/value parameters 
    46      */ 
    47     DEFAULT_PARAMS: { service: "WFS", 
    48                       version: "1.0.0", 
    49                       srsName: "EPSG:4326", 
    50                       typeName: "default:typeName" 
    51                     }, 
    52  
    53     /**   
    54      * Property: params 
    55      * {Object} Hashtable of key/value parameters 
    56      */ 
    57     params: null, 
    58  
     41    /** 
     42     * Property: version 
     43     * {String} WFS version number. 
     44     */ 
     45    version: "1.0.0", 
     46     
     47    /** 
     48     * Property: srsName 
     49     * {String} Name of spatial reference system.  Default is "EPSG:4326". 
     50     */ 
     51    srsName: "EPSG:4326", 
     52     
     53    /** 
     54     * Property: service 
     55     * {String} Name of service.  Default is "WFS". 
     56     */ 
     57    service: "WFS", 
     58     
    5959    /** 
    6060     * Property: defaultPrefix 
     
    7070     */ 
    7171    geometryName: "the_geom", 
    72      
    73     /** 
    74      * Property: featureName 
    75      * {String} Name of the featureType. 
    76      */ 
    77     featureName: null, 
    7872 
    7973    /** 
     
    107101         
    108102        this.filterFormat = new OpenLayers.Format.Filter(); 
    109          
    110         this.params = this.params || {}; 
    111         OpenLayers.Util.applyDefaults( 
    112                        this.params,  
    113                        this.DEFAULT_PARAMS 
    114                        ); 
    115          
    116          
    117103    }, 
    118104     
     
    139125    }, 
    140126     
    141             
     127 
    142128    /** 
    143129     * Method: read 
     
    145131     */ 
    146132    'read': function(options) { 
    147         var mergedOptions = OpenLayers.Util.extend({}, options); 
    148         OpenLayers.Util.applyDefaults(mergedOptions, this.options || {}); 
    149  
    150         var params = {}; 
    151  
    152         OpenLayers.Util.extend(params, mergedOptions.params); 
    153         OpenLayers.Util.applyDefaults(params, this.params); 
    154          
    155         var root = this.createEnvelope(this.readRequestName, params); 
     133        options = OpenLayers.Util.extend({}, options); 
     134        OpenLayers.Util.applyDefaults(options, this.options || {}); 
     135         
     136        var root = this.createEnvelope(this.readRequestName, options); 
     137         
    156138         
    157139        var query = this.format.createElementNSPlus("wfs:Query", { 
    158140            attributes: { 
    159                 typeName: params.typeName, 
    160                 srsName: params.srsName 
    161             } 
    162         }); 
     141                typeName: options.featureType, 
     142                srsName: options.srsName || this.srsName 
     143            } 
     144        }); 
     145        var loc = options.featureType.indexOf(":"); 
     146        if(loc > 0) { 
     147            var prefix = options.featureType.substring(0, loc); 
     148            query.setAttribute("xmlns:" + prefix, options.featureNS); 
     149        } 
    163150  
    164         var filter = mergedOptions.filter; 
     151        var filter = options.filter; 
    165152        if(filter){ 
    166153            this.setFilterProperty(filter); 
     
    183170                resp.code = OpenLayers.Protocol.Response.FAILURE; 
    184171            } 
    185             mergedOptions.callback.call( 
    186                 mergedOptions.scope, resp 
     172            options.callback.call( 
     173                options.scope, resp 
    187174            ); 
    188175        };  
     
    194181            callback: callback, 
    195182            data: data, 
    196             headers: mergedOptions.headers, 
     183            headers: options.headers, 
    197184            scope: this 
    198185        });        
     
    200187     
    201188   /** 
     189    * Method: createEnvelope 
     190    * Creates an enveloping node. 
    202191    *  
    203192    * Parameters: 
    204     *  
    205193    * name - {String}  
    206194    * params - {Object} A hash of parameters 
     195    * 
     196    * Returns: 
     197    * {DOMElement} An element node. 
    207198    */ 
    208199    createEnvelope: function(name, params) { 
     
    217208            if(params[param]) { 
    218209                selectParams[param] = params[param]; 
     210            } else if(this[param]) { 
     211                selectParams[param] = this[param]; 
    219212            } 
    220213        } 
     
    227220            envelope.setAttribute("outputFormat", this.OUTPUT_FORMATS[this.format.CLASS_NAME]);     
    228221        } 
    229          
    230         envelope.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS);         
    231         envelope.setAttribute("xmlns:ogc", this.namespaces.ogc); 
    232222         
    233223        return envelope; 
     
    290280     */ 
    291281    commit: function(features, options) { 
    292         //this code is duplicated all over the place, should be functionalized out, probably 
    293         var mergedOptions = OpenLayers.Util.extend({}, options); 
    294         OpenLayers.Util.applyDefaults(mergedOptions, this.options || {}); 
    295  
    296         var params = {}; 
    297  
    298         OpenLayers.Util.extend(params, mergedOptions.params); 
    299         OpenLayers.Util.applyDefaults(params, this.params); 
    300         // 
     282 
     283        options = OpenLayers.Util.extend({}, options); 
     284        OpenLayers.Util.applyDefaults(options, this.options || {}); 
    301285         
    302286        if(!features){ 
     
    304288        } 
    305289         
    306         var root = this.createEnvelope("wfs:Transaction", this.params); 
     290        var root = this.createEnvelope("wfs:Transaction", options); 
    307291         
    308292        var method, node; 
     
    316300         
    317301        var data = this.format.write(root); 
    318          
    319         if(options){ 
    320             callback = options.callback || function(){}; 
    321         } 
    322302         
    323303        //put this callback elsewhere--this method is getting bloaty 
     
    344324            //The ad hoc objects cobbled together here are totally gross, by the way. 
    345325            //Should be replaced with something better.  What's this Protocol.Response object stuff? 
    346              
    347             if(status.getElementsByTagName("SUCCESS").length > 0){ 
    348                 mergedOptions.callback.call( 
    349                     mergedOptions.scope, {inserts : inserts, success : true} 
    350                 ); 
    351             } else { 
    352                 mergedOptions.callback.call( 
    353                     mergedOptions.scope, {success : false, request : request} 
    354                 ); 
     326            if(options.callback) { 
     327                if(status.getElementsByTagName("SUCCESS").length > 0){ 
     328                    options.callback.call( 
     329                        options.scope, {inserts : inserts, success : true} 
     330                    ); 
     331                } else { 
     332                    options.callback.call( 
     333                        options.scope, {success : false, request : request} 
     334                    ); 
     335                } 
    355336            } 
    356337            
     
    413394    update: function(feature) { 
    414395        var node = this.format.createElementNSPlus("wfs:Update", { 
    415             attributes: {typeName: this.params.typeName} 
     396            attributes: {typeName: this.featureType} 
    416397        }); 
    417398        var prop = this.format.createElementNSPlus("wfs:Property"); 
     
    453434    "delete": function(feature) { 
    454435        var node = this.format.createElementNSPlus("wfs:Delete", { 
    455             attributes: {typeName: this.params.typeName} 
     436            attributes: {typeName: this.featureType} 
    456437        }); 
    457438               
     
    469450         
    470451        var deleteNode = this.format.createElementNSPlus("wfs:Delete", { 
    471             attributes: {typeName: this.params.typeName} 
     452            attributes: {typeName: this.featureType} 
    472453        });        
    473454