Skip to content

Commit

Permalink
WPS example; support for BoundingBox in WPS format
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Mar 31, 2012
1 parent 81b67db commit c3fe359
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
Binary file added examples/data/tazdem.tiff
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/wps.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers WPS Builder Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
Expand Down
50 changes: 45 additions & 5 deletions examples/wps.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
OpenLayers.ProxyHost = "proxy.cgi?url=";

var capabilities, // the capabilities, read by Format.WPSCapabilities::read
var wps = "http://suite.opengeo.org/geoserver/wps",
capabilities, // the capabilities, read by Format.WPSCapabilities::read
process; // the process description from Format.WPSDescribeProcess::read

// get some capabilities
Expand Down Expand Up @@ -30,7 +31,7 @@ document.getElementById("processes").onchange = describeProcess;
// using OpenLayers.Format.WPSCapabilities to read the capabilities
function getCapabilities() {
OpenLayers.Request.GET({
url: "http://suite.opengeo.org/geoserver/wps/",
url: wps,
params: {
"SERVICE": "wps",
"REQUEST": "GetCapabilities"
Expand All @@ -57,7 +58,7 @@ function getCapabilities() {
function describeProcess() {
var selection = this.options[this.selectedIndex].value;
OpenLayers.Request.GET({
url: "http://suite.opengeo.org/geoserver/wps/",
url: wps,
params: {
"SERVICE": "wps",
"REQUEST": "DescribeProcess",
Expand Down Expand Up @@ -89,14 +90,21 @@ function buildForm() {
addWKTInput(input);
} else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
addWFSCollectionInput(input);
} else if (formats["image/tiff"]) {
addRasterInput(input);
} else {
supported = false;
}
} else if (input.boundingBoxData) {
addBoundingBoxInput(input);
} else if (input.literalData) {
addLiteralInput(input);
} else {
supported = false;
}
if (input.minOccurs > 0) {
document.getElementById("input").appendChild(document.createTextNode("* "));
}
}

if (supported) {
Expand Down Expand Up @@ -170,6 +178,38 @@ function addWFSCollectionInput(input) {
document.getElementById("input").appendChild(field);
}

// helper function to dynamically create a raster (GeoTIFF) url input
function addRasterInput(input) {
var name = input.identifier;
var field = document.createElement("input");
field.title = input["abstract"];
var url = window.location.href.split("?")[0];
field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";
document.getElementById("input").appendChild(field);
(field.onblur = function() {
input.reference = {
mimeType: "image/tiff",
href: field.value,
method: "GET"
};
})();
}

// helper function to dynamically create a bounding box input
function addBoundingBoxInput(input) {
var name = input.identifier;
var field = document.createElement("input");
field.title = input["abstract"];
field.value = "left,bottom,right,top";
document.getElementById("input").appendChild(field);
addValueHandlers(field, function() {
input.boundingBoxData = {
projection: "EPSG:4326",
bounds: OpenLayers.Bounds.fromString(field.value)
}
});
}

// helper function to create a literal input textfield or dropdown
function addLiteralInput(input, previousSibling) {
var name = input.identifier;
Expand Down Expand Up @@ -251,7 +291,7 @@ function execute() {
// remove occurrences that the user has not filled out
for (var i=process.dataInputs.length-1; i>=0; --i) {
input = process.dataInputs[i];
if (input.occurrence && !input.data && !input.reference) {
if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
OpenLayers.Util.removeItem(process.dataInputs, input);
}
}
Expand All @@ -264,7 +304,7 @@ function execute() {
process.responseForm.rawDataOutput.mimeType = "application/wkt";
}
OpenLayers.Request.POST({
url: "http://suite.opengeo.org/geoserver/wps",
url: wps,
data: new OpenLayers.Format.WPSExecute().write(process),
success: showOutput
});
Expand Down
4 changes: 2 additions & 2 deletions lib/OpenLayers/Format/OWSCommon/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
*/
writers: {
"ows": {
"BoundingBox": function(options) {
var node = this.createElementNSPlus("ows:BoundingBox", {
"BoundingBox": function(options, nodeName) {
var node = this.createElementNSPlus(nodeName || "ows:BoundingBox", {
attributes: {
crs: options.projection
}
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenLayers/Format/WFST/v1_0_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(
// Not the superclass, only the mixin classes inherit from
// Format.GML.v2. We need this because we don't want to get readNode
// from the superclass's superclass, which is OpenLayers.Format.XML.
return OpenLayers.Format.GML.v2.prototype.readNode.apply(this, [node, obj]);
return OpenLayers.Format.GML.v2.prototype.readNode.apply(this, arguments);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenLayers/Format/WFST/v1_1_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
// Not the superclass, only the mixin classes inherit from
// Format.GML.v3. We need this because we don't want to get readNode
// from the superclass's superclass, which is OpenLayers.Format.XML.
return OpenLayers.Format.GML.v3.prototype.readNode.apply(this, [node, obj]);
return OpenLayers.Format.GML.v3.prototype.readNode.apply(this, arguments);
},

/**
Expand Down
6 changes: 6 additions & 0 deletions lib/OpenLayers/Format/WPSExecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
if (input.reference) {
this.writeNode("wps:Reference", input.reference, node);
}
if (input.boundingBoxData) {
this.writeNode("wps:BoundingBoxData", input.boundingBoxData, node);
}
return node;
},
"Data": function(data) {
Expand Down Expand Up @@ -228,6 +231,9 @@ OpenLayers.Format.WPSExecute = OpenLayers.Class(OpenLayers.Format.XML, {
}
return node;
},
"BoundingBoxData": function(node, obj) {
this.writers['ows']['BoundingBox'].apply(this, [node, obj, "wps:BoundingBoxData"]);
},
"Body": function(body) {
var node = this.createElementNSPlus("wps:Body", {});
if (body.wcs) {
Expand Down

0 comments on commit c3fe359

Please sign in to comment.