[OpenLayers-Commits] r7514 - sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS
commits at openlayers.org
commits at openlayers.org
Tue Jul 15 16:19:26 EDT 2008
Author: tschaub
Date: 2008-07-15 16:19:26 -0400 (Tue, 15 Jul 2008)
New Revision: 7514
Modified:
sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js
Log:
Separating featureType (local), featureNS (namespace uri), and featurePrefix (alias).
Modified: sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js
===================================================================
--- sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-07-15 20:17:30 UTC (rev 7513)
+++ sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-07-15 20:19:26 UTC (rev 7514)
@@ -28,7 +28,6 @@
"OpenLayers.Format.GML" : "GML2"
},
-
/**
* Property: namespaces
* {Object} Namespace dictionary keyed by namespace alias.
@@ -64,6 +63,18 @@
defaultPrefix: "wfs",
/**
+ * Property: featureType
+ * {String} Local feature typeName.
+ */
+ featureType: null,
+
+ /**
+ * Property: featureNS
+ * {String} Feature namespace.
+ */
+ featureNS: null,
+
+ /**
* Property: geometryName
* {String} Name of the geometry attribute for features. Default is
* "the_geom".
@@ -71,6 +82,12 @@
geometryName: "the_geom",
/**
+ * Property: featurePrefix
+ * {String} Namespace alias for feature type. Default is "feature".
+ */
+ featurePrefix: "feature",
+
+ /**
* Property: layer
* {<OpenLayers.Layer.Vector>}
*/
@@ -95,10 +112,22 @@
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
+ *
+ * Valid options properties:
+ * featureType - {String} Local (without prefix) feature typeName (required).
+ * featureNS - {String} Feature namespace (optional).
+ * featurePrefix - {String} Feature namespace alias (optional - only used
+ * if featureNS is provided). Default is 'feature'.
+ * geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
*/
initialize: function(options) {
- OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
-
+ OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
+ if(this.featureNS) {
+ this.namespaces = OpenLayers.Util.extend(
+ {feature: options.featureNS},
+ OpenLayers.Protocol.WFS.v1_0_0.prototype.namespaces
+ );
+ }
this.filterFormat = new OpenLayers.Format.Filter();
},
@@ -110,8 +139,8 @@
* format - {OpenLayers.Format} A format that should handle both XML node creation and
*/
setFormat: function(format){
+ OpenLayers.Util.extend(format.namespaces, this.namespaces);
OpenLayers.Protocol.prototype.setFormat.apply(this, arguments);
- format.namespaces = this.namespaces;
},
/**
@@ -138,14 +167,13 @@
var query = this.format.createElementNSPlus("wfs:Query", {
attributes: {
- typeName: options.featureType,
+ typeName: (options.featureNS ? this.featurePrefix + ":" : "") +
+ options.featureType,
srsName: options.srsName || this.srsName
}
});
- var loc = options.featureType.indexOf(":");
- if(loc > 0) {
- var prefix = options.featureType.substring(0, loc);
- query.setAttribute("xmlns:" + prefix, options.featureNS);
+ if(options.featureNS) {
+ query.setAttribute("xmlns:feature", options.featureNS);
}
var filter = options.filter;
@@ -174,7 +202,9 @@
);
};
- var data = this.format.write(root);
+ var data = OpenLayers.Format.XML.prototype.write.apply(
+ this.format, [root]
+ );
return OpenLayers.Request.POST({
url: this.url,
@@ -222,8 +252,6 @@
return envelope;
},
-
-
/**
* Method: readResponse
@@ -393,7 +421,10 @@
*/
update: function(feature) {
var node = this.format.createElementNSPlus("wfs:Update", {
- attributes: {typeName: this.featureType}
+ attributes: {
+ typeName: (options.featureNS ? this.featurePrefix + ":" : "") +
+ options.featureType
+ }
});
var prop = this.format.createElementNSPlus("wfs:Property");
var name = this.format.createElementNSPlus("wfs:Name", {
@@ -433,7 +464,10 @@
*/
"delete": function(feature) {
var node = this.format.createElementNSPlus("wfs:Delete", {
- attributes: {typeName: this.featureType}
+ attributes: {
+ typeName: (options.featureNS ? this.featurePrefix + ":" : "") +
+ options.featureType
+ }
});
node.appendChild(this.createFidFilterNode(feature));
@@ -449,7 +483,10 @@
var root = this.createEnvelope("wfs:Transaction");
var deleteNode = this.format.createElementNSPlus("wfs:Delete", {
- attributes: {typeName: this.featureType}
+ attributes: {
+ typeName: (options.featureNS ? this.featurePrefix + ":" : "") +
+ options.featureType
+ }
});
var filterNode = this.filterFormat.write(filter);
More information about the Commits
mailing list