source:
trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Protocol/WFS.js
@
76
Revision 76, 2.4 KB checked in by djay, 12 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
2 | * full list of contributors). Published under the Clear BSD license. |
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
4 | * full text of the license. */ |
5 | |
6 | /** |
7 | * @requires OpenLayers/Protocol.js |
8 | */ |
9 | |
10 | /** |
11 | * Function: OpenLayers.Protocol.WFS |
12 | * Used to create a versioned WFS protocol. Default version is 1.0.0. |
13 | * |
14 | * Returns: |
15 | * {<OpenLayers.Protocol>} A WFS protocol of the given version. |
16 | */ |
17 | OpenLayers.Protocol.WFS = function(options) { |
18 | options = OpenLayers.Util.applyDefaults( |
19 | options, OpenLayers.Protocol.WFS.DEFAULTS |
20 | ); |
21 | var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")]; |
22 | if(!cls) { |
23 | throw "Unsupported WFS version: " + options.version; |
24 | } |
25 | return new cls(options); |
26 | }; |
27 | |
28 | /** |
29 | * Function: OpenLayers.Protocol.WFS.fromWMSLayer |
30 | * Convenience function to create a WFS protocol from a WMS layer. This makes |
31 | * the assumption that a WFS requests can be issued at the same URL as |
32 | * WMS requests and that a WFS featureType exists with the same name as the |
33 | * WMS layer. |
34 | * |
35 | * This function is designed to auto-configure <url>, <featureType>, |
36 | * <featurePrefix> and <srsName> for WFS <version> 1.1.0. Note that |
37 | * srsName matching with the WMS layer will not work with WFS 1.0.0.. |
38 | * |
39 | * Parameters: |
40 | * layer - {<OpenLayers.Layer.WMS>} WMS layer that has a matching WFS |
41 | * FeatureType at the same server url with the same typename. |
42 | * options - {Object} Default properties to be set on the protocol. |
43 | * |
44 | */ |
45 | OpenLayers.Protocol.WFS.fromWMSLayer = function(layer, options) { |
46 | var typeName, featurePrefix; |
47 | var param = layer.params["LAYERS"]; |
48 | var parts = (param instanceof Array ? param[0] : param).split(":"); |
49 | if(parts.length > 1) { |
50 | featurePrefix = parts[0]; |
51 | } |
52 | typeName = parts.pop(); |
53 | var protocolOptions = { |
54 | url: layer.url, |
55 | featureType: typeName, |
56 | featurePrefix: featurePrefix, |
57 | srsName: layer.projection && layer.projection.getCode() || |
58 | layer.map && layer.map.getProjectionObject().getCode(), |
59 | version: "1.1.0" |
60 | }; |
61 | return new OpenLayers.Protocol.WFS(OpenLayers.Util.applyDefaults( |
62 | options, protocolOptions |
63 | )); |
64 | }; |
65 | |
66 | /** |
67 | * Constant: OpenLayers.Protocol.WFS.DEFAULTS |
68 | */ |
69 | OpenLayers.Protocol.WFS.DEFAULTS = { |
70 | "version": "1.0.0" |
71 | }; |
Note: See TracBrowser
for help on using the repository browser.