[OpenLayers-Commits] r11050 - in sandbox/sonxurxo/sos: examples lib lib/OpenLayers/Protocol/SOS

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jan 21 07:37:47 EST 2011


Author: sonxurxo
Date: 2011-01-21 04:37:47 -0800 (Fri, 21 Jan 2011)
New Revision: 11050

Added:
   sandbox/sonxurxo/sos/examples/sos2.html
   sandbox/sonxurxo/sos/lib/OpenLayers/Protocol/SOS/v1_0_0_2.js
Modified:
   sandbox/sonxurxo/sos/lib/OpenLayers.js
Log:
Added a SOS protocol to get FOI geometries through a GetObservation request

Added: sandbox/sonxurxo/sos/examples/sos2.html
===================================================================
--- sandbox/sonxurxo/sos/examples/sos2.html	                        (rev 0)
+++ sandbox/sonxurxo/sos/examples/sos2.html	2011-01-21 12:37:47 UTC (rev 11050)
@@ -0,0 +1,114 @@
+<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 = "/cgi-bin/proxy.cgi?url=";
+//        OpenLayers.ProxyHost = "proxy.cgi?url=";
+
+        function init(){
+            map = new OpenLayers.Map( 'map' );
+            var url  = 'http://v-swe.uni-muenster.de:8080/WeatherSOS/sos?';
+
+            var sosLayer = new OpenLayers.Layer.Vector(
+                "SOS", {
+                    reportError: false,
+                    strategies: [
+                        new OpenLayers.Strategy.Fixed(),
+                    ],
+                    projection: new OpenLayers.Projection("EPSG:4326"),
+                    protocol: new OpenLayers.Protocol.SOS.v1_0_0_2({
+                        url : url,
+                        offering: "RAIN_GAUGE",
+                        observedProperties: ["urn:ogc:def:property:OGC::Precipitation1Hour"],
+                        responseFormat: 'text/xml;subtype="om/1.0.0"',
+                        resultModel: "om:Measurement",
+                        eventTime: "latest"
+                    }),
+                    isBaseLayer: false,
+                    visibility: true,
+                    displayInLayerSwitcher: true,
+                    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"
+                        }
+                    })
+                }
+            );
+
+            
+
+            var baseLayer = new OpenLayers.Layer.WMS("Test Layer", "http://vmap0.tiles.osgeo.org/wms/vmap0?", {
+                layers: "basic"}, {singleTile: true});
+
+            map.addLayers([baseLayer, sosLayer]);
+
+            var selectFeature = new OpenLayers.Control.SelectFeature(sosLayer, {
+                hover: true
+            });
+            map.addControls([selectFeature]);
+            selectFeature.activate();
+    
+            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>

Added: sandbox/sonxurxo/sos/lib/OpenLayers/Protocol/SOS/v1_0_0_2.js
===================================================================
--- sandbox/sonxurxo/sos/lib/OpenLayers/Protocol/SOS/v1_0_0_2.js	                        (rev 0)
+++ sandbox/sonxurxo/sos/lib/OpenLayers/Protocol/SOS/v1_0_0_2.js	2011-01-21 12:37:47 UTC (rev 11050)
@@ -0,0 +1,153 @@
+/* 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. */
+
+/**
+ * @requires OpenLayers/Protocol/SOS.js
+ * @requires OpenLayers/Format/SOSGetFeatureOfInterest.js
+ */
+
+/**
+ * Class: OpenLayers.Protocol.SOS.v1_0_0
+ * An SOS v1.0.0 Protocol for vector layers.  Create a new instance with the
+ *     <OpenLayers.Protocol.SOS.v1_0_0> constructor.
+ *
+ * Inherits from:
+ *  - <OpenLayers.Protocol>
+ */
+ OpenLayers.Protocol.SOS.v1_0_0_2 = OpenLayers.Class(OpenLayers.Protocol, {
+
+    offering: null,
+
+    observedProperties: [],
+
+    resultModel: null,
+
+    responseFormat: null,
+
+    eventTime: 'latest',
+
+    /**
+     * APIProperty: fois
+     * {Array(String)} Array of features of interest (foi)
+     */
+//    fois: null,
+
+    /**
+     * 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.SOS
+     * A class for giving layers an SOS 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).
+     * fois - {Array} The features of interest (required).
+     */
+    initialize: function(options) {
+        OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
+        if(!options.format) {
+            this.format = new OpenLayers.Format.SOSGetObservation(
+                this.formatOptions);
+        }
+    },
+   
+    /**
+     * 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);
+    },
+
+    /**
+     * APIMethod: read
+     * Construct a request for reading new sensor positions. This is done by
+     *     issuing one GetFeatureOfInterest request.
+     */
+    read: function(options) {
+        options = OpenLayers.Util.extend({}, options);
+        OpenLayers.Util.applyDefaults(options, this.options || {});
+        var response = new OpenLayers.Protocol.Response({requestType: "read"});
+        var format = this.format;
+        var data = this.format.write(options);
+        response.priv = OpenLayers.Request.POST({
+            url: this.url,
+            callback: this.createCallback(this.handleRead, response, options),
+            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>})} Array of features
+     */
+    parseFeatures: function(request) {
+        var doc = request.responseXML;
+        if(!doc || !doc.documentElement) {
+            doc = request.responseText;
+        }
+        if(!doc || doc.length <= 0) {
+            return null;
+        }
+        var oAM = this.format.read(doc);
+        var features = [];
+        for (var m in oAM.measurements) {
+            var foi = oAM.measurements[m].fois[0].features[0];
+            var geometry = new OpenLayers.Geometry.Point(foi.geometry.x, foi.geometry.y);
+            var feature = new OpenLayers.Feature.Vector(geometry, {
+                value: oAM.measurements[m].result.value,
+                uom: oAM.measurements[m].result.uom,
+                time: oAM.measurements[m].samplingTime.timeInstant.timePosition.substring(0,10) + ', ' + 
+                    oAM.measurements[m].samplingTime.timeInstant.timePosition.substring(11,16)
+            });
+            features.push(feature);
+        }
+        return features;
+    },
+
+    CLASS_NAME: "OpenLayers.Protocol.SOS.v1_0_0_2"
+});

Modified: sandbox/sonxurxo/sos/lib/OpenLayers.js
===================================================================
--- sandbox/sonxurxo/sos/lib/OpenLayers.js	2011-01-21 12:34:06 UTC (rev 11049)
+++ sandbox/sonxurxo/sos/lib/OpenLayers.js	2011-01-21 12:37:47 UTC (rev 11050)
@@ -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. */
@@ -7,62 +7,58 @@
  * @requires OpenLayers/BaseTypes.js
  * @requires OpenLayers/Lang/en.js
  * @requires OpenLayers/Console.js
- */ 
+ */
+ 
+/*
+ * TODO: In 3.0, we will stop supporting build profiles that include
+ * OpenLayers.js. This means we will not need the singleFile and scriptFile
+ * variables, because we don't have to handle the singleFile case any more.
+ */
 
 (function() {
     /**
      * Before creating the OpenLayers namespace, check to see if
      * OpenLayers.singleFile is true.  This occurs if the
      * OpenLayers/SingleFile.js script is included before this one - as is the
-     * case with single file builds.
+     * case with old single file build profiles that included both
+     * OpenLayers.js and OpenLayers/SingleFile.js.
      */
     var singleFile = (typeof OpenLayers == "object" && OpenLayers.singleFile);
     
     /**
-     * Cache for the script location returned from
-     * OpenLayers._getScriptLocation
+     * Relative path of this script.
      */
-    var scriptLocation;
+    var scriptName = (!singleFile) ? "lib/OpenLayers.js" : "OpenLayers.js";
     
     /**
      * Namespace: OpenLayers
      * The OpenLayers object provides a namespace for all things OpenLayers
      */
     window.OpenLayers = {
-        
         /**
-         * Property: _scriptName
-         * {String} Relative path of this script.
-         */
-        _scriptName: (!singleFile) ? "lib/OpenLayers.js" : "OpenLayers.js",
-
-        /**
-         * Function: _getScriptLocation
-         * Return the path to this script.
+         * Method: _getScriptLocation
+         * Return the path to this script. This is also implemented in
+         * OpenLayers/SingleFile.js
          *
          * Returns:
          * {String} Path to this script
          */
-        _getScriptLocation: function () {
-            if (scriptLocation != undefined) {
-                return scriptLocation;
-            }
-            scriptLocation = "";            
-            var isOL = new RegExp("(^|(.*?\\/))(" + OpenLayers._scriptName + ")(\\?|$)");
-         
-            var scripts = document.getElementsByTagName('script');
-            for (var i=0, len=scripts.length; i<len; i++) {
-                var src = scripts[i].getAttribute('src');
-                if (src) {
-                    var match = src.match(isOL);
-                    if(match) {
-                        scriptLocation = match[1];
+        _getScriptLocation: (function() {
+            var r = new RegExp("(^|(.*?\\/))(" + scriptName + ")(\\?|$)"),
+                s = document.getElementsByTagName('script'),
+                src, m, l = "";
+            for(var i=0, len=s.length; i<len; i++) {
+                src = s[i].getAttribute('src');
+                if(src) {
+                    var m = src.match(r);
+                    if(m) {
+                        l = m[1];
                         break;
                     }
                 }
             }
-            return scriptLocation;
-        }
+            return (function() { return l; });
+        })()
     };
     /**
      * OpenLayers.singleFile is a flag indicating this file is being included
@@ -73,12 +69,12 @@
      * 
      * When we *are* part of a SFL build we do not dynamically include the 
      * OpenLayers library code as it will be appended at the end of this file.
-      */
+     */
     if(!singleFile) {
         var jsfiles = new Array(
+            "OpenLayers/BaseTypes/Class.js",
             "OpenLayers/Util.js",
             "OpenLayers/BaseTypes.js",
-            "OpenLayers/BaseTypes/Class.js",
             "OpenLayers/BaseTypes/Bounds.js",
             "OpenLayers/BaseTypes/Element.js",
             "OpenLayers/BaseTypes/LonLat.js",
@@ -131,6 +127,7 @@
             "OpenLayers/Layer/GeoRSS.js",
             "OpenLayers/Layer/Boxes.js",
             "OpenLayers/Layer/XYZ.js",
+            "OpenLayers/Layer/Bing.js",
             "OpenLayers/Layer/TMS.js",
             "OpenLayers/Layer/TileCache.js",
             "OpenLayers/Layer/Zoomify.js",
@@ -228,6 +225,7 @@
             "OpenLayers/Protocol/WFS/v1_1_0.js",
             "OpenLayers/Protocol/SOS.js",
             "OpenLayers/Protocol/SOS/v1_0_0.js",
+            "OpenLayers/Protocol/SOS/v1_0_0_2.js",
             "OpenLayers/Layer/PointTrack.js",
             "OpenLayers/Layer/GML.js",
             "OpenLayers/Style.js",
@@ -292,8 +290,8 @@
             "OpenLayers/Format/WMSGetFeatureInfo.js",
             "OpenLayers/Format/SOSCapabilities.js",
             "OpenLayers/Format/SOSCapabilities/v1_0_0.js",
-            "OpenLayers/Format/SOSGetObservation.js",
             "OpenLayers/Format/SOSGetFeatureOfInterest.js",
+            "OpenLayers/Format/SOSGetObservation.js",
             "OpenLayers/Format/OWSContext.js",
             "OpenLayers/Format/OWSContext/v0_3_1.js",
             "OpenLayers/Format/WMTSCapabilities.js",
@@ -318,28 +316,15 @@
             "OpenLayers/Lang/en.js"
         ); // etc.
 
-        var agent = navigator.userAgent;
-        var docWrite = (agent.match("MSIE") || agent.match("Safari"));
-        if(docWrite) {
-            var allScriptTags = new Array(jsfiles.length);
-        }
+        // use "parser-inserted scripts" for guaranteed execution order
+        // http://hsivonen.iki.fi/script-execution/
+        var allScriptTags = new Array(jsfiles.length);
         var host = OpenLayers._getScriptLocation() + "lib/";    
         for (var i=0, len=jsfiles.length; i<len; i++) {
-            if (docWrite) {
-                allScriptTags[i] = "<script src='" + host + jsfiles[i] +
+            allScriptTags[i] = "<script src='" + host + jsfiles[i] +
                                    "'></script>"; 
-            } else {
-                var s = document.createElement("script");
-                s.src = host + jsfiles[i];
-                var h = document.getElementsByTagName("head").length ? 
-                           document.getElementsByTagName("head")[0] : 
-                           document.body;
-                h.appendChild(s);
-            }
         }
-        if (docWrite) {
-            document.write(allScriptTags.join(""));
-        }
+        document.write(allScriptTags.join(""));
     }
 })();
 



More information about the Commits mailing list