]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Protocol/WFS.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Protocol / WFS.js
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. */
4
5 /**
6  * @requires OpenLayers/Protocol.js
7  */
8
9 /**
10  * Function: OpenLayers.Protocol.WFS
11  * Used to create a versioned WFS protocol.  Default version is 1.0.0.
12  *
13  * Returns:
14  * {<OpenLayers.Protocol>} A WFS protocol of the given version.
15  */
16 OpenLayers.Protocol.WFS = function(options) {
17     options = OpenLayers.Util.applyDefaults(
18         options, OpenLayers.Protocol.WFS.DEFAULTS
19     );
20     var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")];
21     if(!cls) {
22         throw "Unsupported WFS version: " + options.version;
23     }
24     return new cls(options);
25 };
26
27 /**
28  * Function: OpenLayers.Protocol.WFS.fromWMSLayer
29  * Convenience function to create a WFS protocol from a WMS layer.  This makes
30  *     the assumption that a WFS requests can be issued at the same URL as
31  *     WMS requests and that a WFS featureType exists with the same name as the
32  *     WMS layer.
33  *     
34  * This function is designed to auto-configure <url>, <featureType>,
35  *     <featurePrefix> and <srsName> for WFS <version> 1.1.0. Note that
36  *     srsName matching with the WMS layer will not work with WFS 1.0.0..
37  * 
38  * Parameters:
39  * layer - {<OpenLayers.Layer.WMS>} WMS layer that has a matching WFS
40  *     FeatureType at the same server url with the same typename.
41  * options - {Object} Default properties to be set on the protocol.
42  *
43  */
44 OpenLayers.Protocol.WFS.fromWMSLayer = function(layer, options) {
45     var typeName, featurePrefix;
46     var param = layer.params["LAYERS"];
47     var parts = (param instanceof Array ? param[0] : param).split(":");
48     if(parts.length > 1) {
49         featurePrefix = parts[0];
50     }
51     typeName = parts.pop();
52     var protocolOptions = {
53         url: layer.url,
54         featureType: typeName,
55         featurePrefix: featurePrefix,
56         srsName: layer.projection && layer.projection.getCode() ||
57                  layer.map && layer.map.getProjectionObject().getCode(),
58         version: "1.1.0"
59     };
60     return new OpenLayers.Protocol.WFS(OpenLayers.Util.applyDefaults(
61         options, protocolOptions
62     ));
63 };
64
65 /**
66  * Constant: OpenLayers.Protocol.WFS.DEFAULTS
67  */
68 OpenLayers.Protocol.WFS.DEFAULTS = {
69     "version": "1.0.0"
70 };