1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
/**
|
7
|
* @requires OpenLayers/Protocol.js
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Class: 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
|
* Example:
|
18
|
* (code)
|
19
|
* var protocol = new OpenLayers.Protocol.WFS({
|
20
|
* version: "1.1.0",
|
21
|
* url: "http://demo.opengeo.org/geoserver/wfs",
|
22
|
* featureType: "tasmania_roads",
|
23
|
* featureNS: "http://www.openplans.org/topp",
|
24
|
* geometryName: "the_geom"
|
25
|
* });
|
26
|
* (end)
|
27
|
*
|
28
|
* See the protocols for specific WFS versions for more detail.
|
29
|
*/
|
30
|
OpenLayers.Protocol.WFS = function(options) {
|
31
|
options = OpenLayers.Util.applyDefaults(
|
32
|
options, OpenLayers.Protocol.WFS.DEFAULTS
|
33
|
);
|
34
|
var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")];
|
35
|
if(!cls) {
|
36
|
throw "Unsupported WFS version: " + options.version;
|
37
|
}
|
38
|
return new cls(options);
|
39
|
};
|
40
|
|
41
|
/**
|
42
|
* Function: fromWMSLayer
|
43
|
* Convenience function to create a WFS protocol from a WMS layer. This makes
|
44
|
* the assumption that a WFS requests can be issued at the same URL as
|
45
|
* WMS requests and that a WFS featureType exists with the same name as the
|
46
|
* WMS layer.
|
47
|
*
|
48
|
* This function is designed to auto-configure <url>, <featureType>,
|
49
|
* <featurePrefix> and <srsName> for WFS <version> 1.1.0. Note that
|
50
|
* srsName matching with the WMS layer will not work with WFS 1.0.0.
|
51
|
*
|
52
|
* Parameters:
|
53
|
* layer - {<OpenLayers.Layer.WMS>} WMS layer that has a matching WFS
|
54
|
* FeatureType at the same server url with the same typename.
|
55
|
* options - {Object} Default properties to be set on the protocol.
|
56
|
*
|
57
|
* Returns:
|
58
|
* {<OpenLayers.Protocol.WFS>}
|
59
|
*/
|
60
|
OpenLayers.Protocol.WFS.fromWMSLayer = function(layer, options) {
|
61
|
var typeName, featurePrefix;
|
62
|
var param = layer.params["LAYERS"];
|
63
|
var parts = (OpenLayers.Util.isArray(param) ? param[0] : param).split(":");
|
64
|
if(parts.length > 1) {
|
65
|
featurePrefix = parts[0];
|
66
|
}
|
67
|
typeName = parts.pop();
|
68
|
var protocolOptions = {
|
69
|
url: layer.url,
|
70
|
featureType: typeName,
|
71
|
featurePrefix: featurePrefix,
|
72
|
srsName: layer.projection && layer.projection.getCode() ||
|
73
|
layer.map && layer.map.getProjectionObject().getCode(),
|
74
|
version: "1.1.0"
|
75
|
};
|
76
|
return new OpenLayers.Protocol.WFS(OpenLayers.Util.applyDefaults(
|
77
|
options, protocolOptions
|
78
|
));
|
79
|
};
|
80
|
|
81
|
/**
|
82
|
* Constant: OpenLayers.Protocol.WFS.DEFAULTS
|
83
|
*/
|
84
|
OpenLayers.Protocol.WFS.DEFAULTS = {
|
85
|
"version": "1.0.0"
|
86
|
};
|