[OpenLayers-Commits] r11401 - in sandbox/sbrunner/addins/deviceorientation/trunk: examples lib/OpenLayers/Control theme/default

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Feb 24 06:06:49 EST 2011


Author: fredj
Date: 2011-02-24 03:06:49 -0800 (Thu, 24 Feb 2011)
New Revision: 11401

Modified:
   sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.html
   sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.js
   sandbox/sbrunner/addins/deviceorientation/trunk/lib/OpenLayers/Control/DeviceOrientation.js
   sandbox/sbrunner/addins/deviceorientation/trunk/theme/default/style.css
Log:
deviceorientation addins, not finished

Modified: sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.html
===================================================================
--- sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.html	2011-02-24 10:57:56 UTC (rev 11400)
+++ sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.html	2011-02-24 11:06:49 UTC (rev 11401)
@@ -1,19 +1,20 @@
 <!DOCTYPE html>
 <html>
-<head>
+  <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 Device Orientation</title>
+
     <link rel="stylesheet" href="http://www.openlayers.org/dev/theme/default/style.css" type="text/css"/>
     <link rel="stylesheet" href="http://www.openlayers.org/dev/examples/style.css" type="text/css"/>
-    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
 
     <link rel="stylesheet" href="../theme/default/style.css" type="text/css"/>
     <script type="text/javascript" src="../lib/OpenLayers/Control/DeviceOrientation.js"></script>
     <script type="text/javascript" src="orientation.js"></script>
-</head>
-<body onload="init()">
+  </head>
+  <body onload="init()">
     <h1>Device Orientation</h1>
     <div id="map" class="smallmap"></div>
-</body>
+  </body>
 </html>

Modified: sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.js
===================================================================
--- sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.js	2011-02-24 10:57:56 UTC (rev 11400)
+++ sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.js	2011-02-24 11:06:49 UTC (rev 11401)
@@ -7,21 +7,3 @@
     map.addControl(orientation);
     map.zoomToMaxExtent();
 }
-
-//     function init() {
-//         var logs = document.getElementById("logs");
-//         orientation = new OpenLayers.Control.DeviceOrientation();
-//         if (orientation.supported()) {
-//             orientation.events.register("orientationchange", this, function(event) {
-//                 logs.innerHTML = "rotation: " + event.orientation;
-
-//                 var img = document.getElementById("orientation");
-//                 var value = "rotate(" + event.orientation + "deg)";
-//                 img.style.transform = value;
-//                 img.style.webkitTransform = value;
-//             });
-//             orientation.activate();
-//         } else {
-//             logs.innerHTML = "This device don't supports device orientation";
-//         }
-//     }

Modified: sandbox/sbrunner/addins/deviceorientation/trunk/lib/OpenLayers/Control/DeviceOrientation.js
===================================================================
--- sandbox/sbrunner/addins/deviceorientation/trunk/lib/OpenLayers/Control/DeviceOrientation.js	2011-02-24 10:57:56 UTC (rev 11400)
+++ sandbox/sbrunner/addins/deviceorientation/trunk/lib/OpenLayers/Control/DeviceOrientation.js	2011-02-24 11:06:49 UTC (rev 11401)
@@ -9,11 +9,25 @@
 
 /**
  * Class: OpenLayers.Control.DeviceOrientation
- * see: http://dev.w3.org/geo/api/spec-source-orientation.html
+ * The DeviceOrientation displays a div on the map rotated according to
+ * the rotation of the device, the DeviceOrientationEvent is used.  
+ * If the device do not supports this event, the div is hidden.
+ * <http://dev.w3.org/geo/api/spec-source-orientation.html>
+ * 
+ * Inherits from:
+ *  - <OpenLayers.Control>
+ *  
  */
 OpenLayers.Control.DeviceOrientation = OpenLayers.Class(OpenLayers.Control, {
 
     /**
+     * APIProperty: autoActivate
+     * {Boolean} Activate the control when it is added to a map.  Default is
+     *     true.
+     */
+    autoActivate: true,
+
+    /**
      * APIMethod: supported
      *
      * Returns:
@@ -24,32 +38,48 @@
     },
 
     /**
-     * Method: draw
-     *
-     * Returns:
-     * {DOMElement}
+     * APIMethod: activate
      */
-    draw: function() {
-        OpenLayers.Control.prototype.draw.apply(this, arguments);
-        if (this.supported()) {
-            window.addEventListener("deviceorientation",
-                OpenLayers.Function.bind(this.updateOrientation, this), true);
+    activate: function () {
+        if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
+            if (this.supported()) {
+                window.addEventListener("deviceorientation",
+                    OpenLayers.Function.bind(this.updateOrientation, this), true);
+            } else {
+                OpenLayers.Element.addClass(this.div, "unsupported");
+            }
+            return true;
         } else {
-            OpenLayers.Element.addClass(this.div, "unsupported");
+            return false;
         }
-        return this.div;
     },
 
+    /**
+     * APIMethod: deactivate
+     */
+    deactivate: function () {
+        if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
+            if (this.supported()) {
+                window.removeEventListener("deviceorientation",
+                    OpenLayers.Function.bind(this.updateOrientation, this), true);
+            }
+            return true;
+        } else {
+            return false;
+        }
+    },
+
     updateOrientation: function(event) {
         var v = "rotate(" + event.alpha - window.orientation - 90 + "deg)";
         this.div.style.transform = v;
         this.div.style.webkitTransform = v;
     },
 
+    /**
+     * Method: destroy
+     */
     destroy: function() {
-        window.removeEventListener("deviceorientation",
-            OpenLayers.Function.bind(this.updateOrientation, this), true);
-
+        this.deactivate();
         OpenLayers.Control.prototype.destroy.apply(this, arguments);
     },
 

Modified: sandbox/sbrunner/addins/deviceorientation/trunk/theme/default/style.css
===================================================================
--- sandbox/sbrunner/addins/deviceorientation/trunk/theme/default/style.css	2011-02-24 10:57:56 UTC (rev 11400)
+++ sandbox/sbrunner/addins/deviceorientation/trunk/theme/default/style.css	2011-02-24 11:06:49 UTC (rev 11401)
@@ -5,3 +5,7 @@
     height: 30px;
     border: 1px solid red;
 }
+
+.olControlDeviceOrientation.unsupported {
+    display: none;
+}



More information about the Commits mailing list