Changeset 7506
- Timestamp:
- 07/14/08 15:13:44 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/topp/trimet/examples/v2-bbox-wfs-gml.html
r7496 r7506 16 16 17 17 function init(){ 18 OpenLayers.ProxyHost= "/ proxy/?url=";18 OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url="; 19 19 map = new OpenLayers.Map('map'); 20 20 var wms = new OpenLayers.Layer.WMS( … … 24 24 25 25 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" 30 31 }), 31 32 format: new OpenLayers.Format.GML() … … 33 34 34 35 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); 38 37 } 39 38 </script> … … 42 41 <h1 id="title">Vector Behavior Example</h1> 43 42 <p id="shortdesc"> 44 Uses a new strategy, protocol, and format combination.43 Uses a BBOX strategy, WFS protocol, and GML format. 45 44 </p> 46 45 <div id="map"></div> 47 46 <div id="docs"> 48 <p>The vector layer shown uses the Fixed strategy, the HTTPprotocol,47 <p>The vector layer shown uses the BBOX strategy, the WFS protocol, 49 48 and the GML format.</p> 50 49 <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 3 3 * A namespace for versioned WFS protocols. 4 4 */ 5 OpenLayers.Protocol.WFS = {}; 5 OpenLayers.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 16 OpenLayers.Protocol.WFS.DEFAULTS = { 17 "version": "1.0.0" 18 }; sandbox/topp/trimet/lib/OpenLayers/Protocol/WFS/v1_0_0.js
r7496 r7506 19 19 * Array of parameters that should be set in a WFS request's outer envelope. 20 20 */ 21 22 ENVELOPE_PARAMS : ['service','version','maxFeatures', 'outputFormat'], 21 ENVELOPE_PARAMS : ['service', 'version', 'maxFeatures', 'outputFormat'], 23 22 24 23 /** … … 40 39 }, 41 40 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 59 59 /** 60 60 * Property: defaultPrefix … … 70 70 */ 71 71 geometryName: "the_geom", 72 73 /**74 * Property: featureName75 * {String} Name of the featureType.76 */77 featureName: null,78 72 79 73 /** … … 107 101 108 102 this.filterFormat = new OpenLayers.Format.Filter(); 109 110 this.params = this.params || {};111 OpenLayers.Util.applyDefaults(112 this.params,113 this.DEFAULT_PARAMS114 );115 116 117 103 }, 118 104 … … 139 125 }, 140 126 141 127 142 128 /** 143 129 * Method: read … … 145 131 */ 146 132 '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 156 138 157 139 var query = this.format.createElementNSPlus("wfs:Query", { 158 140 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 } 163 150 164 var filter = mergedOptions.filter;151 var filter = options.filter; 165 152 if(filter){ 166 153 this.setFilterProperty(filter); … … 183 170 resp.code = OpenLayers.Protocol.Response.FAILURE; 184 171 } 185 mergedOptions.callback.call(186 mergedOptions.scope, resp172 options.callback.call( 173 options.scope, resp 187 174 ); 188 175 }; … … 194 181 callback: callback, 195 182 data: data, 196 headers: mergedOptions.headers,183 headers: options.headers, 197 184 scope: this 198 185 }); … … 200 187 201 188 /** 189 * Method: createEnvelope 190 * Creates an enveloping node. 202 191 * 203 192 * Parameters: 204 *205 193 * name - {String} 206 194 * params - {Object} A hash of parameters 195 * 196 * Returns: 197 * {DOMElement} An element node. 207 198 */ 208 199 createEnvelope: function(name, params) { … … 217 208 if(params[param]) { 218 209 selectParams[param] = params[param]; 210 } else if(this[param]) { 211 selectParams[param] = this[param]; 219 212 } 220 213 } … … 227 220 envelope.setAttribute("outputFormat", this.OUTPUT_FORMATS[this.format.CLASS_NAME]); 228 221 } 229 230 envelope.setAttribute("xmlns:" + this.format.featurePrefix, this.format.featureNS);231 envelope.setAttribute("xmlns:ogc", this.namespaces.ogc);232 222 233 223 return envelope; … … 290 280 */ 291 281 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 || {}); 301 285 302 286 if(!features){ … … 304 288 } 305 289 306 var root = this.createEnvelope("wfs:Transaction", this.params);290 var root = this.createEnvelope("wfs:Transaction", options); 307 291 308 292 var method, node; … … 316 300 317 301 var data = this.format.write(root); 318 319 if(options){320 callback = options.callback || function(){};321 }322 302 323 303 //put this callback elsewhere--this method is getting bloaty … … 344 324 //The ad hoc objects cobbled together here are totally gross, by the way. 345 325 //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 } 355 336 } 356 337 … … 413 394 update: function(feature) { 414 395 var node = this.format.createElementNSPlus("wfs:Update", { 415 attributes: {typeName: this. params.typeName}396 attributes: {typeName: this.featureType} 416 397 }); 417 398 var prop = this.format.createElementNSPlus("wfs:Property"); … … 453 434 "delete": function(feature) { 454 435 var node = this.format.createElementNSPlus("wfs:Delete", { 455 attributes: {typeName: this. params.typeName}436 attributes: {typeName: this.featureType} 456 437 }); 457 438 … … 469 450 470 451 var deleteNode = this.format.createElementNSPlus("wfs:Delete", { 471 attributes: {typeName: this. params.typeName}452 attributes: {typeName: this.featureType} 472 453 }); 473 454
