1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Tile.js
8 * @requires OpenLayers/Request/XMLHttpRequest.js
12 * Class: OpenLayers.Tile.WFS
13 * Instances of OpenLayers.Tile.WFS are used to manage the image tiles
14 * used by various layers. Create a new image tile with the
15 * <OpenLayers.Tile.WFS> constructor.
20 OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
24 * {Array(<OpenLayers.Feature>)} list of features in this tile
36 * {<OpenLayers.Request.XMLHttpRequest>}
40 /** TBD 3.0 - reorder the parameters to the init function to put URL
41 * as last, so we can continue to call tile.initialize()
42 * without changing the arguments.
44 * Constructor: OpenLayers.Tile.WFS
45 * Constructor for a new <OpenLayers.Tile.WFS> instance.
48 * layer - {<OpenLayers.Layer>} layer that the tile will go in.
49 * position - {<OpenLayers.Pixel>}
50 * bounds - {<OpenLayers.Bounds>}
52 * size - {<OpenLayers.Size>}
54 initialize: function(layer, position, bounds, url, size) {
55 OpenLayers.Tile.prototype.initialize.apply(this, arguments);
62 * nullify references to prevent circular references and memory leaks
65 OpenLayers.Tile.prototype.destroy.apply(this, arguments);
66 this.destroyAllFeatures();
71 //this.request.destroy();
78 * Clear the tile of any bounds/position-related data so that it can
79 * be reused in a new location.
82 this.destroyAllFeatures();
87 * Check that a tile should be drawn, and load features for it.
90 if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
92 //if already loading, send 'reload' instead of 'loadstart'.
93 this.events.triggerEvent("reload");
95 this.isLoading = true;
96 this.events.triggerEvent("loadstart");
98 this.loadFeaturesForRegion(this.requestSuccess);
103 * Method: loadFeaturesForRegion
104 * Abort any pending requests and issue another request for data.
106 * Input are function pointers for what to do on success and failure.
109 * success - {function}
110 * failure - {function}
112 loadFeaturesForRegion:function(success, failure) {
114 this.request.abort();
116 this.request = OpenLayers.Request.GET({
125 * Method: requestSuccess
126 * Called on return from request succcess. Adds results via
127 * layer.addFeatures in vector mode, addResults otherwise.
130 * request - {<OpenLayers.Request.XMLHttpRequest>}
132 requestSuccess:function(request) {
134 var doc = request.responseXML;
135 if (!doc || !doc.documentElement) {
136 doc = request.responseText;
138 if (this.layer.vectorMode) {
139 this.layer.addFeatures(this.layer.formatObject.read(doc));
141 var xml = new OpenLayers.Format.XML();
142 if (typeof doc == "string") {
145 var resultFeatures = xml.getElementsByTagNameNS(
146 doc, "http://www.opengis.net/gml", "featureMember"
148 this.addResults(resultFeatures);
152 this.events.triggerEvent("loadend");
155 //request produced with success, we can delete the request object.
156 //this.request.destroy();
162 * Construct new feature via layer featureClass constructor, and add to
168 addResults: function(results) {
169 for (var i=0; i < results.length; i++) {
170 var feature = new this.layer.featureClass(this.layer,
172 this.features.push(feature);
178 * Method: destroyAllFeatures
179 * Iterate through and call destroy() on each feature, removing it from
182 destroyAllFeatures: function() {
183 while(this.features.length > 0) {
184 var feature = this.features.shift();
189 CLASS_NAME: "OpenLayers.Tile.WFS"