[OpenLayers-Commits] r7506 - in sandbox/topp/trimet: examples lib/OpenLayers/Protocol lib/OpenLayers/Protocol/WFS
commits at openlayers.org
commits at openlayers.org
Mon Jul 14 15:13:44 EDT 2008
Author: tschaub
Date: 2008-07-14 15:13:44 -0400 (Mon, 14 Jul 2008)
New Revision: 7506
Modified:
sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html
sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS.js
sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js
Log:
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.
Modified: sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html
===================================================================
--- sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html 2008-07-14 17:46:20 UTC (rev 7505)
+++ sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html 2008-07-14 19:13:44 UTC (rev 7506)
@@ -15,7 +15,7 @@
var map;
function init(){
- OpenLayers.ProxyHost= "/proxy/?url=";
+ OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url=";
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0",
@@ -23,29 +23,28 @@
);
var layer = new OpenLayers.Layer.Vector("GML", {
- strategy: new OpenLayers.Strategy.BBOX(),
- protocol: new OpenLayers.Protocol.WFS.v1_0_0({
- url: "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp",
- params: {typename: "OWLS", maxfeatures: 10}
+ strategies: [new OpenLayers.Strategy.BBOX()],
+ protocol: new OpenLayers.Protocol.WFS({
+ url: "http://sigma.openplans.org/geoserver/wfs",
+ featureType: "topp:tasmania_cities",
+ featureNS: "http://www.openplans.org/topp"
}),
format: new OpenLayers.Format.GML()
});
map.addLayers([wms, layer]);
- map.zoomToExtent(new OpenLayers.Bounds(
- -3.92, 44.34, 4.87, 49.55
- ));
+ map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Vector Behavior Example</h1>
<p id="shortdesc">
- Uses a new strategy, protocol, and format combination.
+ Uses a BBOX strategy, WFS protocol, and GML format.
</p>
<div id="map"></div>
<div id="docs">
- <p>The vector layer shown uses the Fixed strategy, the HTTP protocol,
+ <p>The vector layer shown uses the BBOX strategy, the WFS protocol,
and the GML format.</p>
<p>The BBOX strategy fetches features within a bounding box. When the map bounds invalidate the data bounds, another request is triggered
<p>The WFS protocol gets features through a WFS request.</p>
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-14 17:46:20 UTC (rev 7505)
+++ sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js 2008-07-14 19:13:44 UTC (rev 7506)
@@ -18,9 +18,8 @@
* Property: ENVELOPE_PARAMS
* Array of parameters that should be set in a WFS request's outer envelope.
*/
+ ENVELOPE_PARAMS : ['service', 'version', 'maxFeatures', 'outputFormat'],
- ENVELOPE_PARAMS : ['service','version','maxFeatures', 'outputFormat'],
-
/**
* Property : OUTPUT_FORMATS
* A mapping from Format classnames to the proper value for the outputFormat parameter of a WFS request.
@@ -39,23 +38,24 @@
ogc: "http://www.opengis.net/ogc"
},
+ /**
+ * Property: version
+ * {String} WFS version number.
+ */
+ version: "1.0.0",
- /**
- * Property: DEFAULT_PARAMS
- * {Object} Hashtable of default key/value parameters
+ /**
+ * Property: srsName
+ * {String} Name of spatial reference system. Default is "EPSG:4326".
*/
- DEFAULT_PARAMS: { service: "WFS",
- version: "1.0.0",
- srsName: "EPSG:4326",
- typeName: "default:typeName"
- },
-
- /**
- * Property: params
- * {Object} Hashtable of key/value parameters
+ srsName: "EPSG:4326",
+
+ /**
+ * Property: service
+ * {String} Name of service. Default is "WFS".
*/
- params: null,
-
+ service: "WFS",
+
/**
* Property: defaultPrefix
* {String} Default namespace alias for creating element nodes. Default
@@ -69,12 +69,6 @@
* "the_geom".
*/
geometryName: "the_geom",
-
- /**
- * Property: featureName
- * {String} Name of the featureType.
- */
- featureName: null,
/**
* Property: layer
@@ -106,14 +100,6 @@
OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
this.filterFormat = new OpenLayers.Format.Filter();
-
- this.params = this.params || {};
- OpenLayers.Util.applyDefaults(
- this.params,
- this.DEFAULT_PARAMS
- );
-
-
},
/**
@@ -138,30 +124,31 @@
OpenLayers.Protocol.prototype.destroy.apply(this);
},
-
+
/**
* Method: read
* Construct a request for reading new features.
*/
'read': function(options) {
- var mergedOptions = OpenLayers.Util.extend({}, options);
- OpenLayers.Util.applyDefaults(mergedOptions, this.options || {});
-
- var params = {};
-
- OpenLayers.Util.extend(params, mergedOptions.params);
- OpenLayers.Util.applyDefaults(params, this.params);
+ options = OpenLayers.Util.extend({}, options);
+ OpenLayers.Util.applyDefaults(options, this.options || {});
- var root = this.createEnvelope(this.readRequestName, params);
+ var root = this.createEnvelope(this.readRequestName, options);
+
var query = this.format.createElementNSPlus("wfs:Query", {
attributes: {
- typeName: params.typeName,
- srsName: params.srsName
+ typeName: 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);
+ }
- var filter = mergedOptions.filter;
+ var filter = options.filter;
if(filter){
this.setFilterProperty(filter);
var filterNode = this.filterFormat.write(filter);
@@ -182,8 +169,8 @@
// failure
resp.code = OpenLayers.Protocol.Response.FAILURE;
}
- mergedOptions.callback.call(
- mergedOptions.scope, resp
+ options.callback.call(
+ options.scope, resp
);
};
@@ -193,17 +180,21 @@
url: this.url,
callback: callback,
data: data,
- headers: mergedOptions.headers,
+ headers: options.headers,
scope: this
});
},
/**
+ * Method: createEnvelope
+ * Creates an enveloping node.
*
* Parameters:
- *
* name - {String}
* params - {Object} A hash of parameters
+ *
+ * Returns:
+ * {DOMElement} An element node.
*/
createEnvelope: function(name, params) {
if(!params){
@@ -216,6 +207,8 @@
param = this.ENVELOPE_PARAMS[i];
if(params[param]) {
selectParams[param] = params[param];
+ } else if(this[param]) {
+ selectParams[param] = this[param];
}
}
@@ -227,9 +220,6 @@
envelope.setAttribute("outputFormat", this.OUTPUT_FORMATS[this.format.CLASS_NAME]);
}
- envelope.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS);
- envelope.setAttribute("xmlns:ogc", this.namespaces.ogc);
-
return envelope;
},
@@ -289,21 +279,15 @@
* features - {Array(<OpenLayers.Feature.Vector>}
*/
commit: function(features, options) {
- //this code is duplicated all over the place, should be functionalized out, probably
- var mergedOptions = OpenLayers.Util.extend({}, options);
- OpenLayers.Util.applyDefaults(mergedOptions, this.options || {});
- var params = {};
-
- OpenLayers.Util.extend(params, mergedOptions.params);
- OpenLayers.Util.applyDefaults(params, this.params);
- //
+ options = OpenLayers.Util.extend({}, options);
+ OpenLayers.Util.applyDefaults(options, this.options || {});
if(!features){
features = this.layer.features;
}
- var root = this.createEnvelope("wfs:Transaction", this.params);
+ var root = this.createEnvelope("wfs:Transaction", options);
var method, node;
for(var i=0; i < features.length; i++) {
@@ -316,10 +300,6 @@
var data = this.format.write(root);
- if(options){
- callback = options.callback || function(){};
- }
-
//put this callback elsewhere--this method is getting bloaty
var wfstCallback = function(request){
//Insert results
@@ -343,15 +323,16 @@
//The ad hoc objects cobbled together here are totally gross, by the way.
//Should be replaced with something better. What's this Protocol.Response object stuff?
-
- if(status.getElementsByTagName("SUCCESS").length > 0){
- mergedOptions.callback.call(
- mergedOptions.scope, {inserts : inserts, success : true}
- );
- } else {
- mergedOptions.callback.call(
- mergedOptions.scope, {success : false, request : request}
- );
+ if(options.callback) {
+ if(status.getElementsByTagName("SUCCESS").length > 0){
+ options.callback.call(
+ options.scope, {inserts : inserts, success : true}
+ );
+ } else {
+ options.callback.call(
+ options.scope, {success : false, request : request}
+ );
+ }
}
}
@@ -412,7 +393,7 @@
*/
update: function(feature) {
var node = this.format.createElementNSPlus("wfs:Update", {
- attributes: {typeName: this.params.typeName}
+ attributes: {typeName: this.featureType}
});
var prop = this.format.createElementNSPlus("wfs:Property");
var name = this.format.createElementNSPlus("wfs:Name", {
@@ -452,7 +433,7 @@
*/
"delete": function(feature) {
var node = this.format.createElementNSPlus("wfs:Delete", {
- attributes: {typeName: this.params.typeName}
+ attributes: {typeName: this.featureType}
});
node.appendChild(this.createFidFilterNode(feature));
@@ -468,7 +449,7 @@
var root = this.createEnvelope("wfs:Transaction");
var deleteNode = this.format.createElementNSPlus("wfs:Delete", {
- attributes: {typeName: this.params.typeName}
+ attributes: {typeName: this.featureType}
});
var filterNode = this.filterFormat.write(filter);
Modified: sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS.js
===================================================================
--- sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS.js 2008-07-14 17:46:20 UTC (rev 7505)
+++ sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS.js 2008-07-14 19:13:44 UTC (rev 7506)
@@ -2,4 +2,17 @@
* Namespace: OpenLayers.Protocol.WFS
* A namespace for versioned WFS protocols.
*/
-OpenLayers.Protocol.WFS = {};
+OpenLayers.Protocol.WFS = function(options) {
+ options = OpenLayers.Util.applyDefaults(
+ options, OpenLayers.Protocol.WFS.DEFAULTS
+ );
+ var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")];
+ if(!cls) {
+ throw "Unsupported WFS version: " + options.version;
+ }
+ return new cls(options);
+}
+
+OpenLayers.Protocol.WFS.DEFAULTS = {
+ "version": "1.0.0"
+};
More information about the Commits
mailing list