OpenLayers OpenLayers

Changeset 7117

Show
Ignore:
Timestamp:
05/08/08 17:22:32 (8 months ago)
Author:
sbenthall
Message:

WFS.Protocol, several changes:
- uses Format.Filter
- read uses POST instead of GET for GetFeature request
- abstracted out XML envelope (namespace, service, version) creation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector-behavior/lib/OpenLayers/Protocol/WFS/v1_0_0.js

    r7108 r7117  
    3333    DEFAULT_PARAMS: { service: "WFS", 
    3434                      version: "1.0.0", 
    35                       request: "GetFeature" 
    3635                    }, 
    3736 
     
    7372     */ 
    7473    parser: null, 
     74     
     75    /** 
     76     * Property: filterFormat 
     77     * {<OpenLayers.Format.Filter>} Parser for reading and writing transactions. 
     78     */ 
     79    filterFormat: null, 
    7580     
    7681    /** 
     
    8994        //}); 
    9095         
     96        this.filterFormat = new OpenLayers.Format.Filter(); 
     97         
    9198        this.params = this.params || {}; 
    9299        OpenLayers.Util.applyDefaults( 
     
    128135        OpenLayers.Util.extend(params, mergedOptions.params); 
    129136        OpenLayers.Util.applyDefaults(params, this.params); 
     137         
     138         
     139        var root = this.createEnvelope("wfs:GetFeature"); 
     140         
     141        var query = this.format.createElementNSPlus("wfs:Query", { 
     142            attributes: {typeName: this.params.typename} 
     143        }); 
     144         
     145        if(params.filter){ 
     146            var filterNode = this.filterFormat.write(params.filter); 
     147            query.appendChild(filterNode);     
     148        } 
     149         
     150        root.appendChild(query); 
     151      
     152        if(params.bbox){ 
     153            var bounds = params.bbox; 
     154            OpenLayers.Console.log(bounds); 
     155             
     156            var bboxFilter = new OpenLayers.Filter.Spatial({ 
     157                type: OpenLayers.Filter.Spatial.BBOX, 
     158                property: this.geometryName, 
     159                value: new OpenLayers.Geometry.Rectangle(bounds[0], bounds[1], bounds[0] - bounds[2], bounds[1] - bounds[3]) 
     160            }); 
     161             
     162            var node = this.filterFormat.write(bboxFilter); 
     163             
     164            root.appendChild(node); 
     165             
     166             
     167        } 
    130168         
    131169        var callback = function(request) { 
     
    145183            ); 
    146184        };  
    147      
    148         return OpenLayers.Request.GET({ 
     185         
     186        var data = this.format.write(root); 
     187     
     188        return OpenLayers.Request.POST({ 
    149189            url: url, 
    150190            callback: callback, 
    151             params: params
     191            data: data
    152192            headers: mergedOptions.headers, 
    153193            scope: this 
    154         });         
    155     }, 
     194        });        
     195    }, 
     196     
     197    // name e.g. 'wfs:Transaction' 
     198    createEnvelope: function(name) { 
     199        var envelope = this.format.createElementNSPlus(name);  
     200 
     201        // should handle params here gracefully 
     202        // should check for e.g. maxFeatures 
     203        envelope.setAttribute('version', this.params.VERSION); 
     204        envelope.setAttribute('service', this.params.SERVICE); 
     205         
     206        envelope.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS); 
     207        
     208        // This should depend on the layer's format. 
     209        envelope.setAttribute("outputFormat","GML2"); 
     210         
     211        envelope.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS); 
     212         
     213        envelope.setAttribute("xmlns:ogc","http://www.opengis.net/ogc"); 
     214         
     215        return envelope; 
     216    }, 
     217     
     218     
    156219 
    157220    /** 
     
    192255        } 
    193256         
    194         var root = this.format.createElementNSPlus("wfs:Transaction", { 
    195             attributes: { 
    196                 version: this.params.VERSION,  
    197                 service: this.params.SERVICE 
    198             } 
    199         }); 
    200          
    201         root.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS); 
     257        var root = this.createEnvelope("wfs:Transaction"); 
    202258         
    203259        var method, node; 
     
    301357        } 
    302358         
     359        // TODO: Replace with slicket Format dealio. (?) 
    303360        // add feature id filter 
    304361        var filter = this.format.createElementNSPlus("ogc:Filter");