[OpenLayers-Commits] r11044 - in sandbox/sonxurxo/sos: examples
lib/OpenLayers/Format/OWSCommon
lib/OpenLayers/Format/SOSCapabilities theme/default/img
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Jan 20 06:36:21 EST 2011
Author: sonxurxo
Date: 2011-01-20 03:36:21 -0800 (Thu, 20 Jan 2011)
New Revision: 11044
Added:
sandbox/sonxurxo/sos/examples/SOSGetObservation.html
sandbox/sonxurxo/sos/theme/default/img/loading.gif
Modified:
sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js
sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js
Log:
Added POST capabilities to SOSCapabilities/v1_0_0.js and OWSCommon/v1.js, example with GetObservation
Added: sandbox/sonxurxo/sos/examples/SOSGetObservation.html
===================================================================
--- sandbox/sonxurxo/sos/examples/SOSGetObservation.html (rev 0)
+++ sandbox/sonxurxo/sos/examples/SOSGetObservation.html 2011-01-20 11:36:21 UTC (rev 11044)
@@ -0,0 +1,274 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+ <style type="text/css">
+ body {
+ font-family: "Lucida Grande", Verdana, Geneva, Lucida, Arial, Helvetica, sans-serif;
+ font-size: 80%;
+ color: #222;
+ background: #fff;
+ margin: 1em 1.5em;
+ }
+ h1 {
+ color: #003a6b;
+ background-color: transparent;
+ font: 100% 'Lucida Grande', Verdana, Geneva, Lucida, Arial, Helvetica, sans-serif;
+ margin: 0;
+ padding-top: 0.5em;
+ font-size: 130%;
+ margin-bottom: 0.5em;
+ border-bottom: 1px solid #fcb100;
+ }
+ #explanation {
+ clear: both;
+ float: left;
+ margin-top: 20px;
+ }
+ #explanation ul {
+ clear: both;
+ float: none;
+ }
+ .sosmap {
+ width: 668px;
+ height: 400px;
+ clear: none;
+ float: left;
+ }
+ #docs {
+ text-align: left;
+ float: left;
+ margin-left: 50px;
+ }
+ </style>
+ <script src="../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ var map;
+
+// OpenLayers.ProxyHost = "proxy.cgi?url=";
+ OpenLayers.ProxyHost = "/cgi-bin/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,
+ // The underlying vector layer which holds the features
+ vectorLayer: null,
+ capsformat: new OpenLayers.Format.SOSCapabilities.v1_0_0(),
+ obsformat: new OpenLayers.Format.SOSGetObservation(),
+ initialize: function (options) {
+ OpenLayers.Util.extend(this, options);
+ // Style the features to show the measurement in their labels. When hover a feature,
+ // the measuremenet time will be displayed
+ this.vectorLayer = new OpenLayers.Layer.Vector("points", {
+ styleMap: new OpenLayers.StyleMap({
+ 'default':{
+ strokeColor: "#e8e8e8",
+ strokeOpacity: 1,
+ strokeWidth: 3,
+ fillColor: "#FF5500",
+ fillOpacity: 0.5,
+ pointRadius: 6,
+ pointerEvents: "visiblePainted",
+ label : "${value} ${uom}",
+
+ fontSize: "11px",
+ fontFamily: "Courier New, monospace",
+ fontWeight: "normal",
+ labelAlign: "cm",
+ labelXOffset: "0",
+ labelYOffset: "15"
+ },
+ 'select':{
+ strokeColor: "#a8a8a8",
+ strokeOpacity: 1,
+ strokeWidth: 3,
+ fillColor: "#aa5500",
+ fillOpacity: 0.8,
+ pointRadius: 4,
+ pointerEvents: "visiblePainted",
+ label : "${value} ${uom} (${time})",
+
+ fontSize: "12px",
+ fontFamily: "Courier New, monospace",
+ fontWeight: "bold",
+ labelAlign: "cm",
+ labelXOffset: "0",
+ labelYOffset: "15"
+ }
+ })
+ });
+ map.addLayer(this.vectorLayer);
+ // The select control
+ var selectFeature = new OpenLayers.Control.SelectFeature(this.vectorLayer, {
+ hover: true
+ });
+ map.addControls([selectFeature]);
+ selectFeature.activate();
+
+ // We request the Capabilities doc through a POST (XML) request
+ var capsXML = this.capsformat.write({
+ AcceptVersions: ["1.0.0", "2.0.0"],
+ Sections: ["Contents", "OperationsMetadata"]
+ });
+
+ OpenLayers.Request.POST({
+ url: this.url,
+ scope: this,
+ data: capsXML,
+ success: this.parseSOSCaps,
+ scope: this
+ });
+ },
+ // Performs a GetObservation request for an offering and an observedProperty
+ getObservation: function(offering, observedProperty) {
+ var obsXML = this.obsformat.write({
+ offering: offering,
+ observedProperties: [observedProperty],
+ responseFormat: 'text/xml;subtype="om/1.0.0"',
+ resultModel: "om:Measurement",
+ eventTime: "latest"
+ });
+
+ OpenLayers.Request.POST({
+ url: this.url,
+ scope: this,
+ data: obsXML,
+ success: this.parseSOSObs,
+ // Hides the loading GIF, and re-enables all radio inputs
+ callback: function() {
+ document.getElementById(offering + '_' + observedProperty).style.display = 'none';
+ var inputs = document.getElementsByClassName('anInput');
+ for(var i in inputs) {
+ inputs[i].disabled = false;
+ }
+ },
+ scope: this
+ });
+ },
+ // Parses the GetObservation response, adding the features to the vector layer
+ parseSOSObs: function(response) {
+ this.SOSObservation = this.obsformat.read(response.responseXML || response.responseText);
+ var features = [];
+ this.removeAllFeatures();
+ for (var measurement in this.SOSObservation.measurements) {
+ var m = this.SOSObservation.measurements[measurement];
+ features.push(new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Point(m.fois[0].components[0].x, m.fois[0].components[0].y), {
+ value: new Number(m.result.value).toFixed(2),
+ uom: m.result.uom,
+ time: m.samplingTime.timeInstant.timePosition.substring(0,10) + ', ' +
+ m.samplingTime.timeInstant.timePosition.substring(11,16)
+ }
+ ));
+ }
+ this.vectorLayer.addFeatures(features);
+ },
+ // Parses the GetCapabilities response, displaying the radio inputs for all observedProperties of all offerings
+ parseSOSCaps: function(response) {
+ // Hide the loading GIF
+ document.getElementById("loadingGif").style.display = 'none';
+ this.SOSCapabilities = this.capsformat.read(response.responseXML || response.responseText);
+ var offerings = this.SOSCapabilities.contents.offeringList;
+ var html = '';
+ html += '<ul>';
+ // For each offering, a list item.
+ for (var offering in offerings) {
+ html += '<li>';
+ html += offering + '<br/>';
+ var responseFormat = offerings[offering].responseFormats[0];
+ var resultModel = "om:Measurement";
+ var eventTime = "latest";
+ var observedProperties = offerings[offering].observedProperties;
+ // For each observedProperty in each offering, a radio input and its loading GIF.
+ for (var observedProperty in observedProperties) {
+ html += '<input type="radio" name="offering" class="' + offering + ' anInput" onchange="onChange(this)" value="' +
+ observedProperties[observedProperty] + '">' + observedProperties[observedProperty] + '</input>' +
+ '<img id="' + offering + '_' + observedProperties[observedProperty] + '" src="../theme/default/img/loading.gif"'
+ + 'style="display:none;clear:right;float:right"></img><br/>';
+ }
+ html += '</li>';
+ }
+ html += '</ul>';
+ document.getElementById('observedPropertiesP').innerHTML = html;
+ },
+ // Removes all features in the vector layer
+ removeAllFeatures: function() {
+ this.vectorLayer.removeAllFeatures();
+ },
+ destroy: function () {
+ },
+ CLASS_NAME: "OpenLayers.SOSClient"
+ });
+
+ // Handler for clicks in the radio inputs
+ function onChange(input) {
+ // Disable all radio inputs while loading
+ var inputs = document.getElementsByClassName('anInput');
+ for(var i in inputs) {
+ inputs[i].disabled = true;
+ }
+ // Show loading GIF for this input
+ document.getElementById(input.className.split(" ")[0] + '_' + input.value).style.display = 'block';
+ // Remove all features
+ sos.removeAllFeatures();
+ // Get the observation
+ sos.getObservation(input.className.split(" ")[0], input.value);
+ };
+
+ 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, bounds: new OpenLayers.Bounds()});
+ 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 GetObservation example</h1>
+
+ <div id="tags">
+ sos, sensor, observation, popup, advanced
+ </div>
+ <div id="explanation">
+ Shows how to connect OpenLayers to a Sensor Observation Service (SOS), obtaining the geometries of the FOIs
+ <b>through the GetObservation request</b>.
+ <ul>
+ <li>
+ Wait until the list of offerings and observed properties load.
+ </li>
+ <li>
+ Then, select one. A <b><i>'GetObservation'</i></b> request will be made, obtaining the measurements for the
+ observed property and the geometries of the features that provide those measurements. The features
+ will be added to an underlying vector layer.
+ </li>
+ <li>
+ Each time you select a new observed property, all the features are removed from this layer (note
+ that not all observed properties have to be measured all features of interest).
+ </li>
+ <li>
+ Hover a feature to see the measurement time instant (<b><i>'latest'</i></b> is requested);
+ </li>
+ </ul>
+ </div>
+ <div id="map" class="sosmap"></div>
+ <div id="docs">
+ <p>
+ Select the observedProperty you want to show: <img id="loadingGif" src="../theme/default/img/loading.gif" style="clear:right;float:right"></img>
+ </p>
+ <p id="observedPropertiesP">
+ </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-19 16:44:39 UTC (rev 11043)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Format/OWSCommon/v1.js 2011-01-20 11:36:21 UTC (rev 11044)
@@ -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. */
@@ -247,6 +247,28 @@
var node = this.createElementNSPlus("ows:OutputFormat", {
value: format });
return node;
+ },
+ "AcceptVersions": function(acceptVersions) {
+ var node = this.createElementNSPlus("ows:AcceptVersions");
+ for (var version in acceptVersions) {
+ this.writeNode("Version", acceptVersions[version], node);
+ }
+ return node;
+ },
+ "Version": function(options) {
+ return this.createElementNSPlus("ows:Version",
+ {value: options});
+ },
+ "Sections": function(sections) {
+ var node = this.createElementNSPlus("ows:Sections");
+ for (var section in sections) {
+ this.writeNode("Section", sections[section], node);
+ }
+ return node;
+ },
+ "Section": function(options) {
+ return this.createElementNSPlus("ows:Section",
+ {value: options});
}
}
},
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-19 16:44:39 UTC (rev 11043)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Format/SOSCapabilities/v1_0_0.js 2011-01-20 11:36:21 UTC (rev 11044)
@@ -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. */
@@ -27,10 +27,20 @@
ows: "http://www.opengis.net/ows/1.1",
sos: "http://www.opengis.net/sos/1.0",
gml: "http://www.opengis.net/gml",
- xlink: "http://www.w3.org/1999/xlink"
+ xlink: "http://www.w3.org/1999/xlink",
+ om: "http://www.opengis.net/om/1.0",
+ ogc: "http://www.opengis.net/ogc",
+ xsi: "http://www.w3.org/2001/XMLSchema-instance"
},
+ schemaLocation: "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd",
+
/**
+ * Property: defaultPrefix
+ */
+ defaultPrefix: "sos",
+
+ /**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
@@ -77,6 +87,28 @@
},
/**
+ * APIMethod: write
+ * Writes a capabilities XML data with the given options.
+ *
+ * Parameters:
+ * options - {Object} Optional object.
+ *
+ * Returns:
+ * {String} An SOS GetCapabilities request XML string.
+ */
+ write: function(options) {
+ var node = this.writeNode("sos:GetCapabilities", options);
+ node.setAttribute("xmlns:ows", this.namespaces.ows);
+ node.setAttribute("xmlns:om", this.namespaces.om);
+ node.setAttribute("xmlns:ogc", this.namespaces.ogc);
+ this.setAttributeNS(
+ node, this.namespaces.xsi,
+ "xsi:schemaLocation", this.schemaLocation
+ );
+ return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
+ },
+
+ /**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
@@ -151,7 +183,27 @@
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
- },
+ },
+ writers: {
+ "sos": {
+ "GetCapabilities": function(options) {
+ var node = this.createElementNSPlus("GetCapabilities", {
+ attributes: {
+ version: this.VERSION,
+ service: 'SOS'
+ }
+ });
+ if(options.AcceptVersions) {
+ this.writeNode("ows:AcceptVersions", options.AcceptVersions, node);
+ }
+ if(options.Sections) {
+ this.writeNode("ows:Sections", options.Sections, node);
+ }
+ return node;
+ }
+ },
+ "ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.writers["ows"]
+ },
CLASS_NAME: "OpenLayers.Format.SOSCapabilities.v1_0_0"
Added: sandbox/sonxurxo/sos/theme/default/img/loading.gif
===================================================================
(Binary files differ)
Property changes on: sandbox/sonxurxo/sos/theme/default/img/loading.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Commits
mailing list