OpenLayers OpenLayers

Changeset 7514

Show
Ignore:
Timestamp:
07/15/08 16:19:26 (2 months ago)
Author:
tschaub
Message:

Separating featureType (local), featureNS (namespace uri), and featurePrefix (alias).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js

    r7506 r7514  
    2929    }, 
    3030     
    31      
    3231    /** 
    3332     * Property: namespaces 
     
    6564     
    6665    /** 
     66     * Property: featureType 
     67     * {String} Local feature typeName. 
     68     */ 
     69    featureType: null, 
     70     
     71    /** 
     72     * Property: featureNS 
     73     * {String} Feature namespace. 
     74     */ 
     75    featureNS: null, 
     76     
     77    /** 
    6778     * Property: geometryName 
    6879     * {String} Name of the geometry attribute for features.  Default is 
     
    7283 
    7384    /** 
     85     * Property: featurePrefix 
     86     * {String} Namespace alias for feature type.  Default is "feature". 
     87     */ 
     88    featurePrefix: "feature", 
     89 
     90    /** 
    7491     * Property: layer 
    7592     * {<OpenLayers.Layer.Vector>} 
     
    96113     * options - {Object} Optional object whose properties will be set on the 
    97114     *     instance. 
     115     * 
     116     * Valid options properties: 
     117     * featureType - {String} Local (without prefix) feature typeName (required). 
     118     * featureNS - {String} Feature namespace (optional). 
     119     * featurePrefix - {String} Feature namespace alias (optional - only used 
     120     *     if featureNS is provided).  Default is 'feature'. 
     121     * geometryName - {String} Name of geometry attribute.  Default is 'the_geom'. 
    98122     */ 
    99123    initialize: function(options) { 
    100         OpenLayers.Protocol.prototype.initialize.apply(this, [options]);         
    101          
     124        OpenLayers.Protocol.prototype.initialize.apply(this, [options]); 
     125        if(this.featureNS) { 
     126            this.namespaces = OpenLayers.Util.extend( 
     127                {feature: options.featureNS}, 
     128                OpenLayers.Protocol.WFS.v1_0_0.prototype.namespaces 
     129            ); 
     130        } 
    102131        this.filterFormat = new OpenLayers.Format.Filter(); 
    103132    }, 
     
    111140     */ 
    112141    setFormat: function(format){ 
     142        OpenLayers.Util.extend(format.namespaces, this.namespaces); 
    113143        OpenLayers.Protocol.prototype.setFormat.apply(this, arguments); 
    114         format.namespaces = this.namespaces; 
    115144    }, 
    116145     
     
    139168        var query = this.format.createElementNSPlus("wfs:Query", { 
    140169            attributes: { 
    141                 typeName: options.featureType, 
     170                typeName: (options.featureNS ? this.featurePrefix + ":" : "") + 
     171                    options.featureType, 
    142172                srsName: options.srsName || this.srsName 
    143173            } 
    144174        }); 
    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); 
     175        if(options.featureNS) { 
     176            query.setAttribute("xmlns:feature", options.featureNS); 
    149177        } 
    150178  
     
    175203        };  
    176204         
    177         var data = this.format.write(root); 
     205        var data = OpenLayers.Format.XML.prototype.write.apply( 
     206            this.format, [root] 
     207        ); 
    178208     
    179209        return OpenLayers.Request.POST({ 
     
    223253        return envelope; 
    224254    }, 
    225      
    226      
    227255 
    228256    /** 
     
    394422    update: function(feature) { 
    395423        var node = this.format.createElementNSPlus("wfs:Update", { 
    396             attributes: {typeName: this.featureType} 
     424            attributes: { 
     425                typeName: (options.featureNS ? this.featurePrefix + ":" : "") + 
     426                    options.featureType 
     427            } 
    397428        }); 
    398429        var prop = this.format.createElementNSPlus("wfs:Property"); 
     
    434465    "delete": function(feature) { 
    435466        var node = this.format.createElementNSPlus("wfs:Delete", { 
    436             attributes: {typeName: this.featureType} 
     467            attributes: { 
     468                typeName: (options.featureNS ? this.featurePrefix + ":" : "") + 
     469                    options.featureType 
     470            } 
    437471        }); 
    438472               
     
    450484         
    451485        var deleteNode = this.format.createElementNSPlus("wfs:Delete", { 
    452             attributes: {typeName: this.featureType} 
     486            attributes: { 
     487                typeName: (options.featureNS ? this.featurePrefix + ":" : "") + 
     488                    options.featureType 
     489            } 
    453490        });        
    454491