Adding a WFS protocol. This allows for creating, reading, updating, and deleting features via WFS. Huge thanks to ahocevar for the test writing and review. r=ahocevar (closes #1648)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8868 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
197
examples/wfs-protocol-transactions.html
Normal file
197
examples/wfs-protocol-transactions.html
Normal file
@@ -0,0 +1,197 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
|
||||
<link rel="stylesheet" href="style.css" type="text/css" />
|
||||
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAbs-AXzXTiUE-iwvdTFv0TRTJUVlep-V_kcHWKMoAW7P0KYzoHRSbTZ4mBasJApBqjm2Vnrs7dKOYJg'></script>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<style>
|
||||
.customEditingToolbar {
|
||||
float: right;
|
||||
right: 0px;
|
||||
height: 30px;
|
||||
width: 200px;
|
||||
}
|
||||
.customEditingToolbar div {
|
||||
float: right;
|
||||
margin: 5px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
.olControlNavigationItemActive {
|
||||
background-image: url("../theme/default/img/editing_tool_bar.png");
|
||||
background-repeat: no-repeat;
|
||||
background-position: -103px -23px;
|
||||
}
|
||||
.olControlNavigationItemInactive {
|
||||
background-image: url("../theme/default/img/editing_tool_bar.png");
|
||||
background-repeat: no-repeat;
|
||||
background-position: -103px -0px;
|
||||
}
|
||||
.olControlDrawFeaturePolygonItemInactive {
|
||||
background-image: url("../theme/default/img/editing_tool_bar.png");
|
||||
background-repeat: no-repeat;
|
||||
background-position: -26px 0px;
|
||||
}
|
||||
.olControlDrawFeaturePolygonItemActive {
|
||||
background-image: url("../theme/default/img/editing_tool_bar.png");
|
||||
background-repeat: no-repeat;
|
||||
background-position: -26px -23px ;
|
||||
}
|
||||
.olControlModifyFeatureItemActive {
|
||||
background-image: url(../theme/default/img/move_feature_on.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0px 1px;
|
||||
}
|
||||
.olControlModifyFeatureItemInactive {
|
||||
background-image: url(../theme/default/img/move_feature_off.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0px 1px;
|
||||
}
|
||||
.olControlDeleteFeatureItemActive {
|
||||
background-image: url(../theme/default/img/remove_point_on.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0px 1px;
|
||||
}
|
||||
.olControlDeleteFeatureItemInactive {
|
||||
background-image: url(../theme/default/img/remove_point_off.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0px 1px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var map, wfs;
|
||||
|
||||
var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
initialize: function(layer, options) {
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.layer = layer;
|
||||
this.handler = new OpenLayers.Handler.Feature(
|
||||
this, layer, {click: this.clickFeature}
|
||||
);
|
||||
},
|
||||
clickFeature: function(feature) {
|
||||
// if feature doesn't have a fid, destroy it
|
||||
if(feature.fid == undefined) {
|
||||
this.layer.destroyFeatures([feature]);
|
||||
} else {
|
||||
feature.state = OpenLayers.State.DELETE;
|
||||
this.layer.events.triggerEvent("afterfeaturemodified",
|
||||
{feature: feature});
|
||||
feature.renderIntent = "select";
|
||||
this.layer.drawFeature(feature);
|
||||
}
|
||||
},
|
||||
setMap: function(map) {
|
||||
this.handler.setMap(map);
|
||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||
},
|
||||
CLASS_NAME: "OpenLayers.Control.DeleteFeature"
|
||||
});
|
||||
|
||||
function init() {
|
||||
OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url=";
|
||||
map = new OpenLayers.Map('map', {
|
||||
projection: new OpenLayers.Projection("EPSG:900913"),
|
||||
displayProjection: new OpenLayers.Projection("EPSG:4326"),
|
||||
units: "m",
|
||||
maxResolution: 156543.0339,
|
||||
maxExtent: new OpenLayers.Bounds(
|
||||
-11593508, 5509847, -11505759, 5557774
|
||||
),
|
||||
controls: [
|
||||
new OpenLayers.Control.PanZoom()
|
||||
]
|
||||
});
|
||||
var gphy = new OpenLayers.Layer.Google(
|
||||
"Google Physical",
|
||||
{type: G_PHYSICAL_MAP, sphericalMercator: true}
|
||||
);
|
||||
|
||||
var saveStrategy = new OpenLayers.Strategy.Save();
|
||||
|
||||
wfs = new OpenLayers.Layer.Vector("Editable Features", {
|
||||
strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
|
||||
projection: new OpenLayers.Projection("EPSG:4326"),
|
||||
protocol: new OpenLayers.Protocol.WFS({
|
||||
version: "1.1.0",
|
||||
srsName: "EPSG:4326",
|
||||
url: "http://demo.opengeo.org/geoserver/wfs",
|
||||
featureNS : "http://www.openplans.org/spearfish",
|
||||
featureType: "restricted",
|
||||
geometryName: "the_geom",
|
||||
schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=sf:restricted"
|
||||
})
|
||||
});
|
||||
|
||||
map.addLayers([gphy, wfs]);
|
||||
|
||||
var panel = new OpenLayers.Control.Panel(
|
||||
{'displayClass': 'customEditingToolbar'}
|
||||
);
|
||||
|
||||
var navigate = new OpenLayers.Control.Navigation({
|
||||
title: "Pan Map",
|
||||
});
|
||||
|
||||
var draw = new OpenLayers.Control.DrawFeature(
|
||||
wfs, OpenLayers.Handler.Polygon,
|
||||
{
|
||||
title: "Draw Feature",
|
||||
displayClass: "olControlDrawFeaturePolygon",
|
||||
handlerOptions: {multi: true}
|
||||
}
|
||||
);
|
||||
|
||||
var edit = new OpenLayers.Control.ModifyFeature(wfs, {
|
||||
title: "Modify Feature",
|
||||
displayClass: "olControlModifyFeature",
|
||||
});
|
||||
|
||||
var del = new DeleteFeature(wfs, {title: "Delete Feature"});
|
||||
|
||||
var save = new OpenLayers.Control.Button({
|
||||
title: "Save Changes",
|
||||
trigger: function() {
|
||||
if(edit.feature) {
|
||||
edit.selectControl.unselectAll();
|
||||
}
|
||||
saveStrategy.save();
|
||||
},
|
||||
displayClass: "olControlSaveFeatures"
|
||||
});
|
||||
|
||||
panel.addControls([navigate, save, del, edit, draw]);
|
||||
panel.defaultControl = navigate;
|
||||
map.addControl(panel);
|
||||
map.zoomToMaxExtent();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
|
||||
<h1 id="title">WFS Transaction Example</h1>
|
||||
|
||||
<div id="tags">
|
||||
</div>
|
||||
<p id="shortdesc">
|
||||
Shows the use of the WFS Transactions (WFS-T).
|
||||
</p>
|
||||
|
||||
<div id="map" class="smallmap"></div>
|
||||
|
||||
<div id="docs">
|
||||
<p>The WFS protocol allows for creation of new features and reading,
|
||||
updating, or deleting of existing features.</p>
|
||||
<p>Use the tools to create, modify, and delete (in order from left
|
||||
to right) features. Use the save tool (picture of a disk) to
|
||||
save your changes. Use the navigation tool (hand) to stop editing
|
||||
and use the mouse for map navigation.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
48
examples/wfs-protocol.html
Normal file
48
examples/wfs-protocol.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>OpenLayers Vector Behavior Example</title>
|
||||
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
|
||||
<link rel="stylesheet" href="style.css" type="text/css" />
|
||||
<script src="../lib/Firebug/firebug.js"></script>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
var map;
|
||||
|
||||
function init() {
|
||||
OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url=";
|
||||
map = new OpenLayers.Map('map');
|
||||
var wms = new OpenLayers.Layer.WMS(
|
||||
"OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'}
|
||||
);
|
||||
|
||||
var layer = new OpenLayers.Layer.Vector("WFS", {
|
||||
strategies: [new OpenLayers.Strategy.BBOX()],
|
||||
protocol: new OpenLayers.Protocol.WFS({
|
||||
url: "http://publicus.opengeo.org/geoserver/wfs",
|
||||
featureType: "tasmania_roads",
|
||||
featureNS: "http://www.openplans.org/topp"
|
||||
}),
|
||||
});
|
||||
|
||||
map.addLayers([wms, layer]);
|
||||
map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1 id="title">Vector Behavior Example</h1>
|
||||
<p id="shortdesc">
|
||||
Uses a BBOX strategy, WFS protocol, and GML format.
|
||||
</p>
|
||||
<div id="map" class="smallmap"></div>
|
||||
<div id="docs">
|
||||
<p>The vector layer shown uses the BBOX strategy, the WFS protocol,
|
||||
and the GML format. The BBOX strategy fetches features within a
|
||||
bounding box. When the map bounds invalidate the data bounds,
|
||||
another request is triggered. The WFS protocol gets features
|
||||
through a WFS request. The GML format is used to serialize
|
||||
features.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -193,6 +193,10 @@
|
||||
"OpenLayers/Protocol/HTTP.js",
|
||||
"OpenLayers/Protocol/SQL.js",
|
||||
"OpenLayers/Protocol/SQL/Gears.js",
|
||||
"OpenLayers/Protocol/WFS.js",
|
||||
"OpenLayers/Protocol/WFS/v1.js",
|
||||
"OpenLayers/Protocol/WFS/v1_0_0.js",
|
||||
"OpenLayers/Protocol/WFS/v1_1_0.js",
|
||||
"OpenLayers/Layer/PointTrack.js",
|
||||
"OpenLayers/Layer/GML.js",
|
||||
"OpenLayers/Style.js",
|
||||
@@ -224,6 +228,10 @@
|
||||
"OpenLayers/Format/SLD/v1.js",
|
||||
"OpenLayers/Format/SLD/v1_0_0.js",
|
||||
"OpenLayers/Format/SLD/v1.js",
|
||||
"OpenLayers/Format/WFST.js",
|
||||
"OpenLayers/Format/WFST/v1.js",
|
||||
"OpenLayers/Format/WFST/v1_0_0.js",
|
||||
"OpenLayers/Format/WFST/v1_1_0.js",
|
||||
"OpenLayers/Format/Text.js",
|
||||
"OpenLayers/Format/JSON.js",
|
||||
"OpenLayers/Format/GeoJSON.js",
|
||||
|
||||
29
lib/OpenLayers/Format/WFST.js
Normal file
29
lib/OpenLayers/Format/WFST.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @requires OpenLayers/Format.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function: OpenLayers.Format.WFST
|
||||
* Used to create a versioned WFS protocol. Default version is 1.0.0.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Format>} A WFST format of the given version.
|
||||
*/
|
||||
OpenLayers.Format.WFST = function(options) {
|
||||
options = OpenLayers.Util.applyDefaults(
|
||||
options, OpenLayers.Format.WFST.DEFAULTS
|
||||
);
|
||||
var cls = OpenLayers.Format.WFST["v"+options.version.replace(/\./g, "_")];
|
||||
if(!cls) {
|
||||
throw "Unsupported WFST version: " + options.version;
|
||||
}
|
||||
return new cls(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Format.WFST.DEFAULTS
|
||||
* {Object} Default properties for the WFST format.
|
||||
*/
|
||||
OpenLayers.Format.WFST.DEFAULTS = {
|
||||
"version": "1.0.0"
|
||||
};
|
||||
373
lib/OpenLayers/Format/WFST/v1.js
Normal file
373
lib/OpenLayers/Format/WFST/v1.js
Normal file
@@ -0,0 +1,373 @@
|
||||
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Format/XML.js
|
||||
* @requires OpenLayers/Format/WFST.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WFST.v1
|
||||
* Superclass for WFST parsers.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
xlink: "http://www.w3.org/1999/xlink",
|
||||
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
||||
wfs: "http://www.opengis.net/wfs",
|
||||
gml: "http://www.opengis.net/gml",
|
||||
ogc: "http://www.opengis.net/ogc"
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
*/
|
||||
defaultPrefix: "wfs",
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: null,
|
||||
|
||||
/**
|
||||
* Property: schemaLocation
|
||||
* {String} Schema location for a particular minor version.
|
||||
*/
|
||||
schemaLocations: null,
|
||||
|
||||
/**
|
||||
* APIProperty: srsName
|
||||
* {String} URI for spatial reference system.
|
||||
*/
|
||||
srsName: null,
|
||||
|
||||
/**
|
||||
* APIProperty: extractAttributes
|
||||
* {Boolean} Extract attributes from GML. Default is true.
|
||||
*/
|
||||
extractAttributes: true,
|
||||
|
||||
/**
|
||||
* APIProperty: xy
|
||||
* {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x)
|
||||
* Changing is not recommended, a new Format should be instantiated.
|
||||
*/
|
||||
xy: true,
|
||||
|
||||
/**
|
||||
* Property: stateName
|
||||
* {Object} Maps feature states to node names.
|
||||
*/
|
||||
stateName: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WFST.v1
|
||||
* Instances of this class are not created directly. Use the
|
||||
* <OpenLayers.Format.WFST.v1_0_0> or <OpenLayers.Format.WFST.v1_1_0>
|
||||
* constructor instead.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
if(options.featureNS) {
|
||||
this.namespaces = OpenLayers.Util.extend(
|
||||
{feature: options.featureNS},
|
||||
OpenLayers.Format.WFST.v1.prototype.namespaces
|
||||
);
|
||||
}
|
||||
// set state name mapping
|
||||
this.stateName = {};
|
||||
this.stateName[OpenLayers.State.INSERT] = "wfs:Insert";
|
||||
this.stateName[OpenLayers.State.UPDATE] = "wfs:Update";
|
||||
this.stateName[OpenLayers.State.DELETE] = "wfs:Delete";
|
||||
// extend format with misc properties from filter and gml formats
|
||||
var filterProto = OpenLayers.Format.Filter.v1.prototype;
|
||||
var gmlProto = OpenLayers.Format.GML.Base.prototype;
|
||||
OpenLayers.Util.extend(this, {
|
||||
readOgcExpression: filterProto.readOgcExpression,
|
||||
getFilterType: filterProto.getFilterType,
|
||||
filterMap: filterProto.filterMap,
|
||||
regExes: gmlProto.regExes
|
||||
});
|
||||
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getSrsName
|
||||
*/
|
||||
getSrsName: function(feature, options) {
|
||||
var srsName = options && options.srsName;
|
||||
if(!srsName) {
|
||||
if(feature && feature.layer) {
|
||||
srsName = feature.layer.projection.getCode();
|
||||
} else {
|
||||
srsName = this.srsName;
|
||||
}
|
||||
}
|
||||
return srsName;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: read
|
||||
* Parse the response from a transaction. Because WFS is split into
|
||||
* Transaction requests (create, update, and delete) and GetFeature
|
||||
* requests (read), this method handles parsing of both types of
|
||||
* responses.
|
||||
*/
|
||||
read: function(data) {
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
if(data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
if(obj.features) {
|
||||
obj = obj.features;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"wfs": {
|
||||
"FeatureCollection": function(node, obj) {
|
||||
obj.features = [];
|
||||
this.readChildNodes(node, obj);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: write
|
||||
* Given an array of features, write a WFS transaction. This assumes
|
||||
* the features have a state property that determines the operation
|
||||
* type - insert, update, or delete.
|
||||
*
|
||||
* Parameters:
|
||||
* features - {Array(<OpenLayers.Feature.Vector>)} A list of features.
|
||||
*
|
||||
* Returns:
|
||||
* {String} A serialized WFS transaction.
|
||||
*/
|
||||
write: function(features) {
|
||||
var node = this.writeNode("wfs:Transaction", features);
|
||||
var value = this.schemaLocationAttr();
|
||||
if(value) {
|
||||
this.setAttributeNS(
|
||||
node, this.namespaces["xsi"], "xsi:schemaLocation", value
|
||||
)
|
||||
}
|
||||
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: writers
|
||||
* As a compliment to the readers property, this structure contains public
|
||||
* writing functions grouped by namespace alias and named like the
|
||||
* node names they produce.
|
||||
*/
|
||||
writers: {
|
||||
"wfs": {
|
||||
"GetFeature": function(options) {
|
||||
var node = this.createElementNSPlus("wfs:GetFeature", {
|
||||
attributes: {
|
||||
service: "WFS",
|
||||
version: this.version,
|
||||
maxFeatures: options && options.maxFeatures,
|
||||
"xsi:schemaLocation": this.schemaLocationAttr(options)
|
||||
}
|
||||
});
|
||||
this.writeNode("Query", options, node);
|
||||
return node;
|
||||
},
|
||||
"Query": function(options) {
|
||||
options = OpenLayers.Util.extend({
|
||||
featureNS: this.featureNS,
|
||||
featurePrefix: this.featurePrefix,
|
||||
featureType: this.featureType,
|
||||
srsName: this.srsName
|
||||
}, options);
|
||||
// TODO: this is still version specific and should be separated out
|
||||
// v1.0.0 does not allow srsName on wfs:Query
|
||||
var node = this.createElementNSPlus("wfs:Query", {
|
||||
attributes: {
|
||||
typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
|
||||
options.featureType,
|
||||
srsName: options.srsName
|
||||
}
|
||||
});
|
||||
if(options.featureNS) {
|
||||
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
||||
}
|
||||
if(options.filter) {
|
||||
this.setFilterProperty(options.filter);
|
||||
this.writeNode("ogc:Filter", options.filter, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Transaction": function(features) {
|
||||
var node = this.createElementNSPlus("wfs:Transaction", {
|
||||
attributes: {
|
||||
service: "WFS",
|
||||
version: this.version
|
||||
}
|
||||
});
|
||||
if(features) {
|
||||
var name, feature;
|
||||
for(var i=0, len=features.length; i<len; ++i) {
|
||||
feature = features[i];
|
||||
name = this.stateName[feature.state];
|
||||
if(name) {
|
||||
this.writeNode(name, feature, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Insert": function(feature) {
|
||||
var node = this.createElementNSPlus("wfs:Insert");
|
||||
this.srsName = this.getSrsName(feature);
|
||||
this.writeNode("feature:_typeName", feature, node);
|
||||
return node;
|
||||
},
|
||||
"Update": function(feature) {
|
||||
var node = this.createElementNSPlus("wfs:Update", {
|
||||
attributes: {
|
||||
typeName: (this.featureNS ? this.featurePrefix + ":" : "") +
|
||||
this.featureType
|
||||
}
|
||||
});
|
||||
if(this.featureNS) {
|
||||
node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS);
|
||||
}
|
||||
|
||||
// add in geometry
|
||||
this.writeNode(
|
||||
"Property", {name: this.geometryName, value: feature}, node
|
||||
);
|
||||
|
||||
// add in attributes
|
||||
for(var key in feature.attributes) {
|
||||
this.writeNode(
|
||||
"Property", {name: key, value: feature.attributes[key]}, node
|
||||
);
|
||||
}
|
||||
|
||||
// add feature id filter
|
||||
this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({
|
||||
fids: [feature.fid]
|
||||
}), node);
|
||||
|
||||
return node;
|
||||
},
|
||||
"Property": function(obj) {
|
||||
var node = this.createElementNSPlus("wfs:Property");
|
||||
this.writeNode("Name", obj.name, node);
|
||||
this.writeNode("Value", obj.value, node);
|
||||
return node;
|
||||
},
|
||||
"Name": function(name) {
|
||||
return this.createElementNSPlus("wfs:Name", {value: name});
|
||||
},
|
||||
"Value": function(obj) {
|
||||
var node;
|
||||
if(obj instanceof OpenLayers.Feature.Vector) {
|
||||
node = this.createElementNSPlus("wfs:Value");
|
||||
this.srsName = this.getSrsName(obj);
|
||||
var geom = this.writeNode("feature:_geometry", obj.geometry).firstChild;
|
||||
node.appendChild(geom);
|
||||
} else {
|
||||
node = this.createElementNSPlus("wfs:Value", {value: obj});
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Delete": function(feature) {
|
||||
var node = this.createElementNSPlus("wfs:Delete", {
|
||||
attributes: {
|
||||
typeName: (this.featureNS ? this.featurePrefix + ":" : "") +
|
||||
this.featureType
|
||||
}
|
||||
});
|
||||
if(this.featureNS) {
|
||||
node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS);
|
||||
}
|
||||
this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({
|
||||
fids: [feature.fid]
|
||||
}), node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: schemaLocationAttr
|
||||
* Generate the xsi:schemaLocation attribute value.
|
||||
*
|
||||
* Returns:
|
||||
* {String} The xsi:schemaLocation attribute or undefined if none.
|
||||
*/
|
||||
schemaLocationAttr: function(options) {
|
||||
options = OpenLayers.Util.extend({
|
||||
featurePrefix: this.featurePrefix,
|
||||
schema: this.schema
|
||||
}, options);
|
||||
var schemaLocations = OpenLayers.Util.extend({}, this.schemaLocations);
|
||||
if(options.schema) {
|
||||
schemaLocations[options.featurePrefix] = options.schema;
|
||||
}
|
||||
var parts = [];
|
||||
var uri;
|
||||
for(var key in schemaLocations) {
|
||||
uri = this.namespaces[key];
|
||||
if(uri) {
|
||||
parts.push(uri + " " + schemaLocations[key]);
|
||||
}
|
||||
}
|
||||
var value = parts.join(" ") || undefined;
|
||||
return value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: setFilterProperty
|
||||
* Set the property of each spatial filter.
|
||||
*
|
||||
* Parameters:
|
||||
* filter - {<OpenLayers.Filter>}
|
||||
*/
|
||||
setFilterProperty: function(filter) {
|
||||
if(filter.filters) {
|
||||
for(var i=0, len=filter.filters.length; i<len; ++i) {
|
||||
this.setFilterProperty(filter.filters[i]);
|
||||
}
|
||||
} else {
|
||||
if(filter instanceof OpenLayers.Filter.Spatial) {
|
||||
// got a spatial filter, set its property
|
||||
filter.property = this.geometryName;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WFST.v1"
|
||||
|
||||
});
|
||||
123
lib/OpenLayers/Format/WFST/v1_0_0.js
Normal file
123
lib/OpenLayers/Format/WFST/v1_0_0.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @requires OpenLayers/Format/WFST/v1.js
|
||||
* @requires OpenLayers/Format/GML/v2.js
|
||||
* @requires OpenLayers/Format/Filter/v1_0_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WFST.v1_0_0
|
||||
* A format for creating WFS v1.0.0 transactions. Create a new instance with the
|
||||
* <OpenLayers.Format.WFST.v1_0_0> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.WFST.v1>
|
||||
*/
|
||||
OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(OpenLayers.Format.WFST.v1, {
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: "1.0.0",
|
||||
|
||||
/**
|
||||
* Property: schemaLocations
|
||||
* {Object} Properties are namespace aliases, values are schema locations.
|
||||
*/
|
||||
schemaLocations: {
|
||||
"wfs": "http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd"
|
||||
},
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WFST.v1_0_0
|
||||
* A class for parsing and generating WFS v1.0.0 transactions.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* instance.
|
||||
*
|
||||
* Valid options properties:
|
||||
* featureType - {String} Local (without prefix) feature typeName (required).
|
||||
* featureNS - {String} Feature namespace (optional).
|
||||
* featurePrefix - {String} Feature namespace alias (optional - only used
|
||||
* if featureNS is provided). Default is 'feature'.
|
||||
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]);
|
||||
OpenLayers.Format.GML.v2.prototype.setGeometryTypes.call(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"wfs": OpenLayers.Util.applyDefaults({
|
||||
"WFS_TransactionResponse": function(node, obj) {
|
||||
obj.insertIds = [];
|
||||
obj.success = false;
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"InsertResult": function(node, container) {
|
||||
var obj = {fids: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.insertIds.push(obj.fids[0]);
|
||||
},
|
||||
"TransactionResult": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Status": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"SUCCESS": function(node, obj) {
|
||||
obj.success = true;
|
||||
}
|
||||
}, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]),
|
||||
"gml": OpenLayers.Format.GML.v2.prototype.readers["gml"],
|
||||
"feature": OpenLayers.Format.GML.v2.prototype.readers["feature"],
|
||||
"ogc": OpenLayers.Format.Filter.v1_0_0.prototype.readers["ogc"]
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: writers
|
||||
* As a compliment to the readers property, this structure contains public
|
||||
* writing functions grouped by namespace alias and named like the
|
||||
* node names they produce.
|
||||
*/
|
||||
writers: {
|
||||
"wfs": OpenLayers.Util.applyDefaults({
|
||||
"Query": function(options) {
|
||||
options = OpenLayers.Util.extend({
|
||||
featureNS: this.featureNS,
|
||||
featurePrefix: this.featurePrefix,
|
||||
featureType: this.featureType,
|
||||
srsName: this.srsName
|
||||
}, options);
|
||||
var node = this.createElementNSPlus("wfs:Query", {
|
||||
attributes: {
|
||||
typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
|
||||
options.featureType
|
||||
}
|
||||
});
|
||||
if(options.featureNS) {
|
||||
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
||||
}
|
||||
if(options.filter) {
|
||||
this.setFilterProperty(options.filter);
|
||||
this.writeNode("ogc:Filter", options.filter, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
|
||||
"gml": OpenLayers.Format.GML.v2.prototype.writers["gml"],
|
||||
"feature": OpenLayers.Format.GML.v2.prototype.writers["feature"],
|
||||
"ogc": OpenLayers.Format.Filter.v1_0_0.prototype.writers["ogc"]
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WFST.v1_0_0"
|
||||
});
|
||||
122
lib/OpenLayers/Format/WFST/v1_1_0.js
Normal file
122
lib/OpenLayers/Format/WFST/v1_1_0.js
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* @requires OpenLayers/Format/WFST/v1.js
|
||||
* @requires OpenLayers/Format/GML/v3.js
|
||||
* @requires OpenLayers/Format/Filter/v1_1_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WFST.v1_1_0
|
||||
* A format for creating WFS v1.1.0 transactions. Create a new instance with the
|
||||
* <OpenLayers.Format.WFST.v1_1_0> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.WFST.v1>
|
||||
*/
|
||||
OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(OpenLayers.Format.WFST.v1, {
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: "1.1.0",
|
||||
|
||||
/**
|
||||
* Property: schemaLocations
|
||||
* {Object} Properties are namespace aliases, values are schema locations.
|
||||
*/
|
||||
schemaLocations: {
|
||||
"wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
|
||||
},
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WFST.v1_1_0
|
||||
* A class for parsing and generating WFS v1.1.0 transactions.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* instance.
|
||||
*
|
||||
* Valid options properties:
|
||||
* featureType - {String} Local (without prefix) feature typeName (required).
|
||||
* featureNS - {String} Feature namespace (optional).
|
||||
* featurePrefix - {String} Feature namespace alias (optional - only used
|
||||
* if featureNS is provided). Default is 'feature'.
|
||||
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]);
|
||||
OpenLayers.Format.GML.v3.prototype.setGeometryTypes.call(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"wfs": OpenLayers.Util.applyDefaults({
|
||||
"TransactionResponse": function(node, obj) {
|
||||
obj.insertIds = [];
|
||||
obj.success = false;
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"TransactionSummary": function(node, obj) {
|
||||
// this is a limited test of success
|
||||
obj.success = true;
|
||||
},
|
||||
"InsertResults": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Feature": function(node, container) {
|
||||
var obj = {fids: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.insertIds.push(obj.fids[0]);
|
||||
}
|
||||
}, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]),
|
||||
"gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
|
||||
"feature": OpenLayers.Format.GML.v3.prototype.readers["feature"],
|
||||
"ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"]
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: writers
|
||||
* As a compliment to the readers property, this structure contains public
|
||||
* writing functions grouped by namespace alias and named like the
|
||||
* node names they produce.
|
||||
*/
|
||||
writers: {
|
||||
"wfs": OpenLayers.Util.applyDefaults({
|
||||
"Query": function(options) {
|
||||
options = OpenLayers.Util.extend({
|
||||
featureNS: this.featureNS,
|
||||
featurePrefix: this.featurePrefix,
|
||||
featureType: this.featureType,
|
||||
srsName: this.srsName
|
||||
}, options);
|
||||
var node = this.createElementNSPlus("wfs:Query", {
|
||||
attributes: {
|
||||
typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
|
||||
options.featureType,
|
||||
srsName: options.srsName
|
||||
}
|
||||
});
|
||||
if(options.featureNS) {
|
||||
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
||||
}
|
||||
if(options.filter) {
|
||||
this.setFilterProperty(options.filter);
|
||||
this.writeNode("ogc:Filter", options.filter, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
|
||||
"gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
|
||||
"feature": OpenLayers.Format.GML.v3.prototype.writers["feature"],
|
||||
"ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"]
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0"
|
||||
});
|
||||
28
lib/OpenLayers/Protocol/WFS.js
Normal file
28
lib/OpenLayers/Protocol/WFS.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @requires OpenLayers/Protocol.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function: OpenLayers.Protocol.WFS
|
||||
* Used to create a versioned WFS protocol. Default version is 1.0.0.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Protocol>} A WFS protocol of the given version.
|
||||
*/
|
||||
OpenLayers.Protocol.WFS = function(options) {
|
||||
options = OpenLayers.Util.applyDefaults(
|
||||
options, OpenLayers.Protocol.WFS.DEFAULTS
|
||||
);
|
||||
var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")];
|
||||
if(!cls) {
|
||||
throw "Unsupported WFS version: " + options.version;
|
||||
}
|
||||
return new cls(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Protocol.WFS.DEFAULTS
|
||||
*/
|
||||
OpenLayers.Protocol.WFS.DEFAULTS = {
|
||||
"version": "1.0.0"
|
||||
};
|
||||
328
lib/OpenLayers/Protocol/WFS/v1.js
Normal file
328
lib/OpenLayers/Protocol/WFS/v1.js
Normal file
@@ -0,0 +1,328 @@
|
||||
/**
|
||||
* @requires OpenLayers/Protocol/WFS.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Protocol.WFS.v1
|
||||
* Abstract class for for v1.0.0 and v1.1.0 protocol.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Protocol>
|
||||
*/
|
||||
OpenLayers.Protocol.WFS.v1 = new OpenLayers.Class(OpenLayers.Protocol, {
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: null,
|
||||
|
||||
/**
|
||||
* Property: srsName
|
||||
* {String} Name of spatial reference system. Default is "EPSG:4326".
|
||||
*/
|
||||
srsName: "EPSG:4326",
|
||||
|
||||
/**
|
||||
* Property: featureType
|
||||
* {String} Local feature typeName.
|
||||
*/
|
||||
featureType: null,
|
||||
|
||||
/**
|
||||
* Property: featureNS
|
||||
* {String} Feature namespace.
|
||||
*/
|
||||
featureNS: null,
|
||||
|
||||
/**
|
||||
* Property: geometryName
|
||||
* {String} Name of the geometry attribute for features. Default is
|
||||
* "the_geom".
|
||||
*/
|
||||
geometryName: "the_geom",
|
||||
|
||||
/**
|
||||
* Property: schema
|
||||
* {String} Optional schema location that will be included in the
|
||||
* schemaLocation attribute value. Note that the feature type schema
|
||||
* is required for a strict XML validator (on transactions with an
|
||||
* insert for example), but is *not* required by the WFS specification
|
||||
* (since the server is supposed to know about feature type schemas).
|
||||
*/
|
||||
schema: null,
|
||||
|
||||
/**
|
||||
* Property: featurePrefix
|
||||
* {String} Namespace alias for feature type. Default is "feature".
|
||||
*/
|
||||
featurePrefix: "feature",
|
||||
|
||||
/**
|
||||
* Property: formatOptions
|
||||
* {Object} Optional options for the format. If a format is not provided,
|
||||
* this property can be used to extend the default format options.
|
||||
*/
|
||||
formatOptions: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Protocol.WFS
|
||||
* A class for giving layers WFS protocol.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* instance.
|
||||
*
|
||||
* Valid options properties:
|
||||
* url - {String} URL to send requests to (required).
|
||||
* featureType - {String} Local (without prefix) feature typeName (required).
|
||||
* featureNS - {String} Feature namespace (required, but can be autodetected
|
||||
* for reading if featurePrefix is provided and identical to the prefix
|
||||
* in the server response).
|
||||
* featurePrefix - {String} Feature namespace alias (optional - only used
|
||||
* for writing if featureNS is provided). Default is 'feature'.
|
||||
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
|
||||
if(!options.format) {
|
||||
this.format = OpenLayers.Format.WFST(OpenLayers.Util.extend({
|
||||
version: this.version,
|
||||
featureType: this.featureType,
|
||||
featureNS: this.featureNS,
|
||||
featurePrefix: this.featurePrefix,
|
||||
geometryName: this.geometryName,
|
||||
srsName: this.srsName,
|
||||
schema: this.schema
|
||||
}, this.formatOptions));
|
||||
}
|
||||
if(!this.featureNS) {
|
||||
// featureNS autodetection
|
||||
var readNode = this.format.readNode;
|
||||
this.format.readNode = function(node, obj) {
|
||||
if(!this.featureNS && node.prefix == this.featurePrefix) {
|
||||
this.featureNS = node.namespaceURI;
|
||||
this.setNamespace("feature", this.featureNS);
|
||||
}
|
||||
return readNode.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* Clean up the protocol.
|
||||
*/
|
||||
destroy: function() {
|
||||
if(this.options && !this.options.format) {
|
||||
this.format.destroy();
|
||||
}
|
||||
this.format = null;
|
||||
OpenLayers.Protocol.prototype.destroy.apply(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createCallback
|
||||
* Returns a function that applies the given public method with resp and
|
||||
* options arguments.
|
||||
*
|
||||
* Parameters:
|
||||
* method - {Function} The method to be applied by the callback.
|
||||
* response - {<OpenLayers.Protocol.Response>} The protocol response object.
|
||||
* options - {Object} Options sent to the protocol method (read, create,
|
||||
* update, or delete).
|
||||
*/
|
||||
createCallback: function(method, response, options) {
|
||||
return OpenLayers.Function.bind(function() {
|
||||
method.apply(this, [response, options]);
|
||||
}, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: read
|
||||
* Construct a request for reading new features. Since WFS splits the
|
||||
* basic CRUD operations into GetFeature requests (for read) and
|
||||
* Transactions (for all others), this method does not make use of the
|
||||
* format's read method (that is only about reading transaction
|
||||
* responses).
|
||||
*/
|
||||
read: function(options) {
|
||||
options = OpenLayers.Util.extend({}, options);
|
||||
OpenLayers.Util.applyDefaults(options, this.options || {});
|
||||
var response = new OpenLayers.Protocol.Response({requestType: "read"});
|
||||
|
||||
var data = OpenLayers.Format.XML.prototype.write.apply(
|
||||
this.format, [this.format.writeNode("wfs:GetFeature", options)]
|
||||
);
|
||||
|
||||
response.priv = OpenLayers.Request.POST({
|
||||
url: options.url,
|
||||
callback: this.createCallback(this.handleRead, response, options),
|
||||
params: options.params,
|
||||
headers: options.headers,
|
||||
data: data
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: handleRead
|
||||
* Deal with response from the read request.
|
||||
*
|
||||
* Parameters:
|
||||
* response - {<OpenLayers.Protocol.Response>} The response object to pass
|
||||
* to the user callback.
|
||||
* options - {Object} The user options passed to the read call.
|
||||
*/
|
||||
handleRead: function(response, options) {
|
||||
if(options.callback) {
|
||||
var request = response.priv;
|
||||
if(request.status >= 200 && request.status < 300) {
|
||||
// success
|
||||
response.features = this.parseFeatures(request);
|
||||
response.code = OpenLayers.Protocol.Response.SUCCESS;
|
||||
} else {
|
||||
// failure
|
||||
response.code = OpenLayers.Protocol.Response.FAILURE;
|
||||
}
|
||||
options.callback.call(options.scope, response);
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: parseFeatures
|
||||
* Read HTTP response body and return features
|
||||
*
|
||||
* Parameters:
|
||||
* request - {XMLHttpRequest} The request object
|
||||
*
|
||||
* Returns:
|
||||
* {Array({<OpenLayers.Feature.Vector>})} or
|
||||
* {<OpenLayers.Feature.Vector>} Array of features or a single feature.
|
||||
*/
|
||||
parseFeatures: function(request) {
|
||||
var doc = request.responseXML;
|
||||
if(!doc || !doc.documentElement) {
|
||||
doc = request.responseText;
|
||||
}
|
||||
if(!doc || doc.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
return this.format.read(doc);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: commit
|
||||
* Given a list of feature, assemble a batch request for update, create,
|
||||
* and delete transactions. A commit call on the prototype amounts
|
||||
* to writing a WFS transaction - so the write method on the format
|
||||
* is used.
|
||||
*
|
||||
* Parameters:
|
||||
* features - {Array(<OpenLayers.Feature.Vector>}
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Protocol.Response>} A response object with a features
|
||||
* property containing any insertIds and a priv property referencing
|
||||
* the XMLHttpRequest object.
|
||||
*/
|
||||
commit: function(features, options) {
|
||||
|
||||
options = OpenLayers.Util.extend({}, options);
|
||||
OpenLayers.Util.applyDefaults(options, this.options);
|
||||
|
||||
var response = new OpenLayers.Protocol.Response({
|
||||
requestType: "commit",
|
||||
reqFeatures: features
|
||||
});
|
||||
response.priv = OpenLayers.Request.POST({
|
||||
url: options.url,
|
||||
data: this.format.write(features, options),
|
||||
callback: this.createCallback(this.handleCommit, response, options)
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: handleCommit
|
||||
* Called when the commit request returns.
|
||||
*
|
||||
* Parameters:
|
||||
* response - {<OpenLayers.Protocol.Response>} The response object to pass
|
||||
* to the user callback.
|
||||
* options - {Object} The user options passed to the commit call.
|
||||
*/
|
||||
handleCommit: function(response, options) {
|
||||
if(options.callback) {
|
||||
var request = response.priv;
|
||||
|
||||
// ensure that we have an xml doc
|
||||
var data = request.responseXML;
|
||||
if(!data || !data.documentElement) {
|
||||
data = request.responseText;
|
||||
}
|
||||
|
||||
var obj = this.format.read(data) || {};
|
||||
|
||||
response.insertIds = obj.insertIds || [];
|
||||
response.code = (obj.success) ?
|
||||
OpenLayers.Protocol.Response.SUCCESS :
|
||||
OpenLayers.Protocol.Response.FAILURE;
|
||||
options.callback.call(options.scope, response);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: filterDelete
|
||||
* Send a request that deletes all features by their filter.
|
||||
*
|
||||
* Parameters:
|
||||
* filter - {OpenLayers.Filter} filter
|
||||
*/
|
||||
filterDelete: function(filter, options) {
|
||||
options = OpenLayers.Util.extend({}, options);
|
||||
OpenLayers.Util.applyDefaults(options, this.options);
|
||||
|
||||
var response = new OpenLayers.Protocol.Response({
|
||||
requestType: "commit"
|
||||
});
|
||||
|
||||
var root = this.format.createElementNSPlus("wfs:Transaction", {
|
||||
attributes: {
|
||||
service: "WFS",
|
||||
version: this.version
|
||||
}
|
||||
});
|
||||
|
||||
var deleteNode = this.format.createElementNSPlus("wfs:Delete", {
|
||||
attributes: {
|
||||
typeName: (options.featureNS ? this.featurePrefix + ":" : "") +
|
||||
options.featureType
|
||||
}
|
||||
});
|
||||
|
||||
if(options.featureNS) {
|
||||
deleteNode.setAttribute("xmlns:" + this.featurePrefix, options.featureNS);
|
||||
}
|
||||
var filterNode = this.format.writeNode("ogc:Filter", filter);
|
||||
|
||||
deleteNode.appendChild(filterNode);
|
||||
|
||||
root.appendChild(deleteNode);
|
||||
|
||||
var data = OpenLayers.Format.XML.prototype.write.apply(
|
||||
this.format, [root]
|
||||
);
|
||||
|
||||
return OpenLayers.Request.POST({
|
||||
url: this.url,
|
||||
callback : options.callback || function(){},
|
||||
data: data
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Protocol.WFS.v1"
|
||||
});
|
||||
39
lib/OpenLayers/Protocol/WFS/v1_0_0.js
Normal file
39
lib/OpenLayers/Protocol/WFS/v1_0_0.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @requires OpenLayers/Protocol/WFS/v1.js
|
||||
* @requires OpenLayers/Format/WFST/v1_0_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Protocol.WFS.v1_0_0
|
||||
* A WFS v1.0.0 protocol for vector layers. Create a new instance with the
|
||||
* <OpenLayers.Protocol.WFS.v1_0_0> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Protocol.WFS.v1>
|
||||
*/
|
||||
OpenLayers.Protocol.WFS.v1_0_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, {
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: "1.0.0",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Protocol.WFS.v1_0_0
|
||||
* A class for giving layers WFS v1.0.0 protocol.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* instance.
|
||||
*
|
||||
* Valid options properties:
|
||||
* featureType - {String} Local (without prefix) feature typeName (required).
|
||||
* featureNS - {String} Feature namespace (optional).
|
||||
* featurePrefix - {String} Feature namespace alias (optional - only used
|
||||
* if featureNS is provided). Default is 'feature'.
|
||||
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
||||
*/
|
||||
|
||||
CLASS_NAME: "OpenLayers.Protocol.WFS.v1_0_0"
|
||||
});
|
||||
43
lib/OpenLayers/Protocol/WFS/v1_1_0.js
Normal file
43
lib/OpenLayers/Protocol/WFS/v1_1_0.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @requires OpenLayers/Protocol/WFS/v1.js
|
||||
* @requires OpenLayers/Format/WFST/v1_1_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Protocol.WFS.v1_1_0
|
||||
* A WFS v1.1.0 protocol for vector layers. Create a new instance with the
|
||||
* <OpenLayers.Protocol.WFS.v1_1_0> constructor.
|
||||
*
|
||||
* Differences from the v1.0.0 protocol:
|
||||
* - uses Filter Encoding 1.1.0 instead of 1.0.0
|
||||
* - uses GML 3 instead of 2 if no format is provided
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Protocol.WFS.v1>
|
||||
*/
|
||||
OpenLayers.Protocol.WFS.v1_1_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, {
|
||||
|
||||
/**
|
||||
* Property: version
|
||||
* {String} WFS version number.
|
||||
*/
|
||||
version: "1.1.0",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Protocol.WFS.v1_1_0
|
||||
* A class for giving layers WFS v1.1.0 protocol.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* instance.
|
||||
*
|
||||
* Valid options properties:
|
||||
* featureType - {String} Local (without prefix) feature typeName (required).
|
||||
* featureNS - {String} Feature namespace (optional).
|
||||
* featurePrefix - {String} Feature namespace alias (optional - only used
|
||||
* if featureNS is provided). Default is 'feature'.
|
||||
* geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
|
||||
*/
|
||||
|
||||
CLASS_NAME: "OpenLayers.Protocol.WFS.v1_1_0"
|
||||
});
|
||||
23
tests/Format/WFST.html
Normal file
23
tests/Format/WFST.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(2);
|
||||
|
||||
var format = new OpenLayers.Format.WFST();
|
||||
t.ok(format instanceof OpenLayers.Format.WFST.v1_0_0, "constructor returns instance with default versioned format");
|
||||
|
||||
format = new OpenLayers.Format.WFST({
|
||||
version: "1.1.0"
|
||||
});
|
||||
t.ok(format instanceof OpenLayers.Format.WFST.v1_1_0, "constructor returns instance with custom versioned format");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:512px; height:256px"> </div>
|
||||
</body>
|
||||
</html>
|
||||
160
tests/Format/WFST/v1.html
Normal file
160
tests/Format/WFST/v1.html
Normal file
@@ -0,0 +1,160 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(1);
|
||||
|
||||
var data = readXML("FeatureCollection");
|
||||
var format = new OpenLayers.Format.WFST({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states"
|
||||
});
|
||||
var features = format.read(data);
|
||||
|
||||
t.eq(features.length, 1, "number of features read from FeatureCollection is correct");
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
|
||||
var format = new OpenLayers.Format.WFST({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states",
|
||||
featurePrefix: "topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
|
||||
var feature = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(1,2),
|
||||
{foo: "bar"});
|
||||
|
||||
var insertFeature = feature.clone();
|
||||
insertFeature.state = OpenLayers.State.INSERT;
|
||||
var updateFeature = feature.clone();
|
||||
updateFeature.fid = "fid.42";
|
||||
updateFeature.state = OpenLayers.State.UPDATE;
|
||||
var deleteFeature = feature.clone();
|
||||
deleteFeature.state = OpenLayers.State.DELETE;
|
||||
deleteFeature.fid = "fid.37";
|
||||
|
||||
t.plan(5);
|
||||
var snippets = {
|
||||
"GetFeature": {maxFeatures: 1},
|
||||
"Transaction": null,
|
||||
"Insert": insertFeature,
|
||||
"Update": updateFeature,
|
||||
"Delete": deleteFeature
|
||||
}
|
||||
|
||||
var arg;
|
||||
for(var snippet in snippets) {
|
||||
arg = snippets[snippet]
|
||||
var expected = readXML(snippet);
|
||||
var got = format.writers["wfs"][snippet].apply(format, [arg]);
|
||||
t.xml_eq(got, expected, snippet + " request created correctly");
|
||||
}
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:512px; height:256px"> </div>
|
||||
|
||||
<div id="FeatureCollection"><!--
|
||||
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:featureMember>
|
||||
<topp:states fid="states.3">
|
||||
<topp:the_geom>
|
||||
<gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-75.70742,38.557476 -75.71106,38.649551 -75.724937,38.83017 -75.752922,39.141548 -75.761658,39.247753 -75.764664,39.295849 -75.772697,39.383007 -75.791435,39.723755 -75.775269,39.724442 -75.745934,39.774818 -75.695114,39.820347 -75.644341,39.838196 -75.583794,39.840008 -75.470345,39.826435 -75.42083,39.79887 -75.412117,39.789658 -75.428009,39.77813 -75.460754,39.763248 -75.475128,39.741718 -75.476334,39.719971 -75.489639,39.714745 -75.610725,39.612793 -75.562996,39.566723 -75.590187,39.463768 -75.515572,39.36694 -75.402481,39.257637 -75.397728,39.073036 -75.324852,39.012386 -75.307899,38.945911 -75.190941,38.80867 -75.083138,38.799812 -75.045998,38.44949 -75.068298,38.449963 -75.093094,38.450451 -75.350204,38.455208 -75.69915,38.463066 -75.70742,38.557476</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
</topp:the_geom>
|
||||
<topp:STATE_NAME>Delaware</topp:STATE_NAME>
|
||||
<topp:STATE_FIPS>10</topp:STATE_FIPS>
|
||||
<topp:SUB_REGION>S Atl</topp:SUB_REGION>
|
||||
<topp:STATE_ABBR>DE</topp:STATE_ABBR>
|
||||
<topp:LAND_KM>5062.456</topp:LAND_KM>
|
||||
<topp:WATER_KM>1385.022</topp:WATER_KM>
|
||||
<topp:PERSONS>666168.0</topp:PERSONS>
|
||||
<topp:FAMILIES>175867.0</topp:FAMILIES>
|
||||
<topp:HOUSHOLD>247497.0</topp:HOUSHOLD>
|
||||
<topp:MALE>322968.0</topp:MALE>
|
||||
<topp:FEMALE>343200.0</topp:FEMALE>
|
||||
<topp:WORKERS>247566.0</topp:WORKERS>
|
||||
<topp:DRVALONE>258087.0</topp:DRVALONE>
|
||||
<topp:CARPOOL>42968.0</topp:CARPOOL>
|
||||
<topp:PUBTRANS>8069.0</topp:PUBTRANS>
|
||||
<topp:EMPLOYED>335147.0</topp:EMPLOYED>
|
||||
<topp:UNEMPLOY>13945.0</topp:UNEMPLOY>
|
||||
<topp:SERVICE>87973.0</topp:SERVICE>
|
||||
<topp:MANUAL>44140.0</topp:MANUAL>
|
||||
<topp:P_MALE>0.485</topp:P_MALE>
|
||||
<topp:P_FEMALE>0.515</topp:P_FEMALE>
|
||||
<topp:SAMP_POP>102776.0</topp:SAMP_POP>
|
||||
</topp:states>
|
||||
</gml:featureMember>
|
||||
</wfs:FeatureCollection>
|
||||
--></div>
|
||||
|
||||
<div id="GetFeature"><!--
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="1" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:Query typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"/>
|
||||
</wfs:GetFeature>
|
||||
--></div>
|
||||
<div id="Transaction"><!--
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"/>
|
||||
--></div>
|
||||
<div id="Insert"><!--
|
||||
<wfs:Insert xmlns:wfs="http://www.opengis.net/wfs">
|
||||
<feature:states xmlns:feature="http://www.openplans.org/topp">
|
||||
<feature:the_geom>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</feature:the_geom>
|
||||
<feature:foo>bar</feature:foo>
|
||||
</feature:states>
|
||||
</wfs:Insert>
|
||||
--></div>
|
||||
<div id="Update"><!--
|
||||
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||
<wfs:Property>
|
||||
<wfs:Name>the_geom</wfs:Name>
|
||||
<wfs:Value>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</wfs:Value>
|
||||
</wfs:Property>
|
||||
<wfs:Property>
|
||||
<wfs:Name>foo</wfs:Name>
|
||||
<wfs:Value>bar</wfs:Value>
|
||||
</wfs:Property>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:FeatureId fid="fid.42"/>
|
||||
</ogc:Filter>
|
||||
</wfs:Update>
|
||||
--></div>
|
||||
<div id="Delete"><!--
|
||||
<wfs:Delete xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:FeatureId fid="fid.37"/>
|
||||
</ogc:Filter>
|
||||
</wfs:Delete>
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
87
tests/Format/WFST/v1_0_0.html
Normal file
87
tests/Format/WFST/v1_0_0.html
Normal file
@@ -0,0 +1,87 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(1);
|
||||
|
||||
var format = new OpenLayers.Format.WFST.v1_0_0({});
|
||||
t.ok(format instanceof OpenLayers.Format.WFST.v1_0_0, "constructor returns instance");
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(2);
|
||||
|
||||
var data = readXML("Transaction_Response");
|
||||
var format = new OpenLayers.Format.WFST.v1_0_0({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states"
|
||||
});
|
||||
var result = format.read(data);
|
||||
t.eq(result.insertIds[0], "none", "InsertIds read correctly");
|
||||
t.eq(result.success, true, "Success read correctly");
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
|
||||
var format = new OpenLayers.Format.WFST.v1_0_0({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states",
|
||||
featurePrefix: "topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
|
||||
t.plan(1);
|
||||
var snippets = {
|
||||
"Query": {
|
||||
filter: new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.BBOX,
|
||||
value: new OpenLayers.Bounds (1,2,3,4)
|
||||
})}
|
||||
}
|
||||
|
||||
var arg;
|
||||
for(var snippet in snippets) {
|
||||
arg = snippets[snippet]
|
||||
var expected = readXML(snippet);
|
||||
var got = format.writers["wfs"][snippet].apply(format, [arg]);
|
||||
t.xml_eq(got, expected, snippet + " request created correctly");
|
||||
}
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:512px; height:256px"> </div>
|
||||
<div id="Transaction_Response"><!--
|
||||
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<wfs:InsertResult>
|
||||
<ogc:FeatureId fid="none"/>
|
||||
</wfs:InsertResult>
|
||||
<wfs:TransactionResult>
|
||||
<wfs:Status>
|
||||
<wfs:SUCCESS/>
|
||||
</wfs:Status>
|
||||
</wfs:TransactionResult>
|
||||
</wfs:WFS_TransactionResponse>
|
||||
--></div>
|
||||
<div id="Query"><!--
|
||||
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
</wfs:Query>
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
91
tests/Format/WFST/v1_1_0.html
Normal file
91
tests/Format/WFST/v1_1_0.html
Normal file
@@ -0,0 +1,91 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(1);
|
||||
|
||||
var format = new OpenLayers.Format.WFST.v1_1_0({});
|
||||
t.ok(format instanceof OpenLayers.Format.WFST.v1_1_0, "constructor returns instance");
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(2);
|
||||
|
||||
var data = readXML("TransactionResponse");
|
||||
var format = new OpenLayers.Format.WFST.v1_1_0({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states"
|
||||
});
|
||||
var result = format.read(data);
|
||||
t.eq(result.insertIds[0], "none", "InsertIds read correctly");
|
||||
t.eq(result.success, true, "Success read correctly");
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
|
||||
var format = new OpenLayers.Format.WFST.v1_1_0({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states",
|
||||
featurePrefix: "topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
|
||||
t.plan(1);
|
||||
var snippets = {
|
||||
"Query": {
|
||||
filter: new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.BBOX,
|
||||
value: new OpenLayers.Bounds (1,2,3,4)
|
||||
})}
|
||||
}
|
||||
|
||||
var arg;
|
||||
for(var snippet in snippets) {
|
||||
arg = snippets[snippet]
|
||||
var expected = readXML(snippet);
|
||||
var got = format.writers["wfs"][snippet].apply(format, [arg]);
|
||||
t.xml_eq(got, expected, snippet + " request created correctly");
|
||||
}
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:512px; height:256px"> </div>
|
||||
<div id="TransactionResponse"><!--
|
||||
<wfs:TransactionResponse version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<wfs:TransactionSummary>
|
||||
<wfs:totalInserted>0</wfs:totalInserted>
|
||||
<wfs:totalUpdated>1</wfs:totalUpdated>
|
||||
<wfs:totalDeleted>0</wfs:totalDeleted>
|
||||
</wfs:TransactionSummary>
|
||||
<wfs:TransactionResults/>
|
||||
<wfs:InsertResults>
|
||||
<wfs:Feature>
|
||||
<ogc:FeatureId fid="none"/>
|
||||
</wfs:Feature>
|
||||
</wfs:InsertResults>
|
||||
</wfs:TransactionResponse>
|
||||
--></div>
|
||||
<div id="Query"><!--
|
||||
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:lowerCorner>1 2</gml:lowerCorner>
|
||||
<gml:upperCorner>3 4</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
</wfs:Query>
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
238
tests/Protocol/WFS.html
Normal file
238
tests/Protocol/WFS.html
Normal file
@@ -0,0 +1,238 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(2);
|
||||
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: "http://some.url.org",
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type"
|
||||
});
|
||||
t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_0_0,
|
||||
"initialize returns instance of default versioned protocol")
|
||||
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: "http://some.url.org",
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type",
|
||||
version: "1.1.0"
|
||||
});
|
||||
t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_1_0,
|
||||
"initialize returns instance of custom versioned protocol")
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(6);
|
||||
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: "http://some.url.org",
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type",
|
||||
parseFeatures: function(request) {
|
||||
t.eq(request.responseText, "foo", "parseFeatures called properly");
|
||||
return "foo";
|
||||
}
|
||||
});
|
||||
|
||||
var _POST = OpenLayers.Request.POST;
|
||||
|
||||
var expected, status;
|
||||
OpenLayers.Request.POST = function(obj) {
|
||||
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
|
||||
obj.status = status;
|
||||
obj.responseText = "foo";
|
||||
obj.options = {};
|
||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||
return obj;
|
||||
};
|
||||
|
||||
expected = readXML("GetFeature_1");
|
||||
status = 200;
|
||||
var response = protocol.read({callback: function(response) {
|
||||
t.eq(response.features, "foo", "user callback properly called with features");
|
||||
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
|
||||
}});
|
||||
|
||||
options = {
|
||||
maxFeatures: 10,
|
||||
featureType: 'type2',
|
||||
srsName: 'EPSG:900913',
|
||||
featureNS: 'htttp://alternative.namespace.org',
|
||||
callback: function(response) {
|
||||
t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback");
|
||||
}
|
||||
};
|
||||
expected = readXML("GetFeature_2");
|
||||
status = 400;
|
||||
var response = protocol.read(options);
|
||||
|
||||
OpenLayers.Request.POST = _POST;
|
||||
}
|
||||
|
||||
function test_commit(t){
|
||||
t.plan(4);
|
||||
|
||||
var url = "http://some.url.org";
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: url,
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type"
|
||||
});
|
||||
protocol.format.read = function(data) {
|
||||
t.eq(data, "foo", "callback called with correct argument");
|
||||
return {
|
||||
insertIds: new Array(3),
|
||||
success: true
|
||||
}
|
||||
};
|
||||
|
||||
var _POST = OpenLayers.Request.POST;
|
||||
|
||||
var expected;
|
||||
OpenLayers.Request.POST = function(obj) {
|
||||
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly");
|
||||
obj.responseText = "foo";
|
||||
obj.options = {};
|
||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||
return obj;
|
||||
};
|
||||
|
||||
var featureDelete = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(42, 7), {has : "cheeseburger"});
|
||||
featureDelete.fid = "fid.37";
|
||||
featureDelete.state = OpenLayers.State.DELETE;
|
||||
featureDelete.layer = {
|
||||
projection: {
|
||||
getCode : function(){
|
||||
return "EPSG:4326";
|
||||
}
|
||||
}
|
||||
}
|
||||
var featureInsert = featureDelete.clone();
|
||||
featureInsert.state = OpenLayers.State.INSERT;
|
||||
var featureModify = featureDelete.clone();
|
||||
featureModify.fid = "fid.37";
|
||||
featureModify.state = OpenLayers.State.UPDATE;
|
||||
|
||||
options = {
|
||||
featureNS: "http://some.namespace.org",
|
||||
featureType: "type",
|
||||
callback: function(response) {
|
||||
t.eq(response.insertIds.length, 3, "correct response passed to user callback");
|
||||
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success properly reported to user callback");
|
||||
}
|
||||
}
|
||||
|
||||
expected = readXML("commit");
|
||||
var response = protocol.commit([featureInsert, featureModify, featureDelete], options);
|
||||
|
||||
OpenLayers.Request.POST = _POST;
|
||||
|
||||
}
|
||||
|
||||
function test_filterDelete(t) {
|
||||
t.plan(2)
|
||||
|
||||
var url = "http://some.url.org";
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: url,
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type"
|
||||
});
|
||||
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.BBOX,
|
||||
value: new OpenLayers.Bounds(-5, -5, 5, 5)
|
||||
});
|
||||
|
||||
var _POST = OpenLayers.Request.POST;
|
||||
|
||||
var expected = readXML("filter_delete");
|
||||
OpenLayers.Request.POST = function(obj) {
|
||||
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "request data correct");
|
||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||
return obj;
|
||||
};
|
||||
|
||||
var response = protocol.filterDelete(filter, {
|
||||
callback: function() {
|
||||
t.ok("user callback function called");
|
||||
}
|
||||
});
|
||||
|
||||
OpenLayers.Request.POST = _POST;
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:512px; height:256px"> </div>
|
||||
<div id="GetFeature_1"><!--
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:Query typeName="feature:type" xmlns:feature="http://namespace.org"/>
|
||||
</wfs:GetFeature>
|
||||
--></div>
|
||||
<div id="GetFeature_2"><!--
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="10" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:Query typeName="feature:type2" xmlns:feature="htttp://alternative.namespace.org"/>
|
||||
</wfs:GetFeature>
|
||||
--></div>
|
||||
<div id="commit"><!--
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:Insert>
|
||||
<feature:type xmlns:feature="http://namespace.org">
|
||||
<feature:the_geom>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
|
||||
</gml:Point>
|
||||
</feature:the_geom>
|
||||
<feature:has>cheeseburger</feature:has>
|
||||
</feature:type>
|
||||
</wfs:Insert>
|
||||
<wfs:Update typeName="feature:type" xmlns:feature="http://namespace.org">
|
||||
<wfs:Property>
|
||||
<wfs:Name>the_geom</wfs:Name>
|
||||
<wfs:Value>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
|
||||
</gml:Point>
|
||||
</wfs:Value>
|
||||
</wfs:Property>
|
||||
<wfs:Property>
|
||||
<wfs:Name>has</wfs:Name>
|
||||
<wfs:Value>cheeseburger</wfs:Value>
|
||||
</wfs:Property>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:FeatureId fid="fid.37"/>
|
||||
</ogc:Filter>
|
||||
</wfs:Update>
|
||||
<wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:FeatureId fid="fid.37"/>
|
||||
</ogc:Filter>
|
||||
</wfs:Delete>
|
||||
</wfs:Transaction>
|
||||
--></div>
|
||||
<div id="filter_delete"><!--
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
|
||||
<wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName/>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
</wfs:Delete>
|
||||
</wfs:Transaction>
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -55,6 +55,10 @@
|
||||
<li>Format/Filter/v1_0_0.html</li>
|
||||
<li>Format/Filter/v1_1_0.html</li>
|
||||
<li>Format/WFSDescribeFeatureType.html</li>
|
||||
<li>Format/WFST.html</li>
|
||||
<li>Format/WFST/v1.html</li>
|
||||
<li>Format/WFST/v1_0_0.html</li>
|
||||
<li>Format/WFST/v1_1_0.html</li>
|
||||
<li>Format/WKT.html</li>
|
||||
<li>Format/WMC.html</li>
|
||||
<li>Format/WMC/v1_1_0.html</li>
|
||||
@@ -121,6 +125,7 @@
|
||||
<li>Protocol/HTTP.html</li>
|
||||
<li>Protocol/SQL.html</li>
|
||||
<li>Protocol/SQL/Gears.html</li>
|
||||
<li>Protocol/WFS.html</li>
|
||||
<li>Renderer.html</li>
|
||||
<li>Renderer/Canvas.html</li>
|
||||
<li>Renderer/Elements.html</li>
|
||||
|
||||
Reference in New Issue
Block a user