[OpenLayers-Commits] r11048 - in sandbox/sonxurxo/sos: examples
lib/OpenLayers/Format lib/OpenLayers/Format/OWSCommon
lib/OpenLayers/Format/SOSCapabilities
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Jan 20 09:26:13 EST 2011
Author: sonxurxo
Date: 2011-01-20 06:26:13 -0800 (Thu, 20 Jan 2011)
New Revision: 11048
Added:
sandbox/sonxurxo/sos/examples/sosPOST.html
Modified:
sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js
sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities.js
sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js
Log:
Some adaptions to patch for #3021
Added: sandbox/sonxurxo/sos/examples/sosPOST.html
===================================================================
--- sandbox/sonxurxo/sos/examples/sosPOST.html (rev 0)
+++ sandbox/sonxurxo/sos/examples/sosPOST.html 2011-01-20 14:26:13 UTC (rev 11048)
@@ -0,0 +1,192 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+ <style type="text/css">
+ .sosmap {
+ width: 768px;
+ height: 512px;
+ }
+ </style>
+ <script src="../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ var map;
+
+ OpenLayers.ProxyHost = "proxy.cgi?url=";
+
+ OpenLayers.Util.extend(OpenLayers.Lang.en,
+ {
+ 'SOSClientType': "Type",
+ 'SOSClientTime': "Date/time",
+ 'SOSClientLastvalue': "Last value"
+ }
+ );
+
+ // Example class on how to put all the OpenLayers SOS pieces together
+ OpenLayers.SOSClient = OpenLayers.Class({
+ url: null,
+ map: null,
+ capsformat: new OpenLayers.Format.SOSCapabilities(),
+ obsformat: new OpenLayers.Format.SOSGetObservation(),
+ initialize: function (options) {
+ OpenLayers.Util.extend(this, options);
+ var capsXML = this.capsformat.write({
+ AcceptVersions: ["1.0.0"],
+ Sections: ["Contents", "OperationsMetadata"],
+ AcceptFormats: ["text/xml"]
+ });
+
+ OpenLayers.Request.POST({
+ url: this.url,
+ scope: this,
+ data: capsXML,
+ success: this.parseSOSCaps,
+ scope: this
+ });
+ },
+ getFois: function() {
+ var result = [];
+ this.offeringCount = 0;
+ for (var name in this.SOSCapabilities.contents.offeringList) {
+ var offering = this.SOSCapabilities.contents.offeringList[name];
+ this.offeringCount++;
+ for (var i=0, len=offering.featureOfInterestIds.length; i<len; i++) {
+ var foi = offering.featureOfInterestIds[i];
+ if (OpenLayers.Util.indexOf(result, foi) === -1) {
+ result.push(foi);
+ }
+ }
+ }
+ return result;
+ },
+ parseSOSCaps: function(response) {
+ // cache capabilities for future use
+ this.SOSCapabilities = this.capsformat.read(response.responseXML || response.responseText);
+ this.layer = new OpenLayers.Layer.Vector("Stations", {
+ strategies: [new OpenLayers.Strategy.Fixed()],
+ protocol: new OpenLayers.Protocol.SOS({
+ formatOptions: {internalProjection: map.getProjectionObject()},
+ url: this.url,
+ fois: this.getFois()
+ })
+ });
+ this.map.addLayer(this.layer);
+ this.ctrl = new OpenLayers.Control.SelectFeature(this.layer,
+ {scope: this, onSelect: this.onFeatureSelect});
+ this.map.addControl(this.ctrl);
+ this.ctrl.activate();
+ },
+ getTitleForObservedProperty: function(property) {
+ for (var name in this.SOSCapabilities.contents.offeringList) {
+ var offering = this.SOSCapabilities.contents.offeringList[name];
+ if (offering.observedProperties[0] === property) {
+ return offering.name;
+ }
+ }
+ },
+ showPopup: function(response) {
+ this.count++;
+ var output = this.obsformat.read(response.responseXML || response.responseText);
+ if (output.measurements.length > 0) {
+ this.html += '<tr>';
+ this.html += '<td width="100">'+this.getTitleForObservedProperty(output.measurements[0].observedProperty)+'</td>';
+ this.html += '<td>'+output.measurements[0].samplingTime.timeInstant.timePosition+'</td>';
+ this.html += '<td>'+output.measurements[0].result.value + ' ' + output.measurements[0].result.uom + '</td>';
+ this.html += '</tr>';
+ }
+ // check if we are done
+ if (this.count === this.numRequests) {
+ var html = '<table cellspacing="10"><tbody>';
+ html += '<tr>';
+ html += '<th><b>'+OpenLayers.i18n('SOSClientType')+'</b></th>';
+ html += '<th><b>'+OpenLayers.i18n('SOSClientTime')+'</b></th>';
+ html += '<th><b>'+OpenLayers.i18n('SOSClientLastvalue')+'</b></th>';
+ html += '</tr>';
+ html += this.html;
+ html += '</tbody></table>';
+ var popup = new OpenLayers.Popup.FramedCloud("sensor",
+ this.feature.geometry.getBounds().getCenterLonLat(),
+ null,
+ html,
+ null,
+ true,
+ function(e) {
+ this.hide();
+ OpenLayers.Event.stop(e);
+ // unselect so popup can be shown again
+ this.map.getControlsByClass('OpenLayers.Control.SelectFeature')[0].unselectAll();
+ }
+ );
+ this.feature.popup = popup;
+ this.map.addPopup(popup);
+ }
+ },
+ onFeatureSelect: function(feature) {
+ this.feature = feature;
+ this.count = 0;
+ this.html = '';
+ this.numRequests = this.offeringCount;
+ if (!this.responseFormat) {
+ for (format in this.SOSCapabilities.operationsMetadata.GetObservation.parameters.responseFormat.allowedValues) {
+ // look for a text/xml type of format
+ if (format.indexOf('text/xml') >= 0) {
+ this.responseFormat = format;
+ }
+ }
+ }
+ // do a GetObservation request to get the latest values
+ for (var name in this.SOSCapabilities.contents.offeringList) {
+ var offering = this.SOSCapabilities.contents.offeringList[name];
+ var xml = this.obsformat.write({
+ eventTime: 'latest',
+ resultModel: 'om:Measurement',
+ responseMode: 'inline',
+ procedure: feature.attributes.id,
+ offering: name,
+ observedProperties: offering.observedProperties,
+ responseFormat: this.responseFormat
+ });
+ OpenLayers.Request.POST({
+ url: this.url,
+ scope: this,
+ failure: this.showPopup,
+ success: this.showPopup,
+ data: xml
+ });
+ }
+ },
+ destroy: function () {
+ },
+ CLASS_NAME: "OpenLayers.SOSClient"
+ });
+
+ function init(){
+ map = new OpenLayers.Map( 'map' );
+ var baseLayer = new OpenLayers.Layer.WMS("Test Layer", "http://vmap0.tiles.osgeo.org/wms/vmap0?", {
+ layers: "basic"}, {singleTile: true});
+
+ var sos = new OpenLayers.SOSClient({map: map, url: 'http://v-swe.uni-muenster.de:8080/WeatherSOS/sos?'});
+
+ map.addLayers([baseLayer]);
+ map.setCenter(new OpenLayers.LonLat(5, 45), 4);
+ map.addControl( new OpenLayers.Control.LayerSwitcher() );
+ map.addControl( new OpenLayers.Control.MousePosition() );
+ }
+ </script>
+ </head>
+ <body onload="init()">
+ <h1 id="title">SOS client example</h1>
+
+ <div id="tags">
+ sos, sensor, observation, popup, advanced
+ </div>
+ <p id="shortdesc">
+ Shows how to connect OpenLayers to a Sensor Observation Service (SOS)
+ </p>
+ <div id="map" class="sosmap"></div>
+ <div id="docs">
+ <p>This example uses a vector layer with a Protocol.SOS and a fixed Strategy.
+ </p><p>When clicking on a point feature (the weather stations offered by the SOS), the
+ latest values for all offerings are displayed in a popup.</p>
+ </div>
+ </body>
+</html>
Modified: sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js
===================================================================
--- sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js 2011-01-20 13:31:30 UTC (rev 11047)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js 2011-01-20 14:26:13 UTC (rev 11048)
@@ -259,6 +259,13 @@
return this.createElementNSPlus("ows:Version",
{value: options});
},
+ "AcceptFormats": function(acceptFormats) {
+ var node = this.createElementNSPlus("ows:AcceptFormats");
+ for (var outputFormat in acceptFormats) {
+ this.writeNode("OutputFormat", acceptFormats[outputFormat], node);
+ }
+ return node;
+ },
"Sections": function(sections) {
var node = this.createElementNSPlus("ows:Sections");
for (var section in sections) {
Modified: sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js
===================================================================
--- sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js 2011-01-20 13:31:30 UTC (rev 11047)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js 2011-01-20 14:26:13 UTC (rev 11048)
@@ -199,6 +199,9 @@
if(options.Sections) {
this.writeNode("ows:Sections", options.Sections, node);
}
+ if(options.AcceptFormats) {
+ this.writeNode("ows:AcceptFormats", options.AcceptFormats, node);
+ }
return node;
}
},
Modified: sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities.js
===================================================================
--- sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities.js 2011-01-20 13:31:30 UTC (rev 11047)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities.js 2011-01-20 14:26:13 UTC (rev 11048)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
@@ -77,6 +77,32 @@
capabilities.version = version;
return capabilities;
},
+ /**
+ * APIMethod: write
+ * Write a SOSCapabilities document given a list of parameters.
+ *
+ * Parameters:
+ * capabilities - {Object} An object representing the GetCapabilities parameters
+ * options - {Object} Optional configuration object.
+ *
+ * Returns:
+ * {String} An SOSCapabilities document string.
+ */
+ write: function(parameters, options) {
+ var version = (options && options.version) ||
+ this.version || this.defaultVersion;
+ if(!this.parser || this.parser.VERSION != version) {
+ var format = OpenLayers.Format.SOSCapabilities[
+ "v" + version.replace(/\./g, "_")
+ ];
+ if(!format) {
+ throw "Can't find a SOSCapabilities parser for version " +
+ version;
+ }
+ this.parser = new format(this.options);
+ }
+ return this.parser.write(parameters);
+ },
CLASS_NAME: "OpenLayers.Format.SOSCapabilities"
More information about the Commits
mailing list