[OpenLayers-Commits] r11314 - in sandbox/sbrunner/openlayers: examples lib lib/OpenLayers/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Feb 23 08:24:28 EST 2011


Author: fredj
Date: 2011-02-23 05:24:27 -0800 (Wed, 23 Feb 2011)
New Revision: 11314

Added:
   sandbox/sbrunner/openlayers/examples/orientation.html
   sandbox/sbrunner/openlayers/lib/OpenLayers/Control/DeviceOrientation.js
Modified:
   sandbox/sbrunner/openlayers/lib/OpenLayers.js
Log:
device orientation control and example

Added: sandbox/sbrunner/openlayers/examples/orientation.html
===================================================================
--- sandbox/sbrunner/openlayers/examples/orientation.html	                        (rev 0)
+++ sandbox/sbrunner/openlayers/examples/orientation.html	2011-02-23 13:24:27 UTC (rev 11314)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <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 Accelerometer Usage</title>
+    <link rel="stylesheet" href="../theme/default/style.css" type="text/css"/>
+    <link rel="stylesheet" href="style.css" type="text/css"/>
+    <script type="text/javascript" src="../lib/OpenLayers.js"></script>
+
+    <style type="text/css">
+        .olControlAttribution {
+            bottom: 5px;
+        }
+    </style>
+    <script type="text/javascript">
+    var orientation;
+    function init() {
+        orientation = new OpenLayers.Control.DeviceOrientation();
+        if (orientation.supported) {
+            orientation.events.register("orientationchange", function(event) {
+                var img = document.getElementById("orientation");
+                var value = "rotate(" + event.orientation + "deg)";
+                img.style.transform = value;
+                img.style.webkitTransform = value;
+            });
+            orientation.activate();
+        }
+    }
+    </script>
+</head>
+<body onload="init()">
+    <h1>Orientation</h1>
+    <img id="orientation" src="img/mobile-arrow.png"/>
+</body>
+</html>

Added: sandbox/sbrunner/openlayers/lib/OpenLayers/Control/DeviceOrientation.js
===================================================================
--- sandbox/sbrunner/openlayers/lib/OpenLayers/Control/DeviceOrientation.js	                        (rev 0)
+++ sandbox/sbrunner/openlayers/lib/OpenLayers/Control/DeviceOrientation.js	2011-02-23 13:24:27 UTC (rev 11314)
@@ -0,0 +1,72 @@
+/* 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. */
+
+
+/**
+ * Class: OpenLayers.Control.DeviceOrientation
+ * see: http://dev.w3.org/geo/api/spec-source-orientation.html
+ */
+
+OpenLayers.Control.DeviceOrientation = OpenLayers.Class(OpenLayers.Control, {
+
+    EVENT_TYPES: ["orientationchange"],
+
+    /**
+     * Property: last
+     */
+    last: null,
+
+    supported: function() {
+        return window.DeviceOrientationEvent !== undefined;
+    },
+
+    /**
+     * Method: activate
+     * Activates the control.
+     *
+     * Returns:
+     * {Boolean} The control was effectively activated.
+     */
+    activate: function() {
+        if (!this.active) {
+            window.addEventListener("deviceorientation",
+                    OpenLayers.Function.bind(this.onOrientation, this), true);
+        }
+        return OpenLayers.Control.prototype.activate.apply(
+            this, arguments
+        );
+    },
+
+    /**
+     * Method: deactivate
+     * Deactivates the control.
+     *
+     * Returns:
+     * {Boolean} The control was effectively deactivated.
+     */
+    deactivate: function() {
+        if (this.active) {
+            window.removeEventListener("deviceorientation",
+                    OpenLayers.Function.bind(this.onOrientation, this), true);
+        }
+        return OpenLayers.Control.prototype.deactivate.apply(
+            this, arguments
+        );
+    },
+
+    getCurrentOrientation: function() {
+        return this.last;
+    },
+
+    onOrientation: function(event) {
+        this.last = OpenLayers.Util.extend(event, {
+            orientation: event.alpha - window.orientation - 90
+        });
+        this.events.triggerEvent("orientationchange", this.last);
+    },
+
+    CLASS_NAME: "OpenLayers.Control.DeviceOrientation"
+});
+

Modified: sandbox/sbrunner/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/sbrunner/openlayers/lib/OpenLayers.js	2011-02-23 13:22:05 UTC (rev 11313)
+++ sandbox/sbrunner/openlayers/lib/OpenLayers.js	2011-02-23 13:24:27 UTC (rev 11314)
@@ -332,6 +332,7 @@
                 "OpenLayers/Control/ZoomPanel.js",
                 "OpenLayers/Control/EditingToolbar.js",
                 "OpenLayers/Control/Geolocate.js",
+                "OpenLayers/Control/DeviceOrientation.js",
                 "OpenLayers/Symbolizer.js",
                 "OpenLayers/Symbolizer/Point.js",
                 "OpenLayers/Symbolizer/Line.js",



More information about the Commits mailing list